flatpickr-ce 4.8.0 → 4.10.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 (110) hide show
  1. package/README.md +58 -0
  2. package/dist/esm/index.js +132 -80
  3. package/dist/esm/l10n/br.js +1 -1
  4. package/dist/esm/l10n/ckb.js +1 -9
  5. package/dist/esm/l10n/fi.js +1 -0
  6. package/dist/esm/l10n/ga.js +1 -1
  7. package/dist/esm/l10n/he.js +1 -1
  8. package/dist/esm/l10n/id.js +1 -1
  9. package/dist/esm/l10n/index.js +4 -0
  10. package/dist/esm/l10n/no.js +1 -1
  11. package/dist/esm/l10n/vn.js +1 -1
  12. package/dist/esm/plugins/momentPlugin.js +1 -1
  13. package/dist/esm/plugins/monthSelect/index.js +13 -9
  14. package/dist/esm/plugins/rangePlugin.js +34 -14
  15. package/dist/esm/plugins/yearSelect/index.js +341 -0
  16. package/dist/esm/utils/dates.js +10 -5
  17. package/dist/esm/utils/formatting.js +43 -35
  18. package/dist/flatpickr.js +253 -122
  19. package/dist/flatpickr.min.js +2 -2
  20. package/dist/l10n/ar-dz.d.ts +3 -0
  21. package/dist/l10n/ar.d.ts +3 -0
  22. package/dist/l10n/at.d.ts +3 -0
  23. package/dist/l10n/az.d.ts +3 -0
  24. package/dist/l10n/be.d.ts +3 -0
  25. package/dist/l10n/bg.d.ts +3 -0
  26. package/dist/l10n/bn.d.ts +3 -0
  27. package/dist/l10n/br.d.ts +3 -0
  28. package/dist/l10n/br.js +1 -1
  29. package/dist/l10n/bs.d.ts +3 -0
  30. package/dist/l10n/cat.d.ts +3 -0
  31. package/dist/l10n/ckb.d.ts +3 -0
  32. package/dist/l10n/ckb.js +1 -9
  33. package/dist/l10n/cs.d.ts +3 -0
  34. package/dist/l10n/cy.d.ts +3 -0
  35. package/dist/l10n/da.d.ts +3 -0
  36. package/dist/l10n/de.d.ts +3 -0
  37. package/dist/l10n/eo.d.ts +3 -0
  38. package/dist/l10n/es.d.ts +3 -0
  39. package/dist/l10n/et.d.ts +3 -0
  40. package/dist/l10n/fa.d.ts +3 -0
  41. package/dist/l10n/fi.d.ts +3 -0
  42. package/dist/l10n/fi.js +1 -0
  43. package/dist/l10n/fo.d.ts +3 -0
  44. package/dist/l10n/fr.d.ts +3 -0
  45. package/dist/l10n/ga.d.ts +3 -0
  46. package/dist/l10n/ga.js +1 -1
  47. package/dist/l10n/gl.d.ts +3 -0
  48. package/dist/l10n/gr.d.ts +3 -0
  49. package/dist/l10n/he.d.ts +3 -0
  50. package/dist/l10n/he.js +1 -1
  51. package/dist/l10n/hi.d.ts +3 -0
  52. package/dist/l10n/hr.d.ts +3 -0
  53. package/dist/l10n/hu.d.ts +3 -0
  54. package/dist/l10n/hy.d.ts +3 -0
  55. package/dist/l10n/id.d.ts +3 -0
  56. package/dist/l10n/id.js +1 -1
  57. package/dist/l10n/index.js +193 -143
  58. package/dist/l10n/is.d.ts +3 -0
  59. package/dist/l10n/it.d.ts +3 -0
  60. package/dist/l10n/ja.d.ts +3 -0
  61. package/dist/l10n/ka.d.ts +3 -0
  62. package/dist/l10n/km.d.ts +3 -0
  63. package/dist/l10n/ko.d.ts +3 -0
  64. package/dist/l10n/kz.d.ts +3 -0
  65. package/dist/l10n/lt.d.ts +3 -0
  66. package/dist/l10n/lv.d.ts +3 -0
  67. package/dist/l10n/mk.d.ts +3 -0
  68. package/dist/l10n/mn.d.ts +3 -0
  69. package/dist/l10n/ms.d.ts +3 -0
  70. package/dist/l10n/my.d.ts +3 -0
  71. package/dist/l10n/nl.d.ts +3 -0
  72. package/dist/l10n/nn.d.ts +3 -0
  73. package/dist/l10n/no.d.ts +3 -0
  74. package/dist/l10n/no.js +1 -1
  75. package/dist/l10n/pa.d.ts +3 -0
  76. package/dist/l10n/pl.d.ts +3 -0
  77. package/dist/l10n/pt.d.ts +3 -0
  78. package/dist/l10n/ro.d.ts +3 -0
  79. package/dist/l10n/ru.d.ts +3 -0
  80. package/dist/l10n/si.d.ts +3 -0
  81. package/dist/l10n/sk.d.ts +3 -0
  82. package/dist/l10n/sl.d.ts +3 -0
  83. package/dist/l10n/sq.d.ts +3 -0
  84. package/dist/l10n/sr-cyr.d.ts +3 -0
  85. package/dist/l10n/sr.d.ts +3 -0
  86. package/dist/l10n/sv.d.ts +3 -0
  87. package/dist/l10n/tg.d.ts +3 -0
  88. package/dist/l10n/th.d.ts +3 -0
  89. package/dist/l10n/tr.d.ts +3 -0
  90. package/dist/l10n/uk.d.ts +3 -0
  91. package/dist/l10n/uz.d.ts +3 -0
  92. package/dist/l10n/uz_latn.d.ts +3 -0
  93. package/dist/l10n/vn.d.ts +3 -0
  94. package/dist/l10n/vn.js +1 -1
  95. package/dist/l10n/zh.d.ts +3 -0
  96. package/dist/l10n/zh_tw.d.ts +3 -0
  97. package/dist/plugins/momentPlugin.js +1 -1
  98. package/dist/plugins/monthSelect/index.js +17 -10
  99. package/dist/plugins/rangePlugin.js +50 -18
  100. package/dist/plugins/yearSelect/index.d.ts +14 -0
  101. package/dist/plugins/yearSelect/index.js +412 -0
  102. package/dist/plugins/yearSelect/style.css +108 -0
  103. package/dist/themes/airbnb.css +9 -10
  104. package/dist/types/instance.d.ts +3 -0
  105. package/dist/types/locale.d.ts +1 -1
  106. package/dist/types/options.d.ts +2 -0
  107. package/dist/typings.d.ts +1 -1
  108. package/dist/utils/dates.d.ts +1 -1
  109. package/package.json +1 -1
  110. package/src/style/themes/airbnb.styl +4 -8
package/README.md CHANGED
@@ -42,6 +42,60 @@ npm install flatpickr@npm:flatpickr-ce
42
42
 
43
43
  ## What's changed since flatpickr 4.6.13
44
44
 
45
+ ### 4.10.0
46
+
47
+ - The native mobile input follows `set("minDate")` and `set("maxDate")`, and its `min` and `max` are a date and time with `enableTime` and a time with `noCalendar`, on a time its picker can offer ([#2860](https://github.com/flatpickr/flatpickr/issues/2860))
48
+ - With `enableSeconds`, the native mobile input shows and picks seconds ([#2908](https://github.com/flatpickr/flatpickr/issues/2908))
49
+ - New `secondIncrement` option for the seconds input; without it the seconds step by `minuteIncrement` as before ([#2912](https://github.com/flatpickr/flatpickr/pull/2912))
50
+ - A time off its increment, as `minDate` can give, no longer keeps a form with the calendar inside it from submitting, and `set("hourIncrement")` and `set("minuteIncrement")` apply at once ([#2923](https://github.com/flatpickr/flatpickr/issues/2923))
51
+ - `enable` and `disable` are checked by day for a value with a time, as for a click ([#2855](https://github.com/flatpickr/flatpickr/issues/2855))
52
+ - The default time is held to `minDate` and `maxDate` only on their own day, so a date-only `maxDate` no longer turns it into 00:00 ([#2894](https://github.com/flatpickr/flatpickr/issues/2894))
53
+ - In multiple mode, dates typed without the space after the conjunction, such as `01/08/2023,02/08/2023`, are read as separate dates ([#2922](https://github.com/flatpickr/flatpickr/issues/2922))
54
+ - monthSelect's multiple mode adds and removes months on click ([#2849](https://github.com/flatpickr/flatpickr/issues/2849), [#2858](https://github.com/flatpickr/flatpickr/issues/2858))
55
+ - In range mode, a tapped end can no longer cross a disabled day ([#2974](https://github.com/flatpickr/flatpickr/pull/2974))
56
+ - With `allowInput`, Escape in the input closes the calendar ([#2915](https://github.com/flatpickr/flatpickr/pull/2915))
57
+ - `set("locale")` switches the time inputs to the locale's 12- or 24-hour form and AM/PM ([#2954](https://github.com/flatpickr/flatpickr/issues/2954))
58
+ - A year past what a Date can hold leaves the calendar as it was instead of breaking it ([#2906](https://github.com/flatpickr/flatpickr/issues/2906))
59
+ - `element._flatpickr` is the instance in the hooks `init` fires and in plugins ([#2977](https://github.com/flatpickr/flatpickr/issues/2977))
60
+ - The airbnb theme's IE rule is a media query that CSS parsers such as lightningcss accept ([#2976](https://github.com/flatpickr/flatpickr/issues/2976))
61
+ - The main entry is typed as `export =`, so the default import works under `moduleResolution` `node16` and `nodenext` ([#2857](https://github.com/flatpickr/flatpickr/pull/2857))
62
+ - Locales: Finnish ranges are separated with an en dash and Indonesian ones with "sampai"; Irish is registered as `ga`, Vietnamese also as `vi` and Norwegian also as `nb`; the Kurdish (Sorani) weekday shorthand is abbreviated ([#2842](https://github.com/flatpickr/flatpickr/pull/2842), [#2966](https://github.com/flatpickr/flatpickr/pull/2966), [#2848](https://github.com/flatpickr/flatpickr/pull/2848), [#2867](https://github.com/flatpickr/flatpickr/pull/2867), [#2904](https://github.com/flatpickr/flatpickr/pull/2904), [#2895](https://github.com/flatpickr/flatpickr/pull/2895))
63
+
64
+ Behavior changes to check when upgrading:
65
+
66
+ - Finnish ranges saved with " to " and Indonesian ones saved with " - " read as a same-day range of their first date. Replace the separator in stored values, or keep it with `locale: { ...Finnish, rangeSeparator: " to " }`.
67
+ - `locale: "hr"` no longer gives Irish; use `"ga"`.
68
+ - TypeScript: under `moduleResolution` `node` with neither `esModuleInterop` nor `allowSyntheticDefaultImports`, the default import is an error (TS1259); turn on `allowSyntheticDefaultImports`. `import * as flatpickr` is typed as the function itself, so `flatpickr.default(...)` no longer compiles.
69
+ - A value with a time (`defaultDate`, `setDate`, typed text) on a day `disable` lists is dropped, and one on a day `enable` lists is kept; an `enable` or `disable` function is called with midnight of its day, as for a click.
70
+ - In multiple mode, a conjunction without leading whitespace whose trimmed part appears in `dateFormat`, such as the default ", " with `"j,M,Y"`, now splits a date apart. A custom `parseDate` gets each date with the whitespace around it trimmed.
71
+ - With the native mobile input and `enableTime` or `noCalendar`, the native picker keeps to `minDate` and `maxDate`, which it ignored. A value kept outside them, as `allowInvalidPreload` keeps one, leaves the input invalid, so its form doesn't submit until it's changed.
72
+ - The calendar's hour, minute and second inputs have no `step` attribute.
73
+ - With `enableTime`, `set("locale")` rebuilds the time inputs, so listeners attached directly to them are lost, as on `set("time_24hr")`.
74
+ - In monthSelect, the view stays on the year of the month picked.
75
+
76
+ ### 4.9.0
77
+
78
+ - New yearSelect plugin: a year-only picker modeled on monthSelect, for single, multiple and range mode ([#5](https://github.com/colinli007/flatpickr-ce/issues/5), [#6](https://github.com/colinli007/flatpickr-ce/pull/6))
79
+ - In range mode, a same-day range written as one date reads back as that range instead of a start that a click outside drops ([#3010](https://github.com/flatpickr/flatpickr/issues/3010))
80
+ - rangePlugin with `allowInput` commits what is typed into its two inputs as one range: a click outside keeps the range, and `onChange` fires once per commit
81
+ - A date or time with a field out of range, such as `02/31/2025` or `24:00`, is invalid instead of rolling over ([#2988](https://github.com/flatpickr/flatpickr/issues/2988))
82
+ - Month names, weekday names and AM/PM are parsed in any case ([#3057](https://github.com/flatpickr/flatpickr/pull/3057))
83
+ - `allowInvalidPreload` no longer throws on a value it can't parse ([#3000](https://github.com/flatpickr/flatpickr/issues/3000), [#2760](https://github.com/flatpickr/flatpickr/issues/2760), [#2856](https://github.com/flatpickr/flatpickr/issues/2856))
84
+ - `clear()`, and `set("minDate")` or `set("maxDate")`, keep the view within the current limits ([#3002](https://github.com/flatpickr/flatpickr/issues/3002))
85
+ - With `showMonths > 1`, picking a day in a shown month of the next year keeps the view ([#3003](https://github.com/flatpickr/flatpickr/issues/3003))
86
+ - Enter and the arrow keys in the month dropdown no longer change the year or move the focus ([#3045](https://github.com/flatpickr/flatpickr/pull/3045))
87
+ - Seconds are only clamped to `minTime`/`maxTime` within their hour ([#3023](https://github.com/flatpickr/flatpickr/issues/3023), [#3024](https://github.com/flatpickr/flatpickr/pull/3024))
88
+ - With `wrap`, `static` and `altInput`, the altInput stays next to the input ([#3037](https://github.com/flatpickr/flatpickr/issues/3037))
89
+ - The Hebrew range separator is " עד ", and the Breton name of Wednesday is fixed ([#3014](https://github.com/flatpickr/flatpickr/issues/3014), [#3088](https://github.com/flatpickr/flatpickr/pull/3088))
90
+
91
+ Behavior changes to check when upgrading:
92
+
93
+ - In range mode without `enableTime`, a string with one date (the input's value, `defaultDate`, `setDate`, typed text) is a same-day range, so the next day picked starts a new range instead of finishing it. With rangePlugin, `setDate("2024-04-19")` sets a same-day range in both inputs.
94
+ - A date with a field out of range is reported to `errorHandler` and selects nothing, also in `minDate`, `maxDate`, `enable` and `disable`. `maxTime: "24:00"` is dropped; use `"23:59"`.
95
+ - Hebrew ranges saved with " אל " read as a same-day range of their first date. Replace the separator in stored values, or keep it with `locale: { ...Hebrew, rangeSeparator: " אל " }`.
96
+ - With rangePlugin and `allowInput`, an emptied or unparsable end leaves the other end as both ends instead of clearing the range, and an end typed before the start takes the start along.
97
+ - With `wrap`, `static` and `altInput`, the altInput is inside the wrap element, which changes DOM snapshots.
98
+
45
99
  ### 4.8.0
46
100
 
47
101
  - A typed value is committed the same way on Enter, blur and a click outside, and `onChange` now fires when a click outside commits it ([#2941](https://github.com/flatpickr/flatpickr/issues/2941), [#3136](https://github.com/flatpickr/flatpickr/pull/3136))
@@ -114,6 +168,10 @@ Framework addons (they depend on the `flatpickr` package, so use the alias above
114
168
  * [vue-flatpickr component](https://github.com/ankurk91/vue-flatpickr-component)
115
169
  * [lit-flatpickr component](https://github.com/Matsuuu/lit-flatpickr)
116
170
 
171
+ ### Options are trusted
172
+
173
+ A few options are inserted into the calendar as HTML, not text: `prevArrow`, `nextArrow`, what `getWeek` returns, the locale's short weekday names, and confirmDate's `confirmIcon`. Like the rest of the config, they are meant to come from your code: don't build them from user input or other untrusted data without escaping it.
174
+
117
175
 
118
176
  ## Contributing
119
177
 
package/dist/esm/index.js CHANGED
@@ -42,6 +42,9 @@ function FlatpickrInstance(element, instanceConfig) {
42
42
  self._bind = bind;
43
43
  self._setHoursFromDate = setHoursFromDate;
44
44
  self._positionCalendar = positionCalendar;
45
+ self._showValue = showValue;
46
+ self._typedValue = typedValue;
47
+ self._getIncrement = getIncrement;
45
48
  self.changeMonth = changeMonth;
46
49
  self.changeYear = changeYear;
47
50
  self.clear = clear;
@@ -127,13 +130,13 @@ function FlatpickrInstance(element, instanceConfig) {
127
130
  });
128
131
  }
129
132
  }
133
+ function defaultTimeDate() {
134
+ return new Date(withinLimits(new Date()).getTime());
135
+ }
130
136
  function updateTime(e) {
131
137
  if (self.selectedDates.length === 0) {
132
- var defaultDate = self.config.minDate === undefined ||
133
- compareDates(new Date(), self.config.minDate) >= 0
134
- ? new Date()
135
- : new Date(self.config.minDate.getTime());
136
- var defaults = getDefaultHours(self.config);
138
+ var defaultDate = defaultTimeDate();
139
+ var defaults = getDefaultHours(self.config, defaultDate);
137
140
  defaultDate.setHours(defaults.hours, defaults.minutes, defaults.seconds, defaultDate.getMilliseconds());
138
141
  self.selectedDates = [defaultDate];
139
142
  self.latestSelectedDateObj = defaultDate;
@@ -200,27 +203,29 @@ function FlatpickrInstance(element, instanceConfig) {
200
203
  ? self.config.maxTime
201
204
  : self.config.maxDate;
202
205
  hours = Math.min(hours, maxTime.getHours());
203
- if (hours === maxTime.getHours())
206
+ if (hours === maxTime.getHours()) {
204
207
  minutes = Math.min(minutes, maxTime.getMinutes());
205
- if (minutes === maxTime.getMinutes())
206
- seconds = Math.min(seconds, maxTime.getSeconds());
208
+ if (minutes === maxTime.getMinutes())
209
+ seconds = Math.min(seconds, maxTime.getSeconds());
210
+ }
207
211
  }
208
212
  if (limitMinHours) {
209
213
  var minTime = self.config.minTime !== undefined
210
214
  ? self.config.minTime
211
215
  : self.config.minDate;
212
216
  hours = Math.max(hours, minTime.getHours());
213
- if (hours === minTime.getHours() && minutes < minTime.getMinutes())
214
- minutes = minTime.getMinutes();
215
- if (minutes === minTime.getMinutes())
216
- seconds = Math.max(seconds, minTime.getSeconds());
217
+ if (hours === minTime.getHours()) {
218
+ minutes = Math.max(minutes, minTime.getMinutes());
219
+ if (minutes === minTime.getMinutes())
220
+ seconds = Math.max(seconds, minTime.getSeconds());
221
+ }
217
222
  }
218
223
  }
219
224
  setHours(hours, minutes, seconds);
220
225
  }
221
226
  function setHoursFromDate(dateObj) {
222
227
  var date = dateObj || self.latestSelectedDateObj;
223
- if (date && date instanceof Date) {
228
+ if (date) {
224
229
  setHours(date.getHours(), date.getMinutes(), date.getSeconds());
225
230
  }
226
231
  }
@@ -241,6 +246,8 @@ function FlatpickrInstance(element, instanceConfig) {
241
246
  }
242
247
  function onYearInput(event) {
243
248
  var eventTarget = getEventTarget(event);
249
+ if (self.yearElements.indexOf(eventTarget) === -1)
250
+ return;
244
251
  var year = parseInt(eventTarget.value) + (event.delta || 0);
245
252
  if (year / 1000 > 1 ||
246
253
  (event.key === "Enter" && !/[^\d]/.test(year.toString()))) {
@@ -332,15 +339,18 @@ function FlatpickrInstance(element, instanceConfig) {
332
339
  });
333
340
  }
334
341
  }
342
+ function withinLimits(date) {
343
+ var _a = self.config, minDate = _a.minDate, maxDate = _a.maxDate;
344
+ if (minDate && minDate.getTime() > date.getTime())
345
+ return minDate;
346
+ if (maxDate && maxDate.getTime() < date.getTime())
347
+ return maxDate;
348
+ return date;
349
+ }
335
350
  function jumpToDate(jumpDate, triggerChange) {
336
351
  var jumpTo = jumpDate !== undefined
337
352
  ? self.parseDate(jumpDate)
338
- : self.latestSelectedDateObj ||
339
- (self.config.minDate && self.config.minDate > self.now
340
- ? self.config.minDate
341
- : self.config.maxDate && self.config.maxDate < self.now
342
- ? self.config.maxDate
343
- : self.now);
353
+ : self.latestSelectedDateObj || withinLimits(self.now);
344
354
  var oldYear = self.currentYear;
345
355
  var oldMonth = self.currentMonth;
346
356
  try {
@@ -378,6 +388,14 @@ function FlatpickrInstance(element, instanceConfig) {
378
388
  event.delta = delta;
379
389
  input && input.dispatchEvent(event);
380
390
  }
391
+ function getIncrement(input) {
392
+ var _a;
393
+ return Number(input === self.hourElement
394
+ ? self.config.hourIncrement
395
+ : input === self.minuteElement
396
+ ? self.config.minuteIncrement
397
+ : (_a = self.config.secondIncrement) !== null && _a !== void 0 ? _a : self.config.minuteIncrement);
398
+ }
381
399
  function build() {
382
400
  var fragment = doc.createDocumentFragment();
383
401
  self.calendarContainer = createElement("div", "flatpickr-calendar");
@@ -424,8 +442,8 @@ function FlatpickrInstance(element, instanceConfig) {
424
442
  if (self.element.parentNode)
425
443
  self.element.parentNode.insertBefore(wrapper, self.element);
426
444
  wrapper.appendChild(self.element);
427
- if (self.altInput)
428
- wrapper.appendChild(self.altInput);
445
+ if (self.altInput && self.input.parentNode)
446
+ self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
429
447
  wrapper.appendChild(self.calendarContainer);
430
448
  }
431
449
  }
@@ -731,7 +749,7 @@ function FlatpickrInstance(element, instanceConfig) {
731
749
  self.calendarContainer.classList.add("hasTime");
732
750
  if (self.config.noCalendar)
733
751
  self.calendarContainer.classList.add("noCalendar");
734
- var defaults = getDefaultHours(self.config);
752
+ var defaults = getDefaultHours(self.config, defaultTimeDate());
735
753
  self.timeContainer = createElement("div", "flatpickr-time");
736
754
  self.timeContainer.tabIndex = -1;
737
755
  var separator = createElement("span", "flatpickr-time-separator", ":");
@@ -754,8 +772,6 @@ function FlatpickrInstance(element, instanceConfig) {
754
772
  self.minuteElement.value = pad(self.latestSelectedDateObj
755
773
  ? self.latestSelectedDateObj.getMinutes()
756
774
  : defaults.minutes);
757
- self.hourElement.setAttribute("step", self.config.hourIncrement.toString());
758
- self.minuteElement.setAttribute("step", self.config.minuteIncrement.toString());
759
775
  self.hourElement.setAttribute("min", self.config.time_24hr ? "0" : "1");
760
776
  self.hourElement.setAttribute("max", self.config.time_24hr ? "23" : "12");
761
777
  self.hourElement.setAttribute("maxlength", "2");
@@ -776,7 +792,6 @@ function FlatpickrInstance(element, instanceConfig) {
776
792
  self.secondElement.value = pad(self.latestSelectedDateObj
777
793
  ? self.latestSelectedDateObj.getSeconds()
778
794
  : defaults.seconds);
779
- self.secondElement.setAttribute("step", self.minuteElement.getAttribute("step"));
780
795
  self.secondElement.setAttribute("min", "0");
781
796
  self.secondElement.setAttribute("max", "59");
782
797
  self.secondElement.setAttribute("maxlength", "2");
@@ -868,19 +883,18 @@ function FlatpickrInstance(element, instanceConfig) {
868
883
  function clear(triggerChangeEvent, toInitial) {
869
884
  if (triggerChangeEvent === void 0) { triggerChangeEvent = true; }
870
885
  if (toInitial === void 0) { toInitial = true; }
871
- self.input.value = "";
872
- if (self.altInput !== undefined)
873
- self.altInput.value = "";
874
886
  if (self.mobileInput !== undefined)
875
887
  self.mobileInput.value = "";
876
888
  self.selectedDates = [];
877
889
  self.latestSelectedDateObj = undefined;
890
+ self._showValue();
878
891
  if (toInitial === true) {
879
- self.currentYear = self._initialDate.getFullYear();
880
- self.currentMonth = self._initialDate.getMonth();
892
+ var initialDate = withinLimits(self._initialDate);
893
+ self.currentYear = initialDate.getFullYear();
894
+ self.currentMonth = initialDate.getMonth();
881
895
  }
882
896
  if (self.config.enableTime === true) {
883
- var _a = getDefaultHours(self.config), hours = _a.hours, minutes = _a.minutes, seconds = _a.seconds;
897
+ var _a = getDefaultHours(self.config, defaultTimeDate()), hours = _a.hours, minutes = _a.minutes, seconds = _a.seconds;
884
898
  setHours(hours, minutes, seconds);
885
899
  }
886
900
  self.redraw();
@@ -1009,6 +1023,7 @@ function FlatpickrInstance(element, instanceConfig) {
1009
1023
  }
1010
1024
  function changeYear(newYear) {
1011
1025
  if (!newYear ||
1026
+ isNaN(new Date(newYear, self.currentMonth, 1).getTime()) ||
1012
1027
  (self.config.minDate && newYear < self.config.minDate.getFullYear()) ||
1013
1028
  (self.config.maxDate && newYear > self.config.maxDate.getFullYear()))
1014
1029
  return;
@@ -1042,28 +1057,25 @@ function FlatpickrInstance(element, instanceConfig) {
1042
1057
  return true;
1043
1058
  if (dateToCheck === undefined)
1044
1059
  return false;
1060
+ var day = new Date(dateToCheck.getTime());
1061
+ day.setHours(0, 0, 0, 0);
1045
1062
  var bool = !!self.config.enable, array = (_a = self.config.enable) !== null && _a !== void 0 ? _a : self.config.disable;
1046
1063
  for (var i = 0, d = void 0; i < array.length; i++) {
1047
1064
  d = array[i];
1048
1065
  if (typeof d === "function" &&
1049
- d(dateToCheck))
1066
+ d(day))
1050
1067
  return bool;
1051
- else if (d instanceof Date &&
1052
- dateToCheck !== undefined &&
1053
- d.getTime() === dateToCheck.getTime())
1068
+ else if (d instanceof Date && d.getTime() === day.getTime())
1054
1069
  return bool;
1055
1070
  else if (typeof d === "string") {
1056
1071
  var parsed = self.parseDate(d, undefined, true);
1057
- return parsed && parsed.getTime() === dateToCheck.getTime()
1058
- ? bool
1059
- : !bool;
1072
+ return parsed && parsed.getTime() === day.getTime() ? bool : !bool;
1060
1073
  }
1061
1074
  else if (typeof d === "object" &&
1062
- dateToCheck !== undefined &&
1063
1075
  d.from &&
1064
1076
  d.to &&
1065
- dateToCheck.getTime() >= d.from.getTime() &&
1066
- dateToCheck.getTime() <= d.to.getTime())
1077
+ day.getTime() >= d.from.getTime() &&
1078
+ day.getTime() <= d.to.getTime())
1067
1079
  return bool;
1068
1080
  }
1069
1081
  return !bool;
@@ -1080,15 +1092,21 @@ function FlatpickrInstance(element, instanceConfig) {
1080
1092
  !(e.relatedTarget && isCalendarElem(e.relatedTarget)))
1081
1093
  announceCommit(commitTypedValue());
1082
1094
  }
1095
+ function typedValue() {
1096
+ return self._input.value.trimEnd() === getDateStr()
1097
+ ? undefined
1098
+ : self._input.value;
1099
+ }
1083
1100
  function commitTypedValue() {
1084
- if (self._input.value.trimEnd() === getDateStr())
1101
+ var typed = self._typedValue();
1102
+ if (typed === undefined)
1085
1103
  return undefined;
1086
1104
  var committed = {
1087
1105
  times: getSelectedTimes(),
1088
1106
  year: self.currentYear,
1089
1107
  month: self.currentMonth,
1090
1108
  };
1091
- self.setDate(self._input.value, false, self.config.altInput ? self.config.altFormat : self.config.dateFormat);
1109
+ self.setDate(typed, false, self.config.altInput ? self.config.altFormat : self.config.dateFormat);
1092
1110
  if (self.hourElement !== undefined) {
1093
1111
  setHoursFromInputs();
1094
1112
  updateValue(false);
@@ -1114,8 +1132,12 @@ function FlatpickrInstance(element, instanceConfig) {
1114
1132
  ? element.contains(eventTarget)
1115
1133
  : eventTarget === self._input;
1116
1134
  var allowInput = self.config.allowInput;
1117
- var allowKeydown = self.isOpen && (!allowInput || !isInput);
1135
+ var isTypingKey = allowInput && isInput && e.keyCode !== 27;
1136
+ var allowKeydown = self.isOpen && !isTypingKey;
1118
1137
  var allowInlineKeydown = self.config.inline && isInput && !allowInput;
1138
+ var isMonthDropdownArrowKey = eventTarget === self.monthsDropdownContainer &&
1139
+ e.keyCode >= 37 &&
1140
+ e.keyCode <= 40;
1119
1141
  if (e.keyCode === 13 && isInput) {
1120
1142
  if (allowInput) {
1121
1143
  announceCommit(commitTypedValue());
@@ -1126,9 +1148,10 @@ function FlatpickrInstance(element, instanceConfig) {
1126
1148
  self.open();
1127
1149
  }
1128
1150
  }
1129
- else if (isCalendarElem(eventTarget) ||
1130
- allowKeydown ||
1131
- allowInlineKeydown) {
1151
+ else if (!isMonthDropdownArrowKey &&
1152
+ (isCalendarElem(eventTarget) ||
1153
+ allowKeydown ||
1154
+ allowInlineKeydown)) {
1132
1155
  var isTimeObj = !!self.timeContainer &&
1133
1156
  self.timeContainer.contains(eventTarget);
1134
1157
  switch (e.keyCode) {
@@ -1358,6 +1381,10 @@ function FlatpickrInstance(element, instanceConfig) {
1358
1381
  if (self.selectedDates) {
1359
1382
  if (!self.config.allowInvalidPreload)
1360
1383
  self.selectedDates = filterEnabledDates(self.selectedDates, true);
1384
+ if (self.latestSelectedDateObj &&
1385
+ self.selectedDates.indexOf(self.latestSelectedDateObj) === -1)
1386
+ self.latestSelectedDateObj =
1387
+ self.selectedDates[self.selectedDates.length - 1];
1361
1388
  if (!self.selectedDates.length && type === "min")
1362
1389
  setHoursFromDate(dateObj);
1363
1390
  updateValue();
@@ -1373,6 +1400,8 @@ function FlatpickrInstance(element, instanceConfig) {
1373
1400
  dateObj !== undefined &&
1374
1401
  inverseDateObj.getFullYear() === dateObj.getFullYear();
1375
1402
  }
1403
+ if (self.mobileInput !== undefined)
1404
+ setMobileLimit(type);
1376
1405
  };
1377
1406
  }
1378
1407
  function parseConfig() {
@@ -1514,7 +1543,7 @@ function FlatpickrInstance(element, instanceConfig) {
1514
1543
  .slice()
1515
1544
  .sort(function (a, b) { return b.length - a.length; })
1516
1545
  .join("|") + ")";
1517
- tokenRegex.K = "(" + self.l10n.amPM[0] + "|" + self.l10n.amPM[1] + "|" + self.l10n.amPM[0].toLowerCase() + "|" + self.l10n.amPM[1].toLowerCase() + ")";
1546
+ tokenRegex.K = "(" + self.l10n.amPM[0] + "|" + self.l10n.amPM[1] + ")";
1518
1547
  if (userConfig.time_24hr === undefined &&
1519
1548
  flatpickr.defaultConfig.time_24hr === undefined) {
1520
1549
  self.config.time_24hr = self.l10n.time_24hr;
@@ -1627,6 +1656,8 @@ function FlatpickrInstance(element, instanceConfig) {
1627
1656
  function selectDate(e) {
1628
1657
  e.preventDefault();
1629
1658
  e.stopPropagation();
1659
+ if (self.config.mode === "range")
1660
+ onMouseOver(getEventTarget(e));
1630
1661
  var isSelectable = function (day) {
1631
1662
  return day.classList &&
1632
1663
  day.classList.contains("flatpickr-day") &&
@@ -1638,9 +1669,10 @@ function FlatpickrInstance(element, instanceConfig) {
1638
1669
  return;
1639
1670
  var target = t;
1640
1671
  var selectedDate = (self.latestSelectedDateObj = new Date(target.dateObj.getTime()));
1641
- var shouldChangeMonth = (selectedDate.getMonth() < self.currentMonth ||
1642
- selectedDate.getMonth() >
1643
- self.currentMonth + self.config.showMonths - 1) &&
1672
+ var firstMonth = self.currentYear * 12 + self.currentMonth;
1673
+ var selectedMonth = selectedDate.getFullYear() * 12 + selectedDate.getMonth();
1674
+ var shouldChangeMonth = (selectedMonth < firstMonth ||
1675
+ selectedMonth > firstMonth + self.config.showMonths - 1) &&
1644
1676
  self.config.mode !== "range";
1645
1677
  self.selectedDateElem = target;
1646
1678
  if (self.config.mode === "single")
@@ -1697,7 +1729,7 @@ function FlatpickrInstance(element, instanceConfig) {
1697
1729
  triggerChange();
1698
1730
  }
1699
1731
  var CALLBACKS = {
1700
- locale: [setupLocale, updateWeekdays],
1732
+ locale: [setupLocale, updateWeekdays, rebuildTime],
1701
1733
  showMonths: [buildMonths, setCalendarWidth, buildWeekdays],
1702
1734
  minDate: [jumpToDate],
1703
1735
  maxDate: [jumpToDate],
@@ -1756,15 +1788,19 @@ function FlatpickrInstance(element, instanceConfig) {
1756
1788
  case "time":
1757
1789
  dates = [self.parseDate(inputDate, format)];
1758
1790
  break;
1759
- case "multiple":
1791
+ case "multiple": {
1792
+ var conjunction = self.config.conjunction;
1760
1793
  dates = inputDate
1761
- .split(self.config.conjunction)
1762
- .map(function (date) { return self.parseDate(date, format); });
1794
+ .split(conjunction.replace(/\s+$/, "") || conjunction)
1795
+ .map(function (date) { return self.parseDate(date.trim(), format); });
1763
1796
  break;
1797
+ }
1764
1798
  case "range":
1765
1799
  dates = inputDate
1766
1800
  .split(self.l10n.rangeSeparator)
1767
1801
  .map(function (date) { return self.parseDate(date, format); });
1802
+ if (dates.length === 1 && !self.config.enableTime)
1803
+ dates.push(self.parseDate(inputDate, format));
1768
1804
  break;
1769
1805
  default:
1770
1806
  break;
@@ -1772,9 +1808,10 @@ function FlatpickrInstance(element, instanceConfig) {
1772
1808
  }
1773
1809
  else
1774
1810
  self.config.errorHandler(new Error("Invalid date supplied: " + JSON.stringify(inputDate)));
1811
+ var parsed = dates.filter(function (d) { return d instanceof Date; });
1775
1812
  self.selectedDates = self.config.allowInvalidPreload
1776
- ? dates
1777
- : filterEnabledDates(dates.filter(function (d) { return d instanceof Date; }), false);
1813
+ ? parsed
1814
+ : filterEnabledDates(parsed, false);
1778
1815
  if (self.config.mode === "range")
1779
1816
  self.selectedDates.sort(function (a, b) { return a.getTime() - b.getTime(); });
1780
1817
  }
@@ -1832,13 +1869,7 @@ function FlatpickrInstance(element, instanceConfig) {
1832
1869
  self._initialDate =
1833
1870
  self.selectedDates.length > 0
1834
1871
  ? self.selectedDates[0]
1835
- : self.config.minDate &&
1836
- self.config.minDate.getTime() > self.now.getTime()
1837
- ? self.config.minDate
1838
- : self.config.maxDate &&
1839
- self.config.maxDate.getTime() < self.now.getTime()
1840
- ? self.config.maxDate
1841
- : self.now;
1872
+ : withinLimits(self.now);
1842
1873
  self.currentYear = self._initialDate.getFullYear();
1843
1874
  self.currentMonth = self._initialDate.getMonth();
1844
1875
  if (self.selectedDates.length > 0)
@@ -1888,18 +1919,38 @@ function FlatpickrInstance(element, instanceConfig) {
1888
1919
  self._positionElement = self.config.positionElement || self._input;
1889
1920
  }
1890
1921
  function setMobileInputType() {
1922
+ var mobileInput = self.mobileInput;
1891
1923
  var inputType = self.config.enableTime
1892
1924
  ? self.config.noCalendar
1893
1925
  ? "time"
1894
1926
  : "datetime-local"
1895
1927
  : "date";
1896
- self.mobileInput.type = inputType;
1928
+ mobileInput.type = inputType;
1897
1929
  self.mobileFormatStr =
1898
1930
  inputType === "datetime-local"
1899
1931
  ? "Y-m-d\\TH:i:S"
1900
1932
  : inputType === "date"
1901
1933
  ? "Y-m-d"
1902
1934
  : "H:i:S";
1935
+ var step = self.input.getAttribute("step") || (self.config.enableSeconds ? "1" : "");
1936
+ if (step)
1937
+ mobileInput.step = step;
1938
+ else
1939
+ mobileInput.removeAttribute("step");
1940
+ setMobileLimit("min");
1941
+ setMobileLimit("max");
1942
+ }
1943
+ function setMobileLimit(type) {
1944
+ var mobileInput = self.mobileInput;
1945
+ var limit = self.config[type + "Date"];
1946
+ if (limit === undefined)
1947
+ return mobileInput.removeAttribute(type);
1948
+ var date = new Date(limit.getTime());
1949
+ var unit = Number(mobileInput.step || 60) % 60 === 0 ? 60 : 1;
1950
+ var round = type === "min" && mobileInput.type !== "date" ? Math.ceil : Math.floor;
1951
+ var seconds = date.getSeconds() + date.getMilliseconds() / 1000;
1952
+ date.setSeconds(round(seconds / unit) * unit, 0);
1953
+ mobileInput[type] = self.formatDate(date, self.mobileFormatStr);
1903
1954
  }
1904
1955
  function setupMobile() {
1905
1956
  self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
@@ -1911,12 +1962,6 @@ function FlatpickrInstance(element, instanceConfig) {
1911
1962
  if (self.selectedDates.length > 0) {
1912
1963
  self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr);
1913
1964
  }
1914
- if (self.config.minDate)
1915
- self.mobileInput.min = self.formatDate(self.config.minDate, "Y-m-d");
1916
- if (self.config.maxDate)
1917
- self.mobileInput.max = self.formatDate(self.config.maxDate, "Y-m-d");
1918
- if (self.input.getAttribute("step"))
1919
- self.mobileInput.step = String(self.input.getAttribute("step"));
1920
1965
  self.input.type = "hidden";
1921
1966
  if (self.altInput !== undefined)
1922
1967
  self.altInput.type = "hidden";
@@ -1956,9 +2001,7 @@ function FlatpickrInstance(element, instanceConfig) {
1956
2001
  }
1957
2002
  function isDateSelected(date) {
1958
2003
  for (var i = 0; i < self.selectedDates.length; i++) {
1959
- var selectedDate = self.selectedDates[i];
1960
- if (selectedDate instanceof Date &&
1961
- compareDates(selectedDate, date) === 0)
2004
+ if (compareDates(self.selectedDates[i], date) === 0)
1962
2005
  return "" + i;
1963
2006
  }
1964
2007
  return false;
@@ -2021,12 +2064,15 @@ function FlatpickrInstance(element, instanceConfig) {
2021
2064
  self.formatDate(currentDate, self.mobileFormatStr) !== mobileValue)
2022
2065
  self.mobileInput.value = mobileValue;
2023
2066
  }
2067
+ self._showValue();
2068
+ if (triggerChange !== false)
2069
+ triggerEvent("onValueUpdate");
2070
+ }
2071
+ function showValue() {
2024
2072
  self.input.value = getDateStr(self.config.dateFormat);
2025
2073
  if (self.altInput !== undefined) {
2026
2074
  self.altInput.value = getDateStr(self.config.altFormat);
2027
2075
  }
2028
- if (triggerChange !== false)
2029
- triggerEvent("onValueUpdate");
2030
2076
  }
2031
2077
  function onMonthNavClick(e) {
2032
2078
  var eventTarget = getEventTarget(e);
@@ -2052,7 +2098,7 @@ function FlatpickrInstance(element, instanceConfig) {
2052
2098
  self.amPM.textContent =
2053
2099
  self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2054
2100
  }
2055
- var min = parseFloat(input.getAttribute("min")), max = parseFloat(input.getAttribute("max")), step = parseFloat(input.getAttribute("step")), curValue = parseInt(input.value, 10), delta = e.delta ||
2101
+ var min = parseFloat(input.getAttribute("min")), max = parseFloat(input.getAttribute("max")), step = getIncrement(input), curValue = parseInt(input.value, 10), delta = e.delta ||
2056
2102
  (isKeyDown ? (e.which === 38 ? 1 : -1) : 0);
2057
2103
  var newValue = curValue + step * delta;
2058
2104
  if (typeof input.value !== "undefined" && input.value.length === 2) {
@@ -2083,7 +2129,14 @@ function FlatpickrInstance(element, instanceConfig) {
2083
2129
  input.value = pad(newValue);
2084
2130
  }
2085
2131
  }
2086
- init();
2132
+ element._flatpickr = self;
2133
+ try {
2134
+ init();
2135
+ }
2136
+ catch (e) {
2137
+ element._flatpickr = undefined;
2138
+ throw e;
2139
+ }
2087
2140
  return self;
2088
2141
  }
2089
2142
  function _flatpickr(nodeList, config) {
@@ -2100,8 +2153,7 @@ function _flatpickr(nodeList, config) {
2100
2153
  node._flatpickr.destroy();
2101
2154
  node._flatpickr = undefined;
2102
2155
  }
2103
- node._flatpickr = FlatpickrInstance(node, config || {});
2104
- instances.push(node._flatpickr);
2156
+ instances.push(FlatpickrInstance(node, config || {}));
2105
2157
  }
2106
2158
  catch (e) {
2107
2159
  console.error(e);
@@ -11,7 +11,7 @@ export var Breton = {
11
11
  "Disul",
12
12
  "Dilun",
13
13
  "Dimeurzh",
14
- "Dimerc'hed",
14
+ "Dimerc'her",
15
15
  "Diriaou",
16
16
  "Digwener",
17
17
  "Disadorn",
@@ -5,15 +5,7 @@ var fp = typeof window !== "undefined" && window.flatpickr !== undefined
5
5
  };
6
6
  export var Kurdish = {
7
7
  weekdays: {
8
- shorthand: [
9
- "یەکشەممە",
10
- "دووشەممە",
11
- "سێشەممە",
12
- "چوارشەممە",
13
- "پێنجشەممە",
14
- "هەینی",
15
- "شەممە",
16
- ],
8
+ shorthand: ["یەک", "دوو", "سێ", "چوار", "پێنج", "هەینی", "شەممە"],
17
9
  longhand: [
18
10
  "یەکشەممە",
19
11
  "دووشەممە",
@@ -51,6 +51,7 @@ export var Finnish = {
51
51
  return ".";
52
52
  },
53
53
  time_24hr: true,
54
+ rangeSeparator: "–",
54
55
  yearAriaLabel: "vuosi",
55
56
  monthAriaLabel: "kuukausi",
56
57
  hourAriaLabel: "tunti",
@@ -49,5 +49,5 @@ export var Irish = {
49
49
  },
50
50
  time_24hr: true,
51
51
  };
52
- fp.l10ns.hr = Irish;
52
+ fp.l10ns.ga = Irish;
53
53
  export default fp.l10ns;
@@ -38,7 +38,7 @@ export var Hebrew = {
38
38
  "דצמבר",
39
39
  ],
40
40
  },
41
- rangeSeparator: " אל ",
41
+ rangeSeparator: " עד ",
42
42
  time_24hr: true,
43
43
  };
44
44
  fp.l10ns.he = Hebrew;
@@ -43,7 +43,7 @@ export var Indonesian = {
43
43
  return "";
44
44
  },
45
45
  time_24hr: true,
46
- rangeSeparator: " - ",
46
+ rangeSeparator: " sampai ",
47
47
  };
48
48
  fp.l10ns.id = Indonesian;
49
49
  export default fp.l10ns;