@ohos-ports/flowbite-datepicker 2.0.0-beta.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 (291) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +73 -0
  3. package/.stylelintrc +12 -0
  4. package/CHANGELOG.md +72 -0
  5. package/LICENSE +21 -0
  6. package/README.md +71 -0
  7. package/demo/index.html +582 -0
  8. package/demo/live-demo.js +471 -0
  9. package/dist/DateRangePicker.cjs.js +2996 -0
  10. package/dist/DateRangePicker.esm.js +2994 -0
  11. package/dist/DateRangePicker.umd.js +3002 -0
  12. package/dist/Datepicker.cjs.js +2778 -0
  13. package/dist/Datepicker.esm.js +2776 -0
  14. package/dist/Datepicker.umd.js +2784 -0
  15. package/dist/css/datepicker-bs4.css +276 -0
  16. package/dist/css/datepicker-bs4.min.css +1 -0
  17. package/dist/css/datepicker-bs5.css +276 -0
  18. package/dist/css/datepicker-bs5.min.css +1 -0
  19. package/dist/css/datepicker-bulma.css +258 -0
  20. package/dist/css/datepicker-bulma.min.css +1 -0
  21. package/dist/css/datepicker-foundation.css +262 -0
  22. package/dist/css/datepicker-foundation.min.css +1 -0
  23. package/dist/css/datepicker.css +306 -0
  24. package/dist/css/datepicker.min.css +1403 -0
  25. package/dist/js/datepicker-full.js +2777 -0
  26. package/dist/js/datepicker-full.min.js +1 -0
  27. package/dist/js/datepicker.js +2569 -0
  28. package/dist/js/datepicker.min.js +1 -0
  29. package/dist/js/locales/ar-tn.js +15 -0
  30. package/dist/js/locales/ar.js +15 -0
  31. package/dist/js/locales/az.js +14 -0
  32. package/dist/js/locales/bg.js +14 -0
  33. package/dist/js/locales/bm.js +18 -0
  34. package/dist/js/locales/bn.js +19 -0
  35. package/dist/js/locales/br.js +18 -0
  36. package/dist/js/locales/bs.js +15 -0
  37. package/dist/js/locales/ca.js +18 -0
  38. package/dist/js/locales/cs.js +19 -0
  39. package/dist/js/locales/cy.js +14 -0
  40. package/dist/js/locales/da.js +19 -0
  41. package/dist/js/locales/de.js +18 -0
  42. package/dist/js/locales/el.js +16 -0
  43. package/dist/js/locales/en-AU.js +18 -0
  44. package/dist/js/locales/en-CA.js +18 -0
  45. package/dist/js/locales/en-GB.js +18 -0
  46. package/dist/js/locales/en-IE.js +17 -0
  47. package/dist/js/locales/en-NZ.js +17 -0
  48. package/dist/js/locales/en-ZA.js +17 -0
  49. package/dist/js/locales/eo.js +17 -0
  50. package/dist/js/locales/es.js +18 -0
  51. package/dist/js/locales/et.js +18 -0
  52. package/dist/js/locales/eu.js +18 -0
  53. package/dist/js/locales/fa.js +17 -0
  54. package/dist/js/locales/fi.js +17 -0
  55. package/dist/js/locales/fo.js +15 -0
  56. package/dist/js/locales/fr-CH.js +21 -0
  57. package/dist/js/locales/fr.js +18 -0
  58. package/dist/js/locales/gl.js +16 -0
  59. package/dist/js/locales/he.js +15 -0
  60. package/dist/js/locales/hi.js +18 -0
  61. package/dist/js/locales/hr.js +13 -0
  62. package/dist/js/locales/hu.js +18 -0
  63. package/dist/js/locales/hy.js +18 -0
  64. package/dist/js/locales/id.js +15 -0
  65. package/dist/js/locales/is.js +14 -0
  66. package/dist/js/locales/it-CH.js +20 -0
  67. package/dist/js/locales/it.js +18 -0
  68. package/dist/js/locales/ja.js +17 -0
  69. package/dist/js/locales/ka.js +17 -0
  70. package/dist/js/locales/kk.js +15 -0
  71. package/dist/js/locales/km.js +15 -0
  72. package/dist/js/locales/ko.js +18 -0
  73. package/dist/js/locales/lt.js +19 -0
  74. package/dist/js/locales/lv.js +18 -0
  75. package/dist/js/locales/me.js +17 -0
  76. package/dist/js/locales/mk.js +15 -0
  77. package/dist/js/locales/mn.js +17 -0
  78. package/dist/js/locales/mr.js +18 -0
  79. package/dist/js/locales/ms.js +15 -0
  80. package/dist/js/locales/nl-BE.js +18 -0
  81. package/dist/js/locales/nl.js +18 -0
  82. package/dist/js/locales/no.js +18 -0
  83. package/dist/js/locales/oc.js +17 -0
  84. package/dist/js/locales/pl.js +17 -0
  85. package/dist/js/locales/pt-BR.js +17 -0
  86. package/dist/js/locales/pt.js +18 -0
  87. package/dist/js/locales/ro.js +17 -0
  88. package/dist/js/locales/ru.js +18 -0
  89. package/dist/js/locales/si.js +18 -0
  90. package/dist/js/locales/sk.js +18 -0
  91. package/dist/js/locales/sl.js +15 -0
  92. package/dist/js/locales/sq.js +18 -0
  93. package/dist/js/locales/sr-latn.js +16 -0
  94. package/dist/js/locales/sr.js +16 -0
  95. package/dist/js/locales/sv.js +17 -0
  96. package/dist/js/locales/sw.js +15 -0
  97. package/dist/js/locales/ta.js +18 -0
  98. package/dist/js/locales/tg.js +19 -0
  99. package/dist/js/locales/th.js +14 -0
  100. package/dist/js/locales/tk.js +18 -0
  101. package/dist/js/locales/tr.js +17 -0
  102. package/dist/js/locales/uk.js +17 -0
  103. package/dist/js/locales/uz-cyrl.js +18 -0
  104. package/dist/js/locales/uz-latn.js +18 -0
  105. package/dist/js/locales/vi.js +16 -0
  106. package/dist/js/locales/zh-CN.js +19 -0
  107. package/dist/js/locales/zh-TW.js +18 -0
  108. package/dist/locales/index.cjs.js +1028 -0
  109. package/dist/locales/index.esm.js +1028 -0
  110. package/dist/main.cjs.js +2999 -0
  111. package/dist/main.esm.js +2994 -0
  112. package/dist/main.umd.js +3005 -0
  113. package/docs/.nojekyll +0 -0
  114. package/docs/README.md +266 -0
  115. package/docs/_sidebar.md +6 -0
  116. package/docs/api.md +284 -0
  117. package/docs/date-string+format.md +90 -0
  118. package/docs/i18n.md +99 -0
  119. package/docs/images/datepicker-inline.jpg +0 -0
  120. package/docs/images/datepicker.jpg +0 -0
  121. package/docs/images/multidate.jpg +0 -0
  122. package/docs/images/picker-structure.jpg +0 -0
  123. package/docs/images/rangepicker.jpg +0 -0
  124. package/docs/images/view-days.jpg +0 -0
  125. package/docs/images/view-decades.jpg +0 -0
  126. package/docs/images/view-months.jpg +0 -0
  127. package/docs/images/view-years.jpg +0 -0
  128. package/docs/index.html +26 -0
  129. package/docs/options.md +354 -0
  130. package/docs/overview.md +174 -0
  131. package/extras/twoDigitToFullYear/test/twoDigitToFullYear.js +58 -0
  132. package/extras/twoDigitToFullYear/twoDigitToFullYear.js +26 -0
  133. package/js/DateRangePicker.js +210 -0
  134. package/js/Datepicker.js +487 -0
  135. package/js/datepicker-full.js +5 -0
  136. package/js/events/functions.js +48 -0
  137. package/js/events/inputFieldListeners.js +206 -0
  138. package/js/events/otherListeners.js +15 -0
  139. package/js/events/pickerListeners.js +70 -0
  140. package/js/i18n/base-locales.js +13 -0
  141. package/js/i18n/locales/ar-tn.js +15 -0
  142. package/js/i18n/locales/ar.js +15 -0
  143. package/js/i18n/locales/az.js +14 -0
  144. package/js/i18n/locales/bg.js +14 -0
  145. package/js/i18n/locales/bm.js +18 -0
  146. package/js/i18n/locales/bn.js +19 -0
  147. package/js/i18n/locales/br.js +18 -0
  148. package/js/i18n/locales/bs.js +15 -0
  149. package/js/i18n/locales/ca.js +18 -0
  150. package/js/i18n/locales/cs.js +19 -0
  151. package/js/i18n/locales/cy.js +14 -0
  152. package/js/i18n/locales/da.js +19 -0
  153. package/js/i18n/locales/de.js +18 -0
  154. package/js/i18n/locales/el.js +16 -0
  155. package/js/i18n/locales/en-AU.js +18 -0
  156. package/js/i18n/locales/en-CA.js +18 -0
  157. package/js/i18n/locales/en-GB.js +18 -0
  158. package/js/i18n/locales/en-IE.js +17 -0
  159. package/js/i18n/locales/en-NZ.js +17 -0
  160. package/js/i18n/locales/en-ZA.js +17 -0
  161. package/js/i18n/locales/eo.js +17 -0
  162. package/js/i18n/locales/es.js +18 -0
  163. package/js/i18n/locales/et.js +18 -0
  164. package/js/i18n/locales/eu.js +18 -0
  165. package/js/i18n/locales/fa.js +17 -0
  166. package/js/i18n/locales/fi.js +17 -0
  167. package/js/i18n/locales/fo.js +15 -0
  168. package/js/i18n/locales/fr-CH.js +21 -0
  169. package/js/i18n/locales/fr.js +18 -0
  170. package/js/i18n/locales/gl.js +16 -0
  171. package/js/i18n/locales/he.js +15 -0
  172. package/js/i18n/locales/hi.js +18 -0
  173. package/js/i18n/locales/hr.js +13 -0
  174. package/js/i18n/locales/hu.js +18 -0
  175. package/js/i18n/locales/hy.js +18 -0
  176. package/js/i18n/locales/id.js +15 -0
  177. package/js/i18n/locales/is.js +14 -0
  178. package/js/i18n/locales/it-CH.js +20 -0
  179. package/js/i18n/locales/it.js +18 -0
  180. package/js/i18n/locales/ja.js +17 -0
  181. package/js/i18n/locales/ka.js +17 -0
  182. package/js/i18n/locales/kk.js +15 -0
  183. package/js/i18n/locales/km.js +15 -0
  184. package/js/i18n/locales/ko.js +18 -0
  185. package/js/i18n/locales/lt.js +19 -0
  186. package/js/i18n/locales/lv.js +18 -0
  187. package/js/i18n/locales/me.js +17 -0
  188. package/js/i18n/locales/mk.js +15 -0
  189. package/js/i18n/locales/mn.js +17 -0
  190. package/js/i18n/locales/mr.js +18 -0
  191. package/js/i18n/locales/ms.js +15 -0
  192. package/js/i18n/locales/nl-BE.js +18 -0
  193. package/js/i18n/locales/nl.js +18 -0
  194. package/js/i18n/locales/no.js +18 -0
  195. package/js/i18n/locales/oc.js +17 -0
  196. package/js/i18n/locales/pl.js +17 -0
  197. package/js/i18n/locales/pt-BR.js +17 -0
  198. package/js/i18n/locales/pt.js +18 -0
  199. package/js/i18n/locales/ro.js +17 -0
  200. package/js/i18n/locales/ru.js +18 -0
  201. package/js/i18n/locales/si.js +18 -0
  202. package/js/i18n/locales/sk.js +18 -0
  203. package/js/i18n/locales/sl.js +15 -0
  204. package/js/i18n/locales/sq.js +18 -0
  205. package/js/i18n/locales/sr-latn.js +16 -0
  206. package/js/i18n/locales/sr.js +16 -0
  207. package/js/i18n/locales/sv.js +17 -0
  208. package/js/i18n/locales/sw.js +15 -0
  209. package/js/i18n/locales/ta.js +18 -0
  210. package/js/i18n/locales/tg.js +19 -0
  211. package/js/i18n/locales/th.js +14 -0
  212. package/js/i18n/locales/tk.js +18 -0
  213. package/js/i18n/locales/tr.js +17 -0
  214. package/js/i18n/locales/uk.js +17 -0
  215. package/js/i18n/locales/uz-cyrl.js +18 -0
  216. package/js/i18n/locales/uz-latn.js +18 -0
  217. package/js/i18n/locales/vi.js +16 -0
  218. package/js/i18n/locales/zh-CN.js +19 -0
  219. package/js/i18n/locales/zh-TW.js +18 -0
  220. package/js/lib/date-format.js +185 -0
  221. package/js/lib/date.js +82 -0
  222. package/js/lib/dom.js +55 -0
  223. package/js/lib/event.js +68 -0
  224. package/js/lib/utils.js +61 -0
  225. package/js/main.js +4 -0
  226. package/js/options/defaultOptions.js +38 -0
  227. package/js/options/processOptions.js +263 -0
  228. package/js/picker/Picker.js +334 -0
  229. package/js/picker/templates/calendarWeeksTemplate.js +8 -0
  230. package/js/picker/templates/daysTemplate.js +8 -0
  231. package/js/picker/templates/pickerTemplate.js +23 -0
  232. package/js/picker/views/DaysView.js +250 -0
  233. package/js/picker/views/MonthsView.js +198 -0
  234. package/js/picker/views/View.js +55 -0
  235. package/js/picker/views/YearsView.js +170 -0
  236. package/package.json +81 -0
  237. package/postcss.config.js +5 -0
  238. package/rollup.config.js +75 -0
  239. package/sass/_mixins.scss +12 -0
  240. package/sass/datepicker-bs4.scss +91 -0
  241. package/sass/datepicker-bs5.scss +91 -0
  242. package/sass/datepicker-bulma.scss +69 -0
  243. package/sass/datepicker-foundation.scss +66 -0
  244. package/sass/datepicker.scss +436 -0
  245. package/sass/index-bs4.scss +5 -0
  246. package/sass/index-bs5.scss +5 -0
  247. package/sass/index-bulma.scss +6 -0
  248. package/sass/index-foundation.scss +3 -0
  249. package/scripts/build-css.js +39 -0
  250. package/scripts/build-locales.js +57 -0
  251. package/scripts/convert-bsdp-locales.js +65 -0
  252. package/scripts/minify-css.js +31 -0
  253. package/scripts/minify-js.js +17 -0
  254. package/style.css +10 -0
  255. package/tailwind.config.js +16 -0
  256. package/tailwind.css +1389 -0
  257. package/test/DateRangePicker/DateRangePicker.js +547 -0
  258. package/test/DateRangePicker/api-methods.js +415 -0
  259. package/test/DateRangePicker/date-selection.js +472 -0
  260. package/test/DateRangePicker/options.js +308 -0
  261. package/test/Datepicker/Datepicker-object.js +236 -0
  262. package/test/Datepicker/api-methods.js +328 -0
  263. package/test/_utils/date.js +102 -0
  264. package/test/_utils/dom.js +70 -0
  265. package/test/events.js +785 -0
  266. package/test/inline-mode.js +45 -0
  267. package/test/keyboard-operation/arrow-down.js +293 -0
  268. package/test/keyboard-operation/arrow-left.js +255 -0
  269. package/test/keyboard-operation/arrow-right.js +215 -0
  270. package/test/keyboard-operation/arrow-up.js +461 -0
  271. package/test/keyboard-operation/edit-mode.js +458 -0
  272. package/test/keyboard-operation/keyboard-operation.js +146 -0
  273. package/test/mouse-operation.js +580 -0
  274. package/test/options/before-show.js +635 -0
  275. package/test/options/bulma-datepicker.sublime-workspace +1280 -0
  276. package/test/options/buttons.js +383 -0
  277. package/test/options/date-restrictions.js +802 -0
  278. package/test/options/format.js +281 -0
  279. package/test/options/multidate.js +380 -0
  280. package/test/options/options.js +727 -0
  281. package/test/options/orientation.js +410 -0
  282. package/test/options/pick-levle+view.js +357 -0
  283. package/test/test.html +94 -0
  284. package/test/unit/DateRangePicker.js +192 -0
  285. package/test/unit/Datepicker.js +307 -0
  286. package/test/unit/_setup.js +28 -0
  287. package/test/unit/lib/date-format.js +310 -0
  288. package/test/unit/lib/date.js +211 -0
  289. package/test/unit/lib/dom.js +142 -0
  290. package/test/unit/lib/event.js +207 -0
  291. package/test/unit/lib/utils.js +135 -0
@@ -0,0 +1,2999 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _arrayLikeToArray(r, a) {
6
+ (null == a || a > r.length) && (a = r.length);
7
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
8
+ return n;
9
+ }
10
+ function _arrayWithHoles(r) {
11
+ if (Array.isArray(r)) return r;
12
+ }
13
+ function _arrayWithoutHoles(r) {
14
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
15
+ }
16
+ function _assertThisInitialized(e) {
17
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
18
+ return e;
19
+ }
20
+ function _callSuper(t, o, e) {
21
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
22
+ }
23
+ function _classCallCheck(a, n) {
24
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
25
+ }
26
+ function _defineProperties(e, r) {
27
+ for (var t = 0; t < r.length; t++) {
28
+ var o = r[t];
29
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
30
+ }
31
+ }
32
+ function _createClass(e, r, t) {
33
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
34
+ writable: !1
35
+ }), e;
36
+ }
37
+ function _get() {
38
+ return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
39
+ var p = _superPropBase(e, t);
40
+ if (p) {
41
+ var n = Object.getOwnPropertyDescriptor(p, t);
42
+ return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
43
+ }
44
+ }, _get.apply(null, arguments);
45
+ }
46
+ function _getPrototypeOf(t) {
47
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
48
+ return t.__proto__ || Object.getPrototypeOf(t);
49
+ }, _getPrototypeOf(t);
50
+ }
51
+ function _inherits(t, e) {
52
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
53
+ t.prototype = Object.create(e && e.prototype, {
54
+ constructor: {
55
+ value: t,
56
+ writable: !0,
57
+ configurable: !0
58
+ }
59
+ }), Object.defineProperty(t, "prototype", {
60
+ writable: !1
61
+ }), e && _setPrototypeOf(t, e);
62
+ }
63
+ function _isNativeReflectConstruct() {
64
+ try {
65
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
66
+ } catch (t) {}
67
+ return (_isNativeReflectConstruct = function () {
68
+ return !!t;
69
+ })();
70
+ }
71
+ function _iterableToArray(r) {
72
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
73
+ }
74
+ function _iterableToArrayLimit(r, l) {
75
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
76
+ if (null != t) {
77
+ var e,
78
+ n,
79
+ i,
80
+ u,
81
+ a = [],
82
+ f = !0,
83
+ o = !1;
84
+ try {
85
+ if (i = (t = t.call(r)).next, 0 === l) {
86
+ if (Object(t) !== t) return;
87
+ f = !1;
88
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
89
+ } catch (r) {
90
+ o = !0, n = r;
91
+ } finally {
92
+ try {
93
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
94
+ } finally {
95
+ if (o) throw n;
96
+ }
97
+ }
98
+ return a;
99
+ }
100
+ }
101
+ function _nonIterableRest() {
102
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
103
+ }
104
+ function _nonIterableSpread() {
105
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
106
+ }
107
+ function _possibleConstructorReturn(t, e) {
108
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
109
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
110
+ return _assertThisInitialized(t);
111
+ }
112
+ function _setPrototypeOf(t, e) {
113
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
114
+ return t.__proto__ = e, t;
115
+ }, _setPrototypeOf(t, e);
116
+ }
117
+ function _slicedToArray(r, e) {
118
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
119
+ }
120
+ function _superPropBase(t, o) {
121
+ for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
122
+ return t;
123
+ }
124
+ function _toConsumableArray(r) {
125
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
126
+ }
127
+ function _toPrimitive(t, r) {
128
+ if ("object" != typeof t || !t) return t;
129
+ var e = t[Symbol.toPrimitive];
130
+ if (void 0 !== e) {
131
+ var i = e.call(t, r || "default");
132
+ if ("object" != typeof i) return i;
133
+ throw new TypeError("@@toPrimitive must return a primitive value.");
134
+ }
135
+ return ("string" === r ? String : Number)(t);
136
+ }
137
+ function _toPropertyKey(t) {
138
+ var i = _toPrimitive(t, "string");
139
+ return "symbol" == typeof i ? i : i + "";
140
+ }
141
+ function _typeof(o) {
142
+ "@babel/helpers - typeof";
143
+
144
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
145
+ return typeof o;
146
+ } : function (o) {
147
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
148
+ }, _typeof(o);
149
+ }
150
+ function _unsupportedIterableToArray(r, a) {
151
+ if (r) {
152
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
153
+ var t = {}.toString.call(r).slice(8, -1);
154
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
155
+ }
156
+ }
157
+
158
+ function hasProperty(obj, prop) {
159
+ return Object.prototype.hasOwnProperty.call(obj, prop);
160
+ }
161
+ function lastItemOf(arr) {
162
+ return arr[arr.length - 1];
163
+ }
164
+
165
+ // push only the items not included in the array
166
+ function pushUnique(arr) {
167
+ for (var _len = arguments.length, items = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
168
+ items[_key - 1] = arguments[_key];
169
+ }
170
+ items.forEach(function (item) {
171
+ if (arr.includes(item)) {
172
+ return;
173
+ }
174
+ arr.push(item);
175
+ });
176
+ return arr;
177
+ }
178
+ function stringToArray(str, separator) {
179
+ // convert empty string to an empty array
180
+ return str ? str.split(separator) : [];
181
+ }
182
+ function isInRange(testVal, min, max) {
183
+ var minOK = min === undefined || testVal >= min;
184
+ var maxOK = max === undefined || testVal <= max;
185
+ return minOK && maxOK;
186
+ }
187
+ function limitToRange(val, min, max) {
188
+ if (val < min) {
189
+ return min;
190
+ }
191
+ if (val > max) {
192
+ return max;
193
+ }
194
+ return val;
195
+ }
196
+ function createTagRepeat(tagName, repeat) {
197
+ var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
198
+ var index = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
199
+ var html = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
200
+ var openTagSrc = Object.keys(attributes).reduce(function (src, attr) {
201
+ var val = attributes[attr];
202
+ if (typeof val === 'function') {
203
+ val = val(index);
204
+ }
205
+ return "".concat(src, " ").concat(attr, "=\"").concat(val, "\"");
206
+ }, tagName);
207
+ html += "<".concat(openTagSrc, "></").concat(tagName, ">");
208
+ var next = index + 1;
209
+ return next < repeat ? createTagRepeat(tagName, repeat, attributes, next, html) : html;
210
+ }
211
+
212
+ // Remove the spacing surrounding tags for HTML parser not to create text nodes
213
+ // before/after elements
214
+ function optimizeTemplateHTML(html) {
215
+ return html.replace(/>\s+/g, '>').replace(/\s+</, '<');
216
+ }
217
+
218
+ function stripTime(timeValue) {
219
+ return new Date(timeValue).setHours(0, 0, 0, 0);
220
+ }
221
+ function today() {
222
+ return new Date().setHours(0, 0, 0, 0);
223
+ }
224
+
225
+ // Get the time value of the start of given date or year, month and day
226
+ function dateValue() {
227
+ switch (arguments.length) {
228
+ case 0:
229
+ return today();
230
+ case 1:
231
+ return stripTime(arguments.length <= 0 ? undefined : arguments[0]);
232
+ }
233
+
234
+ // use setFullYear() to keep 2-digit year from being mapped to 1900-1999
235
+ var newDate = new Date(0);
236
+ newDate.setFullYear.apply(newDate, arguments);
237
+ return newDate.setHours(0, 0, 0, 0);
238
+ }
239
+ function addDays(date, amount) {
240
+ var newDate = new Date(date);
241
+ return newDate.setDate(newDate.getDate() + amount);
242
+ }
243
+ function addWeeks(date, amount) {
244
+ return addDays(date, amount * 7);
245
+ }
246
+ function addMonths(date, amount) {
247
+ // If the day of the date is not in the new month, the last day of the new
248
+ // month will be returned. e.g. Jan 31 + 1 month → Feb 28 (not Mar 03)
249
+ var newDate = new Date(date);
250
+ var monthsToSet = newDate.getMonth() + amount;
251
+ var expectedMonth = monthsToSet % 12;
252
+ if (expectedMonth < 0) {
253
+ expectedMonth += 12;
254
+ }
255
+ var time = newDate.setMonth(monthsToSet);
256
+ return newDate.getMonth() !== expectedMonth ? newDate.setDate(0) : time;
257
+ }
258
+ function addYears(date, amount) {
259
+ // If the date is Feb 29 and the new year is not a leap year, Feb 28 of the
260
+ // new year will be returned.
261
+ var newDate = new Date(date);
262
+ var expectedMonth = newDate.getMonth();
263
+ var time = newDate.setFullYear(newDate.getFullYear() + amount);
264
+ return expectedMonth === 1 && newDate.getMonth() === 2 ? newDate.setDate(0) : time;
265
+ }
266
+
267
+ // Calculate the distance bettwen 2 days of the week
268
+ function dayDiff(day, from) {
269
+ return (day - from + 7) % 7;
270
+ }
271
+
272
+ // Get the date of the specified day of the week of given base date
273
+ function dayOfTheWeekOf(baseDate, dayOfWeek) {
274
+ var weekStart = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
275
+ var baseDay = new Date(baseDate).getDay();
276
+ return addDays(baseDate, dayDiff(dayOfWeek, weekStart) - dayDiff(baseDay, weekStart));
277
+ }
278
+
279
+ // Get the ISO week of a date
280
+ function getWeek(date) {
281
+ // start of ISO week is Monday
282
+ var thuOfTheWeek = dayOfTheWeekOf(date, 4, 1);
283
+ // 1st week == the week where the 4th of January is in
284
+ var firstThu = dayOfTheWeekOf(new Date(thuOfTheWeek).setMonth(0, 4), 4, 1);
285
+ return Math.round((thuOfTheWeek - firstThu) / 604800000) + 1;
286
+ }
287
+
288
+ // Get the start year of the period of years that includes given date
289
+ // years: length of the year period
290
+ function startOfYearPeriod(date, years) {
291
+ /* @see https://en.wikipedia.org/wiki/Year_zero#ISO_8601 */
292
+ var year = new Date(date).getFullYear();
293
+ return Math.floor(year / years) * years;
294
+ }
295
+
296
+ // pattern for format parts
297
+ var reFormatTokens = /dd?|DD?|mm?|MM?|yy?(?:yy)?/;
298
+ // pattern for non date parts
299
+ var reNonDateParts = /[\s!-/:-@[-`{-~年月日]+/;
300
+ // cache for persed formats
301
+ var knownFormats = {};
302
+ // parse funtions for date parts
303
+ var parseFns = {
304
+ y: function y(date, year) {
305
+ return new Date(date).setFullYear(parseInt(year, 10));
306
+ },
307
+ m: function m(date, month, locale) {
308
+ var newDate = new Date(date);
309
+ var monthIndex = parseInt(month, 10) - 1;
310
+ if (isNaN(monthIndex)) {
311
+ if (!month) {
312
+ return NaN;
313
+ }
314
+ var monthName = month.toLowerCase();
315
+ var compareNames = function compareNames(name) {
316
+ return name.toLowerCase().startsWith(monthName);
317
+ };
318
+ // compare with both short and full names because some locales have periods
319
+ // in the short names (not equal to the first X letters of the full names)
320
+ monthIndex = locale.monthsShort.findIndex(compareNames);
321
+ if (monthIndex < 0) {
322
+ monthIndex = locale.months.findIndex(compareNames);
323
+ }
324
+ if (monthIndex < 0) {
325
+ return NaN;
326
+ }
327
+ }
328
+ newDate.setMonth(monthIndex);
329
+ return newDate.getMonth() !== normalizeMonth(monthIndex) ? newDate.setDate(0) : newDate.getTime();
330
+ },
331
+ d: function d(date, day) {
332
+ return new Date(date).setDate(parseInt(day, 10));
333
+ }
334
+ };
335
+ // format functions for date parts
336
+ var formatFns = {
337
+ d: function d(date) {
338
+ return date.getDate();
339
+ },
340
+ dd: function dd(date) {
341
+ return padZero(date.getDate(), 2);
342
+ },
343
+ D: function D(date, locale) {
344
+ return locale.daysShort[date.getDay()];
345
+ },
346
+ DD: function DD(date, locale) {
347
+ return locale.days[date.getDay()];
348
+ },
349
+ m: function m(date) {
350
+ return date.getMonth() + 1;
351
+ },
352
+ mm: function mm(date) {
353
+ return padZero(date.getMonth() + 1, 2);
354
+ },
355
+ M: function M(date, locale) {
356
+ return locale.monthsShort[date.getMonth()];
357
+ },
358
+ MM: function MM(date, locale) {
359
+ return locale.months[date.getMonth()];
360
+ },
361
+ y: function y(date) {
362
+ return date.getFullYear();
363
+ },
364
+ yy: function yy(date) {
365
+ return padZero(date.getFullYear(), 2).slice(-2);
366
+ },
367
+ yyyy: function yyyy(date) {
368
+ return padZero(date.getFullYear(), 4);
369
+ }
370
+ };
371
+
372
+ // get month index in normal range (0 - 11) from any number
373
+ function normalizeMonth(monthIndex) {
374
+ return monthIndex > -1 ? monthIndex % 12 : normalizeMonth(monthIndex + 12);
375
+ }
376
+ function padZero(num, length) {
377
+ return num.toString().padStart(length, '0');
378
+ }
379
+ function parseFormatString(format) {
380
+ if (typeof format !== 'string') {
381
+ throw new Error("Invalid date format.");
382
+ }
383
+ if (format in knownFormats) {
384
+ return knownFormats[format];
385
+ }
386
+
387
+ // sprit the format string into parts and seprators
388
+ var separators = format.split(reFormatTokens);
389
+ var parts = format.match(new RegExp(reFormatTokens, 'g'));
390
+ if (separators.length === 0 || !parts) {
391
+ throw new Error("Invalid date format.");
392
+ }
393
+
394
+ // collect format functions used in the format
395
+ var partFormatters = parts.map(function (token) {
396
+ return formatFns[token];
397
+ });
398
+
399
+ // collect parse function keys used in the format
400
+ // iterate over parseFns' keys in order to keep the order of the keys.
401
+ var partParserKeys = Object.keys(parseFns).reduce(function (keys, key) {
402
+ var token = parts.find(function (part) {
403
+ return part[0] !== 'D' && part[0].toLowerCase() === key;
404
+ });
405
+ if (token) {
406
+ keys.push(key);
407
+ }
408
+ return keys;
409
+ }, []);
410
+ return knownFormats[format] = {
411
+ parser: function parser(dateStr, locale) {
412
+ var dateParts = dateStr.split(reNonDateParts).reduce(function (dtParts, part, index) {
413
+ if (part.length > 0 && parts[index]) {
414
+ var token = parts[index][0];
415
+ if (token === 'M') {
416
+ dtParts.m = part;
417
+ } else if (token !== 'D') {
418
+ dtParts[token] = part;
419
+ }
420
+ }
421
+ return dtParts;
422
+ }, {});
423
+
424
+ // iterate over partParserkeys so that the parsing is made in the oder
425
+ // of year, month and day to prevent the day parser from correcting last
426
+ // day of month wrongly
427
+ return partParserKeys.reduce(function (origDate, key) {
428
+ var newDate = parseFns[key](origDate, dateParts[key], locale);
429
+ // ingnore the part failed to parse
430
+ return isNaN(newDate) ? origDate : newDate;
431
+ }, today());
432
+ },
433
+ formatter: function formatter(date, locale) {
434
+ var dateStr = partFormatters.reduce(function (str, fn, index) {
435
+ return str += "".concat(separators[index]).concat(fn(date, locale));
436
+ }, '');
437
+ // separators' length is always parts' length + 1,
438
+ return dateStr += lastItemOf(separators);
439
+ }
440
+ };
441
+ }
442
+ function parseDate(dateStr, format, locale) {
443
+ if (dateStr instanceof Date || typeof dateStr === 'number') {
444
+ var date = stripTime(dateStr);
445
+ return isNaN(date) ? undefined : date;
446
+ }
447
+ if (!dateStr) {
448
+ return undefined;
449
+ }
450
+ if (dateStr === 'today') {
451
+ return today();
452
+ }
453
+ if (format && format.toValue) {
454
+ var _date = format.toValue(dateStr, format, locale);
455
+ return isNaN(_date) ? undefined : stripTime(_date);
456
+ }
457
+ return parseFormatString(format).parser(dateStr, locale);
458
+ }
459
+ function formatDate(date, format, locale) {
460
+ if (isNaN(date) || !date && date !== 0) {
461
+ return '';
462
+ }
463
+ var dateObj = typeof date === 'number' ? new Date(date) : date;
464
+ if (format.toDisplay) {
465
+ return format.toDisplay(dateObj, format, locale);
466
+ }
467
+ return parseFormatString(format).formatter(dateObj, locale);
468
+ }
469
+
470
+ var listenerRegistry = new WeakMap();
471
+ var _EventTarget$prototyp = EventTarget.prototype,
472
+ addEventListener = _EventTarget$prototyp.addEventListener,
473
+ removeEventListener = _EventTarget$prototyp.removeEventListener;
474
+
475
+ // Register event listeners to a key object
476
+ // listeners: array of listener definitions;
477
+ // - each definition must be a flat array of event target and the arguments
478
+ // used to call addEventListener() on the target
479
+ function registerListeners(keyObj, listeners) {
480
+ var registered = listenerRegistry.get(keyObj);
481
+ if (!registered) {
482
+ registered = [];
483
+ listenerRegistry.set(keyObj, registered);
484
+ }
485
+ listeners.forEach(function (listener) {
486
+ addEventListener.call.apply(addEventListener, _toConsumableArray(listener));
487
+ registered.push(listener);
488
+ });
489
+ }
490
+ function unregisterListeners(keyObj) {
491
+ var listeners = listenerRegistry.get(keyObj);
492
+ if (!listeners) {
493
+ return;
494
+ }
495
+ listeners.forEach(function (listener) {
496
+ removeEventListener.call.apply(removeEventListener, _toConsumableArray(listener));
497
+ });
498
+ listenerRegistry["delete"](keyObj);
499
+ }
500
+
501
+ // Event.composedPath() polyfill for Edge
502
+ // based on https://gist.github.com/kleinfreund/e9787d73776c0e3750dcfcdc89f100ec
503
+ if (!Event.prototype.composedPath) {
504
+ var getComposedPath = function getComposedPath(node) {
505
+ var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
506
+ path.push(node);
507
+ var parent;
508
+ if (node.parentNode) {
509
+ parent = node.parentNode;
510
+ } else if (node.host) {
511
+ // ShadowRoot
512
+ parent = node.host;
513
+ } else if (node.defaultView) {
514
+ // Document
515
+ parent = node.defaultView;
516
+ }
517
+ return parent ? getComposedPath(parent, path) : path;
518
+ };
519
+ Event.prototype.composedPath = function () {
520
+ return getComposedPath(this.target);
521
+ };
522
+ }
523
+ function findFromPath(path, criteria, currentTarget) {
524
+ var index = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
525
+ var el = path[index];
526
+ if (criteria(el)) {
527
+ return el;
528
+ } else if (el === currentTarget || !el.parentElement) {
529
+ // stop when reaching currentTarget or <html>
530
+ return;
531
+ }
532
+ return findFromPath(path, criteria, currentTarget, index + 1);
533
+ }
534
+
535
+ // Search for the actual target of a delegated event
536
+ function findElementInEventPath(ev, selector) {
537
+ var criteria = typeof selector === 'function' ? selector : function (el) {
538
+ return el.matches(selector);
539
+ };
540
+ return findFromPath(ev.composedPath(), criteria, ev.currentTarget);
541
+ }
542
+
543
+ // default locales
544
+ var locales = {
545
+ en: {
546
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
547
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
548
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
549
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
550
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
551
+ today: "Today",
552
+ clear: "Clear",
553
+ titleFormat: "MM y"
554
+ }
555
+ };
556
+
557
+ // config options updatable by setOptions() and their default values
558
+ var defaultOptions = {
559
+ autohide: false,
560
+ beforeShowDay: null,
561
+ beforeShowDecade: null,
562
+ beforeShowMonth: null,
563
+ beforeShowYear: null,
564
+ calendarWeeks: false,
565
+ clearBtn: false,
566
+ dateDelimiter: ',',
567
+ datesDisabled: [],
568
+ daysOfWeekDisabled: [],
569
+ daysOfWeekHighlighted: [],
570
+ defaultViewDate: undefined,
571
+ // placeholder, defaults to today() by the program
572
+ disableTouchKeyboard: false,
573
+ format: 'mm/dd/yyyy',
574
+ language: 'en',
575
+ maxDate: null,
576
+ maxNumberOfDates: 1,
577
+ maxView: 3,
578
+ minDate: null,
579
+ nextArrow: '<svg class="w-4 h-4 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 10"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5h12m0 0L9 1m4 4L9 9"/></svg>',
580
+ orientation: 'auto',
581
+ pickLevel: 0,
582
+ prevArrow: '<svg class="w-4 h-4 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 10"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 5H1m0 0 4 4M1 5l4-4"/></svg>',
583
+ showDaysOfWeek: true,
584
+ showOnClick: true,
585
+ showOnFocus: true,
586
+ startView: 0,
587
+ title: '',
588
+ todayBtn: false,
589
+ todayBtnMode: 0,
590
+ todayHighlight: false,
591
+ updateOnBlur: true,
592
+ weekStart: 0
593
+ };
594
+
595
+ var range = null;
596
+ function parseHTML(html) {
597
+ if (range == null) {
598
+ range = document.createRange();
599
+ }
600
+ return range.createContextualFragment(html);
601
+ }
602
+ function hideElement(el) {
603
+ if (el.style.display === 'none') {
604
+ return;
605
+ }
606
+ // back up the existing display setting in data-style-display
607
+ if (el.style.display) {
608
+ el.dataset.styleDisplay = el.style.display;
609
+ }
610
+ el.style.display = 'none';
611
+ }
612
+ function showElement(el) {
613
+ if (el.style.display !== 'none') {
614
+ return;
615
+ }
616
+ if (el.dataset.styleDisplay) {
617
+ // restore backed-up dispay property
618
+ el.style.display = el.dataset.styleDisplay;
619
+ delete el.dataset.styleDisplay;
620
+ } else {
621
+ el.style.display = '';
622
+ }
623
+ }
624
+ function emptyChildNodes(el) {
625
+ if (el.firstChild) {
626
+ el.removeChild(el.firstChild);
627
+ emptyChildNodes(el);
628
+ }
629
+ }
630
+ function replaceChildNodes(el, newChildNodes) {
631
+ emptyChildNodes(el);
632
+ if (newChildNodes instanceof DocumentFragment) {
633
+ el.appendChild(newChildNodes);
634
+ } else if (typeof newChildNodes === 'string') {
635
+ el.appendChild(parseHTML(newChildNodes));
636
+ } else if (typeof newChildNodes.forEach === 'function') {
637
+ newChildNodes.forEach(function (node) {
638
+ el.appendChild(node);
639
+ });
640
+ }
641
+ }
642
+
643
+ var defaultLang = defaultOptions.language,
644
+ defaultFormat = defaultOptions.format,
645
+ defaultWeekStart = defaultOptions.weekStart;
646
+
647
+ // Reducer function to filter out invalid day-of-week from the input
648
+ function sanitizeDOW(dow, day) {
649
+ return dow.length < 6 && day >= 0 && day < 7 ? pushUnique(dow, day) : dow;
650
+ }
651
+ function calcEndOfWeek(startOfWeek) {
652
+ return (startOfWeek + 6) % 7;
653
+ }
654
+
655
+ // validate input date. if invalid, fallback to the original value
656
+ function validateDate(value, format, locale, origValue) {
657
+ var date = parseDate(value, format, locale);
658
+ return date !== undefined ? date : origValue;
659
+ }
660
+
661
+ // Validate viewId. if invalid, fallback to the original value
662
+ function validateViewId(value, origValue) {
663
+ var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
664
+ var viewId = parseInt(value, 10);
665
+ return viewId >= 0 && viewId <= max ? viewId : origValue;
666
+ }
667
+
668
+ // Create Datepicker configuration to set
669
+ function processOptions(options, datepicker) {
670
+ var inOpts = Object.assign({}, options);
671
+ var config = {};
672
+ var locales = datepicker.constructor.locales;
673
+ var _ref = datepicker.config || {},
674
+ format = _ref.format,
675
+ language = _ref.language,
676
+ locale = _ref.locale,
677
+ maxDate = _ref.maxDate,
678
+ maxView = _ref.maxView,
679
+ minDate = _ref.minDate,
680
+ pickLevel = _ref.pickLevel,
681
+ startView = _ref.startView,
682
+ weekStart = _ref.weekStart;
683
+ if (inOpts.language) {
684
+ var lang;
685
+ if (inOpts.language !== language) {
686
+ if (locales[inOpts.language]) {
687
+ lang = inOpts.language;
688
+ } else {
689
+ // Check if langauge + region tag can fallback to the one without
690
+ // region (e.g. fr-CA → fr)
691
+ lang = inOpts.language.split('-')[0];
692
+ if (locales[lang] === undefined) {
693
+ lang = false;
694
+ }
695
+ }
696
+ }
697
+ delete inOpts.language;
698
+ if (lang) {
699
+ language = config.language = lang;
700
+
701
+ // update locale as well when updating language
702
+ var origLocale = locale || locales[defaultLang];
703
+ // use default language's properties for the fallback
704
+ locale = Object.assign({
705
+ format: defaultFormat,
706
+ weekStart: defaultWeekStart
707
+ }, locales[defaultLang]);
708
+ if (language !== defaultLang) {
709
+ Object.assign(locale, locales[language]);
710
+ }
711
+ config.locale = locale;
712
+ // if format and/or weekStart are the same as old locale's defaults,
713
+ // update them to new locale's defaults
714
+ if (format === origLocale.format) {
715
+ format = config.format = locale.format;
716
+ }
717
+ if (weekStart === origLocale.weekStart) {
718
+ weekStart = config.weekStart = locale.weekStart;
719
+ config.weekEnd = calcEndOfWeek(locale.weekStart);
720
+ }
721
+ }
722
+ }
723
+ if (inOpts.format) {
724
+ var hasToDisplay = typeof inOpts.format.toDisplay === 'function';
725
+ var hasToValue = typeof inOpts.format.toValue === 'function';
726
+ var validFormatString = reFormatTokens.test(inOpts.format);
727
+ if (hasToDisplay && hasToValue || validFormatString) {
728
+ format = config.format = inOpts.format;
729
+ }
730
+ delete inOpts.format;
731
+ }
732
+
733
+ //*** dates ***//
734
+ // while min and maxDate for "no limit" in the options are better to be null
735
+ // (especially when updating), the ones in the config have to be undefined
736
+ // because null is treated as 0 (= unix epoch) when comparing with time value
737
+ var minDt = minDate;
738
+ var maxDt = maxDate;
739
+ if (inOpts.minDate !== undefined) {
740
+ minDt = inOpts.minDate === null ? dateValue(0, 0, 1) // set 0000-01-01 to prevent negative values for year
741
+ : validateDate(inOpts.minDate, format, locale, minDt);
742
+ delete inOpts.minDate;
743
+ }
744
+ if (inOpts.maxDate !== undefined) {
745
+ maxDt = inOpts.maxDate === null ? undefined : validateDate(inOpts.maxDate, format, locale, maxDt);
746
+ delete inOpts.maxDate;
747
+ }
748
+ if (maxDt < minDt) {
749
+ minDate = config.minDate = maxDt;
750
+ maxDate = config.maxDate = minDt;
751
+ } else {
752
+ if (minDate !== minDt) {
753
+ minDate = config.minDate = minDt;
754
+ }
755
+ if (maxDate !== maxDt) {
756
+ maxDate = config.maxDate = maxDt;
757
+ }
758
+ }
759
+ if (inOpts.datesDisabled) {
760
+ config.datesDisabled = inOpts.datesDisabled.reduce(function (dates, dt) {
761
+ var date = parseDate(dt, format, locale);
762
+ return date !== undefined ? pushUnique(dates, date) : dates;
763
+ }, []);
764
+ delete inOpts.datesDisabled;
765
+ }
766
+ if (inOpts.defaultViewDate !== undefined) {
767
+ var viewDate = parseDate(inOpts.defaultViewDate, format, locale);
768
+ if (viewDate !== undefined) {
769
+ config.defaultViewDate = viewDate;
770
+ }
771
+ delete inOpts.defaultViewDate;
772
+ }
773
+
774
+ //*** days of week ***//
775
+ if (inOpts.weekStart !== undefined) {
776
+ var wkStart = Number(inOpts.weekStart) % 7;
777
+ if (!isNaN(wkStart)) {
778
+ weekStart = config.weekStart = wkStart;
779
+ config.weekEnd = calcEndOfWeek(wkStart);
780
+ }
781
+ delete inOpts.weekStart;
782
+ }
783
+ if (inOpts.daysOfWeekDisabled) {
784
+ config.daysOfWeekDisabled = inOpts.daysOfWeekDisabled.reduce(sanitizeDOW, []);
785
+ delete inOpts.daysOfWeekDisabled;
786
+ }
787
+ if (inOpts.daysOfWeekHighlighted) {
788
+ config.daysOfWeekHighlighted = inOpts.daysOfWeekHighlighted.reduce(sanitizeDOW, []);
789
+ delete inOpts.daysOfWeekHighlighted;
790
+ }
791
+
792
+ //*** multi date ***//
793
+ if (inOpts.maxNumberOfDates !== undefined) {
794
+ var maxNumberOfDates = parseInt(inOpts.maxNumberOfDates, 10);
795
+ if (maxNumberOfDates >= 0) {
796
+ config.maxNumberOfDates = maxNumberOfDates;
797
+ config.multidate = maxNumberOfDates !== 1;
798
+ }
799
+ delete inOpts.maxNumberOfDates;
800
+ }
801
+ if (inOpts.dateDelimiter) {
802
+ config.dateDelimiter = String(inOpts.dateDelimiter);
803
+ delete inOpts.dateDelimiter;
804
+ }
805
+
806
+ //*** pick level & view ***//
807
+ var newPickLevel = pickLevel;
808
+ if (inOpts.pickLevel !== undefined) {
809
+ newPickLevel = validateViewId(inOpts.pickLevel, 2);
810
+ delete inOpts.pickLevel;
811
+ }
812
+ if (newPickLevel !== pickLevel) {
813
+ pickLevel = config.pickLevel = newPickLevel;
814
+ }
815
+ var newMaxView = maxView;
816
+ if (inOpts.maxView !== undefined) {
817
+ newMaxView = validateViewId(inOpts.maxView, maxView);
818
+ delete inOpts.maxView;
819
+ }
820
+ // ensure max view >= pick level
821
+ newMaxView = pickLevel > newMaxView ? pickLevel : newMaxView;
822
+ if (newMaxView !== maxView) {
823
+ maxView = config.maxView = newMaxView;
824
+ }
825
+ var newStartView = startView;
826
+ if (inOpts.startView !== undefined) {
827
+ newStartView = validateViewId(inOpts.startView, newStartView);
828
+ delete inOpts.startView;
829
+ }
830
+ // ensure pick level <= start view <= max view
831
+ if (newStartView < pickLevel) {
832
+ newStartView = pickLevel;
833
+ } else if (newStartView > maxView) {
834
+ newStartView = maxView;
835
+ }
836
+ if (newStartView !== startView) {
837
+ config.startView = newStartView;
838
+ }
839
+
840
+ //*** template ***//
841
+ if (inOpts.prevArrow) {
842
+ var prevArrow = parseHTML(inOpts.prevArrow);
843
+ if (prevArrow.childNodes.length > 0) {
844
+ config.prevArrow = prevArrow.childNodes;
845
+ }
846
+ delete inOpts.prevArrow;
847
+ }
848
+ if (inOpts.nextArrow) {
849
+ var nextArrow = parseHTML(inOpts.nextArrow);
850
+ if (nextArrow.childNodes.length > 0) {
851
+ config.nextArrow = nextArrow.childNodes;
852
+ }
853
+ delete inOpts.nextArrow;
854
+ }
855
+
856
+ //*** misc ***//
857
+ if (inOpts.disableTouchKeyboard !== undefined) {
858
+ config.disableTouchKeyboard = 'ontouchstart' in document && !!inOpts.disableTouchKeyboard;
859
+ delete inOpts.disableTouchKeyboard;
860
+ }
861
+ if (inOpts.orientation) {
862
+ var orientation = inOpts.orientation.toLowerCase().split(/\s+/g);
863
+ config.orientation = {
864
+ x: orientation.find(function (x) {
865
+ return x === 'left' || x === 'right';
866
+ }) || 'auto',
867
+ y: orientation.find(function (y) {
868
+ return y === 'top' || y === 'bottom';
869
+ }) || 'auto'
870
+ };
871
+ delete inOpts.orientation;
872
+ }
873
+ if (inOpts.todayBtnMode !== undefined) {
874
+ switch (inOpts.todayBtnMode) {
875
+ case 0:
876
+ case 1:
877
+ config.todayBtnMode = inOpts.todayBtnMode;
878
+ }
879
+ delete inOpts.todayBtnMode;
880
+ }
881
+
882
+ //*** copy the rest ***//
883
+ Object.keys(inOpts).forEach(function (key) {
884
+ if (inOpts[key] !== undefined && hasProperty(defaultOptions, key)) {
885
+ config[key] = inOpts[key];
886
+ }
887
+ });
888
+ return config;
889
+ }
890
+
891
+ var pickerTemplate = optimizeTemplateHTML("<div class=\"datepicker hidden\">\n <div class=\"datepicker-picker inline-block rounded-base bg-neutral-primary-medium border border-default-medium p-4\">\n <div class=\"datepicker-header\">\n <div class=\"datepicker-title bg-neutral-primary-medium text-heading px-2 py-3 text-center font-medium\"></div>\n <div class=\"datepicker-controls flex justify-between mb-2\">\n <button type=\"button\" class=\"bg-neutral-primary-medium rounded-base text-body hover:bg-neutral-tertiary-medium hover:text-heading text-lg p-2.5 focus:outline-none focus:ring-2 focus:ring-neutral-tertiary prev-btn\"></button>\n <button type=\"button\" class=\"text-sm rounded-base text-heading bg-neutral-primary-medium font-medium py-2.5 px-5 hover:bg-neutral-tertiary-medium focus:outline-none focus:ring-2 focus:ring-neutral-tertiary view-switch\"></button>\n <button type=\"button\" class=\"bg-neutral-primary-medium rounded-base text-body hover:bg-neutral-tertiary-medium hover:text-heading text-lg p-2.5 focus:outline-none focus:ring-2 focus:ring-neutral-tertiary next-btn\"></button>\n </div>\n </div>\n <div class=\"datepicker-main p-1\"></div>\n <div class=\"datepicker-footer\">\n <div class=\"datepicker-controls flex space-x-2 rtl:space-x-reverse mt-2\">\n <button type=\"button\" class=\"%buttonClass% today-btn text-white bg-brand hover:bg-brand-strong focus:ring-4 focus:ring-brand-medium font-medium rounded-base text-sm px-5 py-2 text-center w-1/2\"></button>\n <button type=\"button\" class=\"%buttonClass% clear-btn text-body bg-neutral-secondary-medium border border-default-medium hover:bg-neutral-tertiary-medium focus:ring-4 focus:ring-neutral-tertiary font-medium rounded-base text-sm px-5 py-2 text-center w-1/2\"></button>\n </div>\n </div>\n </div>\n</div>");
892
+
893
+ var daysTemplate = optimizeTemplateHTML("<div class=\"days\">\n <div class=\"days-of-week grid grid-cols-7 mb-1\">".concat(createTagRepeat('span', 7, {
894
+ "class": 'dow block flex-1 leading-9 border-0 rounded-base cursor-default text-center text-body font-medium text-sm'
895
+ }), "</div>\n <div class=\"datepicker-grid w-64 grid grid-cols-7\">").concat(createTagRepeat('span', 42, {
896
+ "class": 'block flex-1 leading-9 border-0 rounded-base cursor-default text-center text-body font-medium text-sm h-6 leading-6 text-sm font-medium text-fg-disabled'
897
+ }), "</div>\n</div>"));
898
+
899
+ var calendarWeeksTemplate = optimizeTemplateHTML("<div class=\"calendar-weeks\">\n <div class=\"days-of-week flex\"><span class=\"dow h-6 leading-6 text-sm font-medium text-fg-disabled\"></span></div>\n <div class=\"weeks\">".concat(createTagRepeat('span', 6, {
900
+ "class": 'week block flex-1 leading-9 border-0 rounded-base cursor-default text-center text-body font-medium text-sm'
901
+ }), "</div>\n</div>"));
902
+
903
+ // Base class of the view classes
904
+ var View = /*#__PURE__*/function () {
905
+ function View(picker, config) {
906
+ _classCallCheck(this, View);
907
+ Object.assign(this, config, {
908
+ picker: picker,
909
+ element: parseHTML("<div class=\"datepicker-view flex\"></div>").firstChild,
910
+ selected: []
911
+ });
912
+ this.init(this.picker.datepicker.config);
913
+ }
914
+ return _createClass(View, [{
915
+ key: "init",
916
+ value: function init(options) {
917
+ if (options.pickLevel !== undefined) {
918
+ this.isMinView = this.id === options.pickLevel;
919
+ }
920
+ this.setOptions(options);
921
+ this.updateFocus();
922
+ this.updateSelection();
923
+ }
924
+
925
+ // Execute beforeShow() callback and apply the result to the element
926
+ // args:
927
+ // - current - current value on the iteration on view rendering
928
+ // - timeValue - time value of the date to pass to beforeShow()
929
+ }, {
930
+ key: "performBeforeHook",
931
+ value: function performBeforeHook(el, current, timeValue) {
932
+ var result = this.beforeShow(new Date(timeValue));
933
+ switch (_typeof(result)) {
934
+ case 'boolean':
935
+ result = {
936
+ enabled: result
937
+ };
938
+ break;
939
+ case 'string':
940
+ result = {
941
+ classes: result
942
+ };
943
+ }
944
+ if (result) {
945
+ if (result.enabled === false) {
946
+ el.classList.add('disabled');
947
+ pushUnique(this.disabled, current);
948
+ }
949
+ if (result.classes) {
950
+ var _el$classList;
951
+ var extraClasses = result.classes.split(/\s+/);
952
+ (_el$classList = el.classList).add.apply(_el$classList, _toConsumableArray(extraClasses));
953
+ if (extraClasses.includes('disabled')) {
954
+ pushUnique(this.disabled, current);
955
+ }
956
+ }
957
+ if (result.content) {
958
+ replaceChildNodes(el, result.content);
959
+ }
960
+ }
961
+ }
962
+ }]);
963
+ }();
964
+
965
+ var DaysView = /*#__PURE__*/function (_View) {
966
+ function DaysView(picker) {
967
+ _classCallCheck(this, DaysView);
968
+ return _callSuper(this, DaysView, [picker, {
969
+ id: 0,
970
+ name: 'days',
971
+ cellClass: 'day'
972
+ }]);
973
+ }
974
+ _inherits(DaysView, _View);
975
+ return _createClass(DaysView, [{
976
+ key: "init",
977
+ value: function init(options) {
978
+ var onConstruction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
979
+ if (onConstruction) {
980
+ var inner = parseHTML(daysTemplate).firstChild;
981
+ this.dow = inner.firstChild;
982
+ this.grid = inner.lastChild;
983
+ this.element.appendChild(inner);
984
+ }
985
+ _get(_getPrototypeOf(DaysView.prototype), "init", this).call(this, options);
986
+ }
987
+ }, {
988
+ key: "setOptions",
989
+ value: function setOptions(options) {
990
+ var _this = this;
991
+ var updateDOW;
992
+ if (hasProperty(options, 'minDate')) {
993
+ this.minDate = options.minDate;
994
+ }
995
+ if (hasProperty(options, 'maxDate')) {
996
+ this.maxDate = options.maxDate;
997
+ }
998
+ if (options.datesDisabled) {
999
+ this.datesDisabled = options.datesDisabled;
1000
+ }
1001
+ if (options.daysOfWeekDisabled) {
1002
+ this.daysOfWeekDisabled = options.daysOfWeekDisabled;
1003
+ updateDOW = true;
1004
+ }
1005
+ if (options.daysOfWeekHighlighted) {
1006
+ this.daysOfWeekHighlighted = options.daysOfWeekHighlighted;
1007
+ }
1008
+ if (options.todayHighlight !== undefined) {
1009
+ this.todayHighlight = options.todayHighlight;
1010
+ }
1011
+ if (options.weekStart !== undefined) {
1012
+ this.weekStart = options.weekStart;
1013
+ this.weekEnd = options.weekEnd;
1014
+ updateDOW = true;
1015
+ }
1016
+ if (options.locale) {
1017
+ var locale = this.locale = options.locale;
1018
+ this.dayNames = locale.daysMin;
1019
+ this.switchLabelFormat = locale.titleFormat;
1020
+ updateDOW = true;
1021
+ }
1022
+ if (options.beforeShowDay !== undefined) {
1023
+ this.beforeShow = typeof options.beforeShowDay === 'function' ? options.beforeShowDay : undefined;
1024
+ }
1025
+ if (options.calendarWeeks !== undefined) {
1026
+ if (options.calendarWeeks && !this.calendarWeeks) {
1027
+ var weeksElem = parseHTML(calendarWeeksTemplate).firstChild;
1028
+ this.calendarWeeks = {
1029
+ element: weeksElem,
1030
+ dow: weeksElem.firstChild,
1031
+ weeks: weeksElem.lastChild
1032
+ };
1033
+ this.element.insertBefore(weeksElem, this.element.firstChild);
1034
+ } else if (this.calendarWeeks && !options.calendarWeeks) {
1035
+ this.element.removeChild(this.calendarWeeks.element);
1036
+ this.calendarWeeks = null;
1037
+ }
1038
+ }
1039
+ if (options.showDaysOfWeek !== undefined) {
1040
+ if (options.showDaysOfWeek) {
1041
+ showElement(this.dow);
1042
+ if (this.calendarWeeks) {
1043
+ showElement(this.calendarWeeks.dow);
1044
+ }
1045
+ } else {
1046
+ hideElement(this.dow);
1047
+ if (this.calendarWeeks) {
1048
+ hideElement(this.calendarWeeks.dow);
1049
+ }
1050
+ }
1051
+ }
1052
+
1053
+ // update days-of-week when locale, daysOfweekDisabled or weekStart is changed
1054
+ if (updateDOW) {
1055
+ Array.from(this.dow.children).forEach(function (el, index) {
1056
+ var dow = (_this.weekStart + index) % 7;
1057
+ el.textContent = _this.dayNames[dow];
1058
+ el.className = _this.daysOfWeekDisabled.includes(dow) ? 'dow disabled text-center h-6 leading-6 text-sm font-medium text-fg-disabled cursor-not-allowed' : 'dow text-center h-6 leading-6 text-sm font-medium text-body';
1059
+ });
1060
+ }
1061
+ }
1062
+
1063
+ // Apply update on the focused date to view's settings
1064
+ }, {
1065
+ key: "updateFocus",
1066
+ value: function updateFocus() {
1067
+ var viewDate = new Date(this.picker.viewDate);
1068
+ var viewYear = viewDate.getFullYear();
1069
+ var viewMonth = viewDate.getMonth();
1070
+ var firstOfMonth = dateValue(viewYear, viewMonth, 1);
1071
+ var start = dayOfTheWeekOf(firstOfMonth, this.weekStart, this.weekStart);
1072
+ this.first = firstOfMonth;
1073
+ this.last = dateValue(viewYear, viewMonth + 1, 0);
1074
+ this.start = start;
1075
+ this.focused = this.picker.viewDate;
1076
+ }
1077
+
1078
+ // Apply update on the selected dates to view's settings
1079
+ }, {
1080
+ key: "updateSelection",
1081
+ value: function updateSelection() {
1082
+ var _this$picker$datepick = this.picker.datepicker,
1083
+ dates = _this$picker$datepick.dates,
1084
+ rangepicker = _this$picker$datepick.rangepicker;
1085
+ this.selected = dates;
1086
+ if (rangepicker) {
1087
+ this.range = rangepicker.dates;
1088
+ }
1089
+ }
1090
+
1091
+ // Update the entire view UI
1092
+ }, {
1093
+ key: "render",
1094
+ value: function render() {
1095
+ var _this2 = this;
1096
+ // update today marker on ever render
1097
+ this.today = this.todayHighlight ? today() : undefined;
1098
+ // refresh disabled dates on every render in order to clear the ones added
1099
+ // by beforeShow hook at previous render
1100
+ this.disabled = _toConsumableArray(this.datesDisabled);
1101
+ var switchLabel = formatDate(this.focused, this.switchLabelFormat, this.locale);
1102
+ this.picker.setViewSwitchLabel(switchLabel);
1103
+ this.picker.setPrevBtnDisabled(this.first <= this.minDate);
1104
+ this.picker.setNextBtnDisabled(this.last >= this.maxDate);
1105
+ if (this.calendarWeeks) {
1106
+ // start of the UTC week (Monday) of the 1st of the month
1107
+ var startOfWeek = dayOfTheWeekOf(this.first, 1, 1);
1108
+ Array.from(this.calendarWeeks.weeks.children).forEach(function (el, index) {
1109
+ el.textContent = getWeek(addWeeks(startOfWeek, index));
1110
+ });
1111
+ }
1112
+ Array.from(this.grid.children).forEach(function (el, index) {
1113
+ var classList = el.classList;
1114
+ var current = addDays(_this2.start, index);
1115
+ var date = new Date(current);
1116
+ var day = date.getDay();
1117
+ el.className = "datepicker-cell hover:bg-neutral-tertiary-medium block flex-1 leading-9 border-0 rounded-base cursor-pointer text-center text-body font-medium text-sm ".concat(_this2.cellClass);
1118
+ el.dataset.date = current;
1119
+ el.textContent = date.getDate();
1120
+ if (current < _this2.first) {
1121
+ classList.add('prev', 'text-fg-disabled');
1122
+ } else if (current > _this2.last) {
1123
+ classList.add('next', 'text-fg-disabled');
1124
+ }
1125
+ if (_this2.today === current) {
1126
+ classList.add('today', 'bg-gray-100', 'dark:bg-gray-600');
1127
+ }
1128
+ if (current < _this2.minDate || current > _this2.maxDate || _this2.disabled.includes(current)) {
1129
+ classList.add('disabled', 'cursor-not-allowed', 'text-fg-disabled');
1130
+ classList.remove('hover:bg-neutral-tertiary-medium', 'text-body', 'cursor-pointer');
1131
+ }
1132
+ if (_this2.daysOfWeekDisabled.includes(day)) {
1133
+ classList.add('disabled', 'cursor-not-allowed', 'text-fg-disabled');
1134
+ classList.remove('hover:bg-neutral-tertiary-medium', 'text-body', 'cursor-pointer');
1135
+ pushUnique(_this2.disabled, current);
1136
+ }
1137
+ if (_this2.daysOfWeekHighlighted.includes(day)) {
1138
+ classList.add('highlighted');
1139
+ }
1140
+ if (_this2.range) {
1141
+ var _this2$range = _slicedToArray(_this2.range, 2),
1142
+ rangeStart = _this2$range[0],
1143
+ rangeEnd = _this2$range[1];
1144
+ if (current > rangeStart && current < rangeEnd) {
1145
+ classList.add('range', 'bg-neutral-tertiary-medium');
1146
+ classList.remove('rounded-base', 'rounded-s-base', 'rounded-e-base');
1147
+ }
1148
+ if (current === rangeStart) {
1149
+ classList.add('range-start', 'bg-brand', 'rounded-s-base');
1150
+ classList.remove('rounded-base', 'rounded-e-base');
1151
+ }
1152
+ if (current === rangeEnd) {
1153
+ classList.add('range-end', 'bg-neutral-tertiary-medium', 'rounded-e-base');
1154
+ classList.remove('rounded-base', 'rounded-s-base');
1155
+ }
1156
+ }
1157
+ if (_this2.selected.includes(current)) {
1158
+ classList.add('selected', 'bg-brand', 'text-white');
1159
+ classList.remove('text-body', 'hover:bg-neutral-tertiary-medium', 'bg-neutral-tertiary-medium');
1160
+ }
1161
+ if (current === _this2.focused) {
1162
+ classList.add('focused');
1163
+ }
1164
+ if (_this2.beforeShow) {
1165
+ _this2.performBeforeHook(el, current, current);
1166
+ }
1167
+ });
1168
+ }
1169
+
1170
+ // Update the view UI by applying the changes of selected and focused items
1171
+ }, {
1172
+ key: "refresh",
1173
+ value: function refresh() {
1174
+ var _this3 = this;
1175
+ var _ref = this.range || [],
1176
+ _ref2 = _slicedToArray(_ref, 2),
1177
+ rangeStart = _ref2[0],
1178
+ rangeEnd = _ref2[1];
1179
+ this.grid.querySelectorAll('.range, .range-start, .range-end, .selected, .focused').forEach(function (el) {
1180
+ el.classList.remove('range', 'range-start', 'range-end', 'selected', 'bg-brand', 'text-white', 'focused');
1181
+ el.classList.add('text-body', 'rounded-base');
1182
+ });
1183
+ Array.from(this.grid.children).forEach(function (el) {
1184
+ var current = Number(el.dataset.date);
1185
+ var classList = el.classList;
1186
+ classList.remove('bg-neutral-tertiary-medium', 'rounded-s-base', 'rounded-e-base');
1187
+ if (current > rangeStart && current < rangeEnd) {
1188
+ classList.add('range', 'bg-neutral-tertiary-medium');
1189
+ classList.remove('rounded-base');
1190
+ }
1191
+ if (current === rangeStart) {
1192
+ classList.add('range-start', 'bg-brand', 'text-white', 'rounded-s-base');
1193
+ classList.remove('rounded-base');
1194
+ }
1195
+ if (current === rangeEnd) {
1196
+ classList.add('range-end', 'bg-neutral-tertiary-medium', 'rounded-e-base');
1197
+ classList.remove('rounded-base');
1198
+ }
1199
+ if (_this3.selected.includes(current)) {
1200
+ classList.add('selected', 'bg-brand', 'text-white');
1201
+ classList.remove('text-body', 'hover:bg-neutral-tertiary-medium', 'bg-neutral-tertiary-medium');
1202
+ }
1203
+ if (current === _this3.focused) {
1204
+ classList.add('focused');
1205
+ }
1206
+ });
1207
+ }
1208
+
1209
+ // Update the view UI by applying the change of focused item
1210
+ }, {
1211
+ key: "refreshFocus",
1212
+ value: function refreshFocus() {
1213
+ var index = Math.round((this.focused - this.start) / 86400000);
1214
+ this.grid.querySelectorAll('.focused').forEach(function (el) {
1215
+ el.classList.remove('focused');
1216
+ });
1217
+ this.grid.children[index].classList.add('focused');
1218
+ }
1219
+ }]);
1220
+ }(View);
1221
+
1222
+ function computeMonthRange(range, thisYear) {
1223
+ if (!range || !range[0] || !range[1]) {
1224
+ return;
1225
+ }
1226
+ var _range = _slicedToArray(range, 2),
1227
+ _range$ = _slicedToArray(_range[0], 2),
1228
+ startY = _range$[0],
1229
+ startM = _range$[1],
1230
+ _range$2 = _slicedToArray(_range[1], 2),
1231
+ endY = _range$2[0],
1232
+ endM = _range$2[1];
1233
+ if (startY > thisYear || endY < thisYear) {
1234
+ return;
1235
+ }
1236
+ return [startY === thisYear ? startM : -1, endY === thisYear ? endM : 12];
1237
+ }
1238
+ var MonthsView = /*#__PURE__*/function (_View) {
1239
+ function MonthsView(picker) {
1240
+ _classCallCheck(this, MonthsView);
1241
+ return _callSuper(this, MonthsView, [picker, {
1242
+ id: 1,
1243
+ name: 'months',
1244
+ cellClass: 'month'
1245
+ }]);
1246
+ }
1247
+ _inherits(MonthsView, _View);
1248
+ return _createClass(MonthsView, [{
1249
+ key: "init",
1250
+ value: function init(options) {
1251
+ var onConstruction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1252
+ if (onConstruction) {
1253
+ this.grid = this.element;
1254
+ this.element.classList.add('months', 'datepicker-grid', 'w-64', 'grid', 'grid-cols-4');
1255
+ this.grid.appendChild(parseHTML(createTagRepeat('span', 12, {
1256
+ 'data-month': function dataMonth(ix) {
1257
+ return ix;
1258
+ }
1259
+ })));
1260
+ }
1261
+ _get(_getPrototypeOf(MonthsView.prototype), "init", this).call(this, options);
1262
+ }
1263
+ }, {
1264
+ key: "setOptions",
1265
+ value: function setOptions(options) {
1266
+ if (options.locale) {
1267
+ this.monthNames = options.locale.monthsShort;
1268
+ }
1269
+ if (hasProperty(options, 'minDate')) {
1270
+ if (options.minDate === undefined) {
1271
+ this.minYear = this.minMonth = this.minDate = undefined;
1272
+ } else {
1273
+ var minDateObj = new Date(options.minDate);
1274
+ this.minYear = minDateObj.getFullYear();
1275
+ this.minMonth = minDateObj.getMonth();
1276
+ this.minDate = minDateObj.setDate(1);
1277
+ }
1278
+ }
1279
+ if (hasProperty(options, 'maxDate')) {
1280
+ if (options.maxDate === undefined) {
1281
+ this.maxYear = this.maxMonth = this.maxDate = undefined;
1282
+ } else {
1283
+ var maxDateObj = new Date(options.maxDate);
1284
+ this.maxYear = maxDateObj.getFullYear();
1285
+ this.maxMonth = maxDateObj.getMonth();
1286
+ this.maxDate = dateValue(this.maxYear, this.maxMonth + 1, 0);
1287
+ }
1288
+ }
1289
+ if (options.beforeShowMonth !== undefined) {
1290
+ this.beforeShow = typeof options.beforeShowMonth === 'function' ? options.beforeShowMonth : undefined;
1291
+ }
1292
+ }
1293
+
1294
+ // Update view's settings to reflect the viewDate set on the picker
1295
+ }, {
1296
+ key: "updateFocus",
1297
+ value: function updateFocus() {
1298
+ var viewDate = new Date(this.picker.viewDate);
1299
+ this.year = viewDate.getFullYear();
1300
+ this.focused = viewDate.getMonth();
1301
+ }
1302
+
1303
+ // Update view's settings to reflect the selected dates
1304
+ }, {
1305
+ key: "updateSelection",
1306
+ value: function updateSelection() {
1307
+ var _this$picker$datepick = this.picker.datepicker,
1308
+ dates = _this$picker$datepick.dates,
1309
+ rangepicker = _this$picker$datepick.rangepicker;
1310
+ this.selected = dates.reduce(function (selected, timeValue) {
1311
+ var date = new Date(timeValue);
1312
+ var year = date.getFullYear();
1313
+ var month = date.getMonth();
1314
+ if (selected[year] === undefined) {
1315
+ selected[year] = [month];
1316
+ } else {
1317
+ pushUnique(selected[year], month);
1318
+ }
1319
+ return selected;
1320
+ }, {});
1321
+ if (rangepicker && rangepicker.dates) {
1322
+ this.range = rangepicker.dates.map(function (timeValue) {
1323
+ var date = new Date(timeValue);
1324
+ return isNaN(date) ? undefined : [date.getFullYear(), date.getMonth()];
1325
+ });
1326
+ }
1327
+ }
1328
+
1329
+ // Update the entire view UI
1330
+ }, {
1331
+ key: "render",
1332
+ value: function render() {
1333
+ var _this = this;
1334
+ // refresh disabled months on every render in order to clear the ones added
1335
+ // by beforeShow hook at previous render
1336
+ this.disabled = [];
1337
+ this.picker.setViewSwitchLabel(this.year);
1338
+ this.picker.setPrevBtnDisabled(this.year <= this.minYear);
1339
+ this.picker.setNextBtnDisabled(this.year >= this.maxYear);
1340
+ var selected = this.selected[this.year] || [];
1341
+ var yrOutOfRange = this.year < this.minYear || this.year > this.maxYear;
1342
+ var isMinYear = this.year === this.minYear;
1343
+ var isMaxYear = this.year === this.maxYear;
1344
+ var range = computeMonthRange(this.range, this.year);
1345
+ Array.from(this.grid.children).forEach(function (el, index) {
1346
+ var classList = el.classList;
1347
+ var date = dateValue(_this.year, index, 1);
1348
+ el.className = "datepicker-cell hover:bg-neutral-tertiary-medium block flex-1 leading-9 border-0 rounded-base cursor-pointer text-center text-body font-medium text-sm ".concat(_this.cellClass);
1349
+ if (_this.isMinView) {
1350
+ el.dataset.date = date;
1351
+ }
1352
+ // reset text on every render to clear the custom content set
1353
+ // by beforeShow hook at previous render
1354
+ el.textContent = _this.monthNames[index];
1355
+ if (yrOutOfRange || isMinYear && index < _this.minMonth || isMaxYear && index > _this.maxMonth) {
1356
+ classList.add('disabled');
1357
+ }
1358
+ if (range) {
1359
+ var _range2 = _slicedToArray(range, 2),
1360
+ rangeStart = _range2[0],
1361
+ rangeEnd = _range2[1];
1362
+ if (index > rangeStart && index < rangeEnd) {
1363
+ classList.add('range');
1364
+ }
1365
+ if (index === rangeStart) {
1366
+ classList.add('range-start');
1367
+ }
1368
+ if (index === rangeEnd) {
1369
+ classList.add('range-end');
1370
+ }
1371
+ }
1372
+ if (selected.includes(index)) {
1373
+ classList.add('selected', 'bg-brand', 'text-white', 'dark:text-white');
1374
+ classList.remove('text-body', 'hover:bg-neutral-tertiary-medium', 'dark:text-white');
1375
+ }
1376
+ if (index === _this.focused) {
1377
+ classList.add('focused');
1378
+ }
1379
+ if (_this.beforeShow) {
1380
+ _this.performBeforeHook(el, index, date);
1381
+ }
1382
+ });
1383
+ }
1384
+
1385
+ // Update the view UI by applying the changes of selected and focused items
1386
+ }, {
1387
+ key: "refresh",
1388
+ value: function refresh() {
1389
+ var _this2 = this;
1390
+ var selected = this.selected[this.year] || [];
1391
+ var _ref = computeMonthRange(this.range, this.year) || [],
1392
+ _ref2 = _slicedToArray(_ref, 2),
1393
+ rangeStart = _ref2[0],
1394
+ rangeEnd = _ref2[1];
1395
+ this.grid.querySelectorAll('.range, .range-start, .range-end, .selected, .focused').forEach(function (el) {
1396
+ el.classList.remove('range', 'range-start', 'range-end', 'selected', 'bg-brand', 'dark:text-white', 'text-white', 'focused');
1397
+ el.classList.add('text-body', 'hover:bg-neutral-tertiary-medium', 'dark:text-white');
1398
+ });
1399
+ Array.from(this.grid.children).forEach(function (el, index) {
1400
+ var classList = el.classList;
1401
+ if (index > rangeStart && index < rangeEnd) {
1402
+ classList.add('range');
1403
+ }
1404
+ if (index === rangeStart) {
1405
+ classList.add('range-start');
1406
+ }
1407
+ if (index === rangeEnd) {
1408
+ classList.add('range-end');
1409
+ }
1410
+ if (selected.includes(index)) {
1411
+ classList.add('selected', 'bg-brand', 'text-white', 'dark:text-white');
1412
+ classList.remove('text-body', 'hover:bg-neutral-tertiary-medium', 'dark:text-white');
1413
+ }
1414
+ if (index === _this2.focused) {
1415
+ classList.add('focused');
1416
+ }
1417
+ });
1418
+ }
1419
+
1420
+ // Update the view UI by applying the change of focused item
1421
+ }, {
1422
+ key: "refreshFocus",
1423
+ value: function refreshFocus() {
1424
+ this.grid.querySelectorAll('.focused').forEach(function (el) {
1425
+ el.classList.remove('focused');
1426
+ });
1427
+ this.grid.children[this.focused].classList.add('focused');
1428
+ }
1429
+ }]);
1430
+ }(View);
1431
+
1432
+ function toTitleCase(word) {
1433
+ return _toConsumableArray(word).reduce(function (str, ch, ix) {
1434
+ return str += ix ? ch : ch.toUpperCase();
1435
+ }, '');
1436
+ }
1437
+
1438
+ // Class representing the years and decades view elements
1439
+ var YearsView = /*#__PURE__*/function (_View) {
1440
+ function YearsView(picker, config) {
1441
+ _classCallCheck(this, YearsView);
1442
+ return _callSuper(this, YearsView, [picker, config]);
1443
+ }
1444
+ _inherits(YearsView, _View);
1445
+ return _createClass(YearsView, [{
1446
+ key: "init",
1447
+ value: function init(options) {
1448
+ var onConstruction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1449
+ if (onConstruction) {
1450
+ this.navStep = this.step * 10;
1451
+ this.beforeShowOption = "beforeShow".concat(toTitleCase(this.cellClass));
1452
+ this.grid = this.element;
1453
+ this.element.classList.add(this.name, 'datepicker-grid', 'w-64', 'grid', 'grid-cols-4');
1454
+ this.grid.appendChild(parseHTML(createTagRepeat('span', 12)));
1455
+ }
1456
+ _get(_getPrototypeOf(YearsView.prototype), "init", this).call(this, options);
1457
+ }
1458
+ }, {
1459
+ key: "setOptions",
1460
+ value: function setOptions(options) {
1461
+ if (hasProperty(options, 'minDate')) {
1462
+ if (options.minDate === undefined) {
1463
+ this.minYear = this.minDate = undefined;
1464
+ } else {
1465
+ this.minYear = startOfYearPeriod(options.minDate, this.step);
1466
+ this.minDate = dateValue(this.minYear, 0, 1);
1467
+ }
1468
+ }
1469
+ if (hasProperty(options, 'maxDate')) {
1470
+ if (options.maxDate === undefined) {
1471
+ this.maxYear = this.maxDate = undefined;
1472
+ } else {
1473
+ this.maxYear = startOfYearPeriod(options.maxDate, this.step);
1474
+ this.maxDate = dateValue(this.maxYear, 11, 31);
1475
+ }
1476
+ }
1477
+ if (options[this.beforeShowOption] !== undefined) {
1478
+ var beforeShow = options[this.beforeShowOption];
1479
+ this.beforeShow = typeof beforeShow === 'function' ? beforeShow : undefined;
1480
+ }
1481
+ }
1482
+
1483
+ // Update view's settings to reflect the viewDate set on the picker
1484
+ }, {
1485
+ key: "updateFocus",
1486
+ value: function updateFocus() {
1487
+ var viewDate = new Date(this.picker.viewDate);
1488
+ var first = startOfYearPeriod(viewDate, this.navStep);
1489
+ var last = first + 9 * this.step;
1490
+ this.first = first;
1491
+ this.last = last;
1492
+ this.start = first - this.step;
1493
+ this.focused = startOfYearPeriod(viewDate, this.step);
1494
+ }
1495
+
1496
+ // Update view's settings to reflect the selected dates
1497
+ }, {
1498
+ key: "updateSelection",
1499
+ value: function updateSelection() {
1500
+ var _this = this;
1501
+ var _this$picker$datepick = this.picker.datepicker,
1502
+ dates = _this$picker$datepick.dates,
1503
+ rangepicker = _this$picker$datepick.rangepicker;
1504
+ this.selected = dates.reduce(function (years, timeValue) {
1505
+ return pushUnique(years, startOfYearPeriod(timeValue, _this.step));
1506
+ }, []);
1507
+ if (rangepicker && rangepicker.dates) {
1508
+ this.range = rangepicker.dates.map(function (timeValue) {
1509
+ if (timeValue !== undefined) {
1510
+ return startOfYearPeriod(timeValue, _this.step);
1511
+ }
1512
+ });
1513
+ }
1514
+ }
1515
+
1516
+ // Update the entire view UI
1517
+ }, {
1518
+ key: "render",
1519
+ value: function render() {
1520
+ var _this2 = this;
1521
+ // refresh disabled years on every render in order to clear the ones added
1522
+ // by beforeShow hook at previous render
1523
+ this.disabled = [];
1524
+ this.picker.setViewSwitchLabel("".concat(this.first, "-").concat(this.last));
1525
+ this.picker.setPrevBtnDisabled(this.first <= this.minYear);
1526
+ this.picker.setNextBtnDisabled(this.last >= this.maxYear);
1527
+ Array.from(this.grid.children).forEach(function (el, index) {
1528
+ var classList = el.classList;
1529
+ var current = _this2.start + index * _this2.step;
1530
+ var date = dateValue(current, 0, 1);
1531
+ el.className = "datepicker-cell hover:bg-neutral-tertiary-medium block flex-1 leading-9 border-0 rounded-base cursor-pointer text-center text-body font-medium text-sm ".concat(_this2.cellClass);
1532
+ if (_this2.isMinView) {
1533
+ el.dataset.date = date;
1534
+ }
1535
+ el.textContent = el.dataset.year = current;
1536
+ if (index === 0) {
1537
+ classList.add('prev');
1538
+ } else if (index === 11) {
1539
+ classList.add('next');
1540
+ }
1541
+ if (current < _this2.minYear || current > _this2.maxYear) {
1542
+ classList.add('disabled');
1543
+ }
1544
+ if (_this2.range) {
1545
+ var _this2$range = _slicedToArray(_this2.range, 2),
1546
+ rangeStart = _this2$range[0],
1547
+ rangeEnd = _this2$range[1];
1548
+ if (current > rangeStart && current < rangeEnd) {
1549
+ classList.add('range');
1550
+ }
1551
+ if (current === rangeStart) {
1552
+ classList.add('range-start');
1553
+ }
1554
+ if (current === rangeEnd) {
1555
+ classList.add('range-end');
1556
+ }
1557
+ }
1558
+ if (_this2.selected.includes(current)) {
1559
+ classList.add('selected', 'bg-brand', 'text-white', 'dark:text-white');
1560
+ classList.remove('text-body', 'hover:bg-neutral-tertiary-medium', 'dark:text-white');
1561
+ }
1562
+ if (current === _this2.focused) {
1563
+ classList.add('focused');
1564
+ }
1565
+ if (_this2.beforeShow) {
1566
+ _this2.performBeforeHook(el, current, date);
1567
+ }
1568
+ });
1569
+ }
1570
+
1571
+ // Update the view UI by applying the changes of selected and focused items
1572
+ }, {
1573
+ key: "refresh",
1574
+ value: function refresh() {
1575
+ var _this3 = this;
1576
+ var _ref = this.range || [],
1577
+ _ref2 = _slicedToArray(_ref, 2),
1578
+ rangeStart = _ref2[0],
1579
+ rangeEnd = _ref2[1];
1580
+ this.grid.querySelectorAll('.range, .range-start, .range-end, .selected, .focused').forEach(function (el) {
1581
+ el.classList.remove('range', 'range-start', 'range-end', 'selected', 'bg-brand', 'text-white', 'dark:text-white', 'focused');
1582
+ });
1583
+ Array.from(this.grid.children).forEach(function (el) {
1584
+ var current = Number(el.textContent);
1585
+ var classList = el.classList;
1586
+ if (current > rangeStart && current < rangeEnd) {
1587
+ classList.add('range');
1588
+ }
1589
+ if (current === rangeStart) {
1590
+ classList.add('range-start');
1591
+ }
1592
+ if (current === rangeEnd) {
1593
+ classList.add('range-end');
1594
+ }
1595
+ if (_this3.selected.includes(current)) {
1596
+ classList.add('selected', 'bg-brand', 'text-white', 'hover:text-heading');
1597
+ classList.remove('text-body', 'hover:bg-neutral-tertiary-medium', 'hover:text-heading');
1598
+ }
1599
+ if (current === _this3.focused) {
1600
+ classList.add('focused');
1601
+ }
1602
+ });
1603
+ }
1604
+
1605
+ // Update the view UI by applying the change of focused item
1606
+ }, {
1607
+ key: "refreshFocus",
1608
+ value: function refreshFocus() {
1609
+ var index = Math.round((this.focused - this.start) / this.step);
1610
+ this.grid.querySelectorAll('.focused').forEach(function (el) {
1611
+ el.classList.remove('focused');
1612
+ });
1613
+ this.grid.children[index].classList.add('focused');
1614
+ }
1615
+ }]);
1616
+ }(View);
1617
+
1618
+ function triggerDatepickerEvent(datepicker, type) {
1619
+ var detail = {
1620
+ date: datepicker.getDate(),
1621
+ viewDate: new Date(datepicker.picker.viewDate),
1622
+ viewId: datepicker.picker.currentView.id,
1623
+ datepicker: datepicker
1624
+ };
1625
+ datepicker.element.dispatchEvent(new CustomEvent(type, {
1626
+ detail: detail
1627
+ }));
1628
+ }
1629
+
1630
+ // direction: -1 (to previous), 1 (to next)
1631
+ function goToPrevOrNext(datepicker, direction) {
1632
+ var _datepicker$config = datepicker.config,
1633
+ minDate = _datepicker$config.minDate,
1634
+ maxDate = _datepicker$config.maxDate;
1635
+ var _datepicker$picker = datepicker.picker,
1636
+ currentView = _datepicker$picker.currentView,
1637
+ viewDate = _datepicker$picker.viewDate;
1638
+ var newViewDate;
1639
+ switch (currentView.id) {
1640
+ case 0:
1641
+ newViewDate = addMonths(viewDate, direction);
1642
+ break;
1643
+ case 1:
1644
+ newViewDate = addYears(viewDate, direction);
1645
+ break;
1646
+ default:
1647
+ newViewDate = addYears(viewDate, direction * currentView.navStep);
1648
+ }
1649
+ newViewDate = limitToRange(newViewDate, minDate, maxDate);
1650
+ datepicker.picker.changeFocus(newViewDate).render();
1651
+ }
1652
+ function switchView(datepicker) {
1653
+ var viewId = datepicker.picker.currentView.id;
1654
+ if (viewId === datepicker.config.maxView) {
1655
+ return;
1656
+ }
1657
+ datepicker.picker.changeView(viewId + 1).render();
1658
+ }
1659
+ function unfocus(datepicker) {
1660
+ if (datepicker.config.updateOnBlur) {
1661
+ datepicker.update({
1662
+ autohide: true
1663
+ });
1664
+ } else {
1665
+ datepicker.refresh('input');
1666
+ datepicker.hide();
1667
+ }
1668
+ }
1669
+
1670
+ function goToSelectedMonthOrYear(datepicker, selection) {
1671
+ var picker = datepicker.picker;
1672
+ var viewDate = new Date(picker.viewDate);
1673
+ var viewId = picker.currentView.id;
1674
+ var newDate = viewId === 1 ? addMonths(viewDate, selection - viewDate.getMonth()) : addYears(viewDate, selection - viewDate.getFullYear());
1675
+ picker.changeFocus(newDate).changeView(viewId - 1).render();
1676
+ }
1677
+ function onClickTodayBtn(datepicker) {
1678
+ var picker = datepicker.picker;
1679
+ var currentDate = today();
1680
+ if (datepicker.config.todayBtnMode === 1) {
1681
+ if (datepicker.config.autohide) {
1682
+ datepicker.setDate(currentDate);
1683
+ return;
1684
+ }
1685
+ datepicker.setDate(currentDate, {
1686
+ render: false
1687
+ });
1688
+ picker.update();
1689
+ }
1690
+ if (picker.viewDate !== currentDate) {
1691
+ picker.changeFocus(currentDate);
1692
+ }
1693
+ picker.changeView(0).render();
1694
+ }
1695
+ function onClickClearBtn(datepicker) {
1696
+ datepicker.setDate({
1697
+ clear: true
1698
+ });
1699
+ }
1700
+ function onClickViewSwitch(datepicker) {
1701
+ switchView(datepicker);
1702
+ }
1703
+ function onClickPrevBtn(datepicker) {
1704
+ goToPrevOrNext(datepicker, -1);
1705
+ }
1706
+ function onClickNextBtn(datepicker) {
1707
+ goToPrevOrNext(datepicker, 1);
1708
+ }
1709
+
1710
+ // For the picker's main block to delegete the events from `datepicker-cell`s
1711
+ function onClickView(datepicker, ev) {
1712
+ var target = findElementInEventPath(ev, '.datepicker-cell');
1713
+ if (!target || target.classList.contains('disabled')) {
1714
+ return;
1715
+ }
1716
+ var _datepicker$picker$cu = datepicker.picker.currentView,
1717
+ id = _datepicker$picker$cu.id,
1718
+ isMinView = _datepicker$picker$cu.isMinView;
1719
+ if (isMinView) {
1720
+ datepicker.setDate(Number(target.dataset.date));
1721
+ } else if (id === 1) {
1722
+ goToSelectedMonthOrYear(datepicker, Number(target.dataset.month));
1723
+ } else {
1724
+ goToSelectedMonthOrYear(datepicker, Number(target.dataset.year));
1725
+ }
1726
+ }
1727
+ function onClickPicker(datepicker) {
1728
+ if (!datepicker.inline && !datepicker.config.disableTouchKeyboard) {
1729
+ datepicker.inputField.focus();
1730
+ }
1731
+ }
1732
+
1733
+ function processPickerOptions(picker, options) {
1734
+ if (options.title !== undefined) {
1735
+ if (options.title) {
1736
+ picker.controls.title.textContent = options.title;
1737
+ showElement(picker.controls.title);
1738
+ } else {
1739
+ picker.controls.title.textContent = '';
1740
+ hideElement(picker.controls.title);
1741
+ }
1742
+ }
1743
+ if (options.prevArrow) {
1744
+ var prevBtn = picker.controls.prevBtn;
1745
+ emptyChildNodes(prevBtn);
1746
+ options.prevArrow.forEach(function (node) {
1747
+ prevBtn.appendChild(node.cloneNode(true));
1748
+ });
1749
+ }
1750
+ if (options.nextArrow) {
1751
+ var nextBtn = picker.controls.nextBtn;
1752
+ emptyChildNodes(nextBtn);
1753
+ options.nextArrow.forEach(function (node) {
1754
+ nextBtn.appendChild(node.cloneNode(true));
1755
+ });
1756
+ }
1757
+ if (options.locale) {
1758
+ picker.controls.todayBtn.textContent = options.locale.today;
1759
+ picker.controls.clearBtn.textContent = options.locale.clear;
1760
+ }
1761
+ if (options.todayBtn !== undefined) {
1762
+ if (options.todayBtn) {
1763
+ showElement(picker.controls.todayBtn);
1764
+ } else {
1765
+ hideElement(picker.controls.todayBtn);
1766
+ }
1767
+ }
1768
+ if (hasProperty(options, 'minDate') || hasProperty(options, 'maxDate')) {
1769
+ var _picker$datepicker$co = picker.datepicker.config,
1770
+ minDate = _picker$datepicker$co.minDate,
1771
+ maxDate = _picker$datepicker$co.maxDate;
1772
+ picker.controls.todayBtn.disabled = !isInRange(today(), minDate, maxDate);
1773
+ }
1774
+ if (options.clearBtn !== undefined) {
1775
+ if (options.clearBtn) {
1776
+ showElement(picker.controls.clearBtn);
1777
+ } else {
1778
+ hideElement(picker.controls.clearBtn);
1779
+ }
1780
+ }
1781
+ }
1782
+
1783
+ // Compute view date to reset, which will be...
1784
+ // - the last item of the selected dates or defaultViewDate if no selection
1785
+ // - limitted to minDate or maxDate if it exceeds the range
1786
+ function computeResetViewDate(datepicker) {
1787
+ var dates = datepicker.dates,
1788
+ config = datepicker.config;
1789
+ var viewDate = dates.length > 0 ? lastItemOf(dates) : config.defaultViewDate;
1790
+ return limitToRange(viewDate, config.minDate, config.maxDate);
1791
+ }
1792
+
1793
+ // Change current view's view date
1794
+ function setViewDate(picker, newDate) {
1795
+ var oldViewDate = new Date(picker.viewDate);
1796
+ var newViewDate = new Date(newDate);
1797
+ var _picker$currentView = picker.currentView,
1798
+ id = _picker$currentView.id,
1799
+ year = _picker$currentView.year,
1800
+ first = _picker$currentView.first,
1801
+ last = _picker$currentView.last;
1802
+ var viewYear = newViewDate.getFullYear();
1803
+ picker.viewDate = newDate;
1804
+ if (viewYear !== oldViewDate.getFullYear()) {
1805
+ triggerDatepickerEvent(picker.datepicker, 'changeYear');
1806
+ }
1807
+ if (newViewDate.getMonth() !== oldViewDate.getMonth()) {
1808
+ triggerDatepickerEvent(picker.datepicker, 'changeMonth');
1809
+ }
1810
+
1811
+ // return whether the new date is in different period on time from the one
1812
+ // displayed in the current view
1813
+ // when true, the view needs to be re-rendered on the next UI refresh.
1814
+ switch (id) {
1815
+ case 0:
1816
+ return newDate < first || newDate > last;
1817
+ case 1:
1818
+ return viewYear !== year;
1819
+ default:
1820
+ return viewYear < first || viewYear > last;
1821
+ }
1822
+ }
1823
+ function getTextDirection(el) {
1824
+ return window.getComputedStyle(el).direction;
1825
+ }
1826
+
1827
+ // Class representing the picker UI
1828
+ var Picker = /*#__PURE__*/function () {
1829
+ function Picker(datepicker) {
1830
+ _classCallCheck(this, Picker);
1831
+ this.datepicker = datepicker;
1832
+ var template = pickerTemplate.replace(/%buttonClass%/g, datepicker.config.buttonClass);
1833
+ var element = this.element = parseHTML(template).firstChild;
1834
+ var _element$firstChild$c = _slicedToArray(element.firstChild.children, 3),
1835
+ header = _element$firstChild$c[0],
1836
+ main = _element$firstChild$c[1],
1837
+ footer = _element$firstChild$c[2];
1838
+ var title = header.firstElementChild;
1839
+ var _header$lastElementCh = _slicedToArray(header.lastElementChild.children, 3),
1840
+ prevBtn = _header$lastElementCh[0],
1841
+ viewSwitch = _header$lastElementCh[1],
1842
+ nextBtn = _header$lastElementCh[2];
1843
+ var _footer$firstChild$ch = _slicedToArray(footer.firstChild.children, 2),
1844
+ todayBtn = _footer$firstChild$ch[0],
1845
+ clearBtn = _footer$firstChild$ch[1];
1846
+ var controls = {
1847
+ title: title,
1848
+ prevBtn: prevBtn,
1849
+ viewSwitch: viewSwitch,
1850
+ nextBtn: nextBtn,
1851
+ todayBtn: todayBtn,
1852
+ clearBtn: clearBtn
1853
+ };
1854
+ this.main = main;
1855
+ this.controls = controls;
1856
+ var elementClass = datepicker.inline ? 'inline' : 'dropdown';
1857
+ element.classList.add("datepicker-".concat(elementClass));
1858
+ elementClass === 'dropdown' ? element.classList.add('dropdown', 'absolute', 'top-0', 'left-0', 'z-50', 'pt-2') : null;
1859
+ processPickerOptions(this, datepicker.config);
1860
+ this.viewDate = computeResetViewDate(datepicker);
1861
+
1862
+ // set up event listeners
1863
+ registerListeners(datepicker, [[element, 'click', onClickPicker.bind(null, datepicker), {
1864
+ capture: true
1865
+ }], [main, 'click', onClickView.bind(null, datepicker)], [controls.viewSwitch, 'click', onClickViewSwitch.bind(null, datepicker)], [controls.prevBtn, 'click', onClickPrevBtn.bind(null, datepicker)], [controls.nextBtn, 'click', onClickNextBtn.bind(null, datepicker)], [controls.todayBtn, 'click', onClickTodayBtn.bind(null, datepicker)], [controls.clearBtn, 'click', onClickClearBtn.bind(null, datepicker)]]);
1866
+
1867
+ // set up views
1868
+ this.views = [new DaysView(this), new MonthsView(this), new YearsView(this, {
1869
+ id: 2,
1870
+ name: 'years',
1871
+ cellClass: 'year',
1872
+ step: 1
1873
+ }), new YearsView(this, {
1874
+ id: 3,
1875
+ name: 'decades',
1876
+ cellClass: 'decade',
1877
+ step: 10
1878
+ })];
1879
+ this.currentView = this.views[datepicker.config.startView];
1880
+ this.currentView.render();
1881
+ this.main.appendChild(this.currentView.element);
1882
+ datepicker.config.container.appendChild(this.element);
1883
+ }
1884
+ return _createClass(Picker, [{
1885
+ key: "setOptions",
1886
+ value: function setOptions(options) {
1887
+ processPickerOptions(this, options);
1888
+ this.views.forEach(function (view) {
1889
+ view.init(options, false);
1890
+ });
1891
+ this.currentView.render();
1892
+ }
1893
+ }, {
1894
+ key: "detach",
1895
+ value: function detach() {
1896
+ this.datepicker.config.container.removeChild(this.element);
1897
+ }
1898
+ }, {
1899
+ key: "show",
1900
+ value: function show() {
1901
+ if (this.active) {
1902
+ return;
1903
+ }
1904
+ this.element.classList.add('active', 'block');
1905
+ this.element.classList.remove('hidden');
1906
+ this.active = true;
1907
+ var datepicker = this.datepicker;
1908
+ if (!datepicker.inline) {
1909
+ // ensure picker's direction matches input's
1910
+ var inputDirection = getTextDirection(datepicker.inputField);
1911
+ if (inputDirection !== getTextDirection(datepicker.config.container)) {
1912
+ this.element.dir = inputDirection;
1913
+ } else if (this.element.dir) {
1914
+ this.element.removeAttribute('dir');
1915
+ }
1916
+ this.place();
1917
+ if (datepicker.config.disableTouchKeyboard) {
1918
+ datepicker.inputField.blur();
1919
+ }
1920
+ }
1921
+ triggerDatepickerEvent(datepicker, 'show');
1922
+ }
1923
+ }, {
1924
+ key: "hide",
1925
+ value: function hide() {
1926
+ if (!this.active) {
1927
+ return;
1928
+ }
1929
+ this.datepicker.exitEditMode();
1930
+ this.element.classList.remove('active', 'block');
1931
+ this.element.classList.add('active', 'block', 'hidden');
1932
+ this.active = false;
1933
+ triggerDatepickerEvent(this.datepicker, 'hide');
1934
+ }
1935
+ }, {
1936
+ key: "place",
1937
+ value: function place() {
1938
+ var _this$element = this.element,
1939
+ classList = _this$element.classList,
1940
+ style = _this$element.style;
1941
+ var _this$datepicker = this.datepicker,
1942
+ config = _this$datepicker.config,
1943
+ inputField = _this$datepicker.inputField;
1944
+ var container = config.container;
1945
+ var _this$element$getBoun = this.element.getBoundingClientRect(),
1946
+ calendarWidth = _this$element$getBoun.width,
1947
+ calendarHeight = _this$element$getBoun.height;
1948
+ var _container$getBoundin = container.getBoundingClientRect(),
1949
+ containerLeft = _container$getBoundin.left,
1950
+ containerTop = _container$getBoundin.top,
1951
+ containerWidth = _container$getBoundin.width;
1952
+ var _inputField$getBoundi = inputField.getBoundingClientRect(),
1953
+ inputLeft = _inputField$getBoundi.left,
1954
+ inputTop = _inputField$getBoundi.top,
1955
+ inputWidth = _inputField$getBoundi.width,
1956
+ inputHeight = _inputField$getBoundi.height;
1957
+ var _config$orientation = config.orientation,
1958
+ orientX = _config$orientation.x,
1959
+ orientY = _config$orientation.y;
1960
+ var scrollTop;
1961
+ var left;
1962
+ var top;
1963
+ if (container === document.body) {
1964
+ scrollTop = window.scrollY;
1965
+ left = inputLeft + window.scrollX;
1966
+ top = inputTop + scrollTop;
1967
+ } else {
1968
+ scrollTop = container.scrollTop;
1969
+ left = inputLeft - containerLeft;
1970
+ top = inputTop - containerTop + scrollTop;
1971
+ }
1972
+ if (orientX === 'auto') {
1973
+ if (left < 0) {
1974
+ // align to the left and move into visible area if input's left edge < window's
1975
+ orientX = 'left';
1976
+ left = 10;
1977
+ } else if (left + calendarWidth > containerWidth) {
1978
+ // align to the right if canlendar's right edge > container's
1979
+ orientX = 'right';
1980
+ } else {
1981
+ orientX = getTextDirection(inputField) === 'rtl' ? 'right' : 'left';
1982
+ }
1983
+ }
1984
+ if (orientX === 'right') {
1985
+ left -= calendarWidth - inputWidth;
1986
+ }
1987
+ if (orientY === 'auto') {
1988
+ orientY = top - calendarHeight < scrollTop ? 'bottom' : 'top';
1989
+ }
1990
+ if (orientY === 'top') {
1991
+ top -= calendarHeight;
1992
+ } else {
1993
+ top += inputHeight;
1994
+ }
1995
+ classList.remove('datepicker-orient-top', 'datepicker-orient-bottom', 'datepicker-orient-right', 'datepicker-orient-left');
1996
+ classList.add("datepicker-orient-".concat(orientY), "datepicker-orient-".concat(orientX));
1997
+ style.top = top ? "".concat(top, "px") : top;
1998
+ style.left = left ? "".concat(left, "px") : left;
1999
+ }
2000
+ }, {
2001
+ key: "setViewSwitchLabel",
2002
+ value: function setViewSwitchLabel(labelText) {
2003
+ this.controls.viewSwitch.textContent = labelText;
2004
+ }
2005
+ }, {
2006
+ key: "setPrevBtnDisabled",
2007
+ value: function setPrevBtnDisabled(disabled) {
2008
+ this.controls.prevBtn.disabled = disabled;
2009
+ }
2010
+ }, {
2011
+ key: "setNextBtnDisabled",
2012
+ value: function setNextBtnDisabled(disabled) {
2013
+ this.controls.nextBtn.disabled = disabled;
2014
+ }
2015
+ }, {
2016
+ key: "changeView",
2017
+ value: function changeView(viewId) {
2018
+ var oldView = this.currentView;
2019
+ var newView = this.views[viewId];
2020
+ if (newView.id !== oldView.id) {
2021
+ this.currentView = newView;
2022
+ this._renderMethod = 'render';
2023
+ triggerDatepickerEvent(this.datepicker, 'changeView');
2024
+ this.main.replaceChild(newView.element, oldView.element);
2025
+ }
2026
+ return this;
2027
+ }
2028
+
2029
+ // Change the focused date (view date)
2030
+ }, {
2031
+ key: "changeFocus",
2032
+ value: function changeFocus(newViewDate) {
2033
+ this._renderMethod = setViewDate(this, newViewDate) ? 'render' : 'refreshFocus';
2034
+ this.views.forEach(function (view) {
2035
+ view.updateFocus();
2036
+ });
2037
+ return this;
2038
+ }
2039
+
2040
+ // Apply the change of the selected dates
2041
+ }, {
2042
+ key: "update",
2043
+ value: function update() {
2044
+ var newViewDate = computeResetViewDate(this.datepicker);
2045
+ this._renderMethod = setViewDate(this, newViewDate) ? 'render' : 'refresh';
2046
+ this.views.forEach(function (view) {
2047
+ view.updateFocus();
2048
+ view.updateSelection();
2049
+ });
2050
+ return this;
2051
+ }
2052
+
2053
+ // Refresh the picker UI
2054
+ }, {
2055
+ key: "render",
2056
+ value: function render() {
2057
+ var quickRender = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2058
+ var renderMethod = quickRender && this._renderMethod || 'render';
2059
+ delete this._renderMethod;
2060
+ this.currentView[renderMethod]();
2061
+ }
2062
+ }]);
2063
+ }();
2064
+
2065
+ // Find the closest date that doesn't meet the condition for unavailable date
2066
+ // Returns undefined if no available date is found
2067
+ // addFn: function to calculate the next date
2068
+ // - args: time value, amount
2069
+ // increase: amount to pass to addFn
2070
+ // testFn: function to test the unavailablity of the date
2071
+ // - args: time value; retun: true if unavailable
2072
+ function findNextAvailableOne(date, addFn, increase, testFn, min, max) {
2073
+ if (!isInRange(date, min, max)) {
2074
+ return;
2075
+ }
2076
+ if (testFn(date)) {
2077
+ var newDate = addFn(date, increase);
2078
+ return findNextAvailableOne(newDate, addFn, increase, testFn, min, max);
2079
+ }
2080
+ return date;
2081
+ }
2082
+
2083
+ // direction: -1 (left/up), 1 (right/down)
2084
+ // vertical: true for up/down, false for left/right
2085
+ function moveByArrowKey(datepicker, ev, direction, vertical) {
2086
+ var picker = datepicker.picker;
2087
+ var currentView = picker.currentView;
2088
+ var step = currentView.step || 1;
2089
+ var viewDate = picker.viewDate;
2090
+ var addFn;
2091
+ var testFn;
2092
+ switch (currentView.id) {
2093
+ case 0:
2094
+ if (vertical) {
2095
+ viewDate = addDays(viewDate, direction * 7);
2096
+ } else if (ev.ctrlKey || ev.metaKey) {
2097
+ viewDate = addYears(viewDate, direction);
2098
+ } else {
2099
+ viewDate = addDays(viewDate, direction);
2100
+ }
2101
+ addFn = addDays;
2102
+ testFn = function testFn(date) {
2103
+ return currentView.disabled.includes(date);
2104
+ };
2105
+ break;
2106
+ case 1:
2107
+ viewDate = addMonths(viewDate, vertical ? direction * 4 : direction);
2108
+ addFn = addMonths;
2109
+ testFn = function testFn(date) {
2110
+ var dt = new Date(date);
2111
+ var year = currentView.year,
2112
+ disabled = currentView.disabled;
2113
+ return dt.getFullYear() === year && disabled.includes(dt.getMonth());
2114
+ };
2115
+ break;
2116
+ default:
2117
+ viewDate = addYears(viewDate, direction * (vertical ? 4 : 1) * step);
2118
+ addFn = addYears;
2119
+ testFn = function testFn(date) {
2120
+ return currentView.disabled.includes(startOfYearPeriod(date, step));
2121
+ };
2122
+ }
2123
+ viewDate = findNextAvailableOne(viewDate, addFn, direction < 0 ? -step : step, testFn, currentView.minDate, currentView.maxDate);
2124
+ if (viewDate !== undefined) {
2125
+ picker.changeFocus(viewDate).render();
2126
+ }
2127
+ }
2128
+ function onKeydown(datepicker, ev) {
2129
+ if (ev.key === 'Tab') {
2130
+ unfocus(datepicker);
2131
+ return;
2132
+ }
2133
+ var picker = datepicker.picker;
2134
+ var _picker$currentView = picker.currentView,
2135
+ id = _picker$currentView.id,
2136
+ isMinView = _picker$currentView.isMinView;
2137
+ if (!picker.active) {
2138
+ switch (ev.key) {
2139
+ case 'ArrowDown':
2140
+ case 'Escape':
2141
+ picker.show();
2142
+ break;
2143
+ case 'Enter':
2144
+ datepicker.update();
2145
+ break;
2146
+ default:
2147
+ return;
2148
+ }
2149
+ } else if (datepicker.editMode) {
2150
+ switch (ev.key) {
2151
+ case 'Escape':
2152
+ picker.hide();
2153
+ break;
2154
+ case 'Enter':
2155
+ datepicker.exitEditMode({
2156
+ update: true,
2157
+ autohide: datepicker.config.autohide
2158
+ });
2159
+ break;
2160
+ default:
2161
+ return;
2162
+ }
2163
+ } else {
2164
+ switch (ev.key) {
2165
+ case 'Escape':
2166
+ picker.hide();
2167
+ break;
2168
+ case 'ArrowLeft':
2169
+ if (ev.ctrlKey || ev.metaKey) {
2170
+ goToPrevOrNext(datepicker, -1);
2171
+ } else if (ev.shiftKey) {
2172
+ datepicker.enterEditMode();
2173
+ return;
2174
+ } else {
2175
+ moveByArrowKey(datepicker, ev, -1, false);
2176
+ }
2177
+ break;
2178
+ case 'ArrowRight':
2179
+ if (ev.ctrlKey || ev.metaKey) {
2180
+ goToPrevOrNext(datepicker, 1);
2181
+ } else if (ev.shiftKey) {
2182
+ datepicker.enterEditMode();
2183
+ return;
2184
+ } else {
2185
+ moveByArrowKey(datepicker, ev, 1, false);
2186
+ }
2187
+ break;
2188
+ case 'ArrowUp':
2189
+ if (ev.ctrlKey || ev.metaKey) {
2190
+ switchView(datepicker);
2191
+ } else if (ev.shiftKey) {
2192
+ datepicker.enterEditMode();
2193
+ return;
2194
+ } else {
2195
+ moveByArrowKey(datepicker, ev, -1, true);
2196
+ }
2197
+ break;
2198
+ case 'ArrowDown':
2199
+ if (ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
2200
+ datepicker.enterEditMode();
2201
+ return;
2202
+ }
2203
+ moveByArrowKey(datepicker, ev, 1, true);
2204
+ break;
2205
+ case 'Enter':
2206
+ if (isMinView) {
2207
+ datepicker.setDate(picker.viewDate);
2208
+ } else {
2209
+ picker.changeView(id - 1).render();
2210
+ }
2211
+ break;
2212
+ case 'Backspace':
2213
+ case 'Delete':
2214
+ datepicker.enterEditMode();
2215
+ return;
2216
+ default:
2217
+ if (ev.key.length === 1 && !ev.ctrlKey && !ev.metaKey) {
2218
+ datepicker.enterEditMode();
2219
+ }
2220
+ return;
2221
+ }
2222
+ }
2223
+ ev.preventDefault();
2224
+ ev.stopPropagation();
2225
+ }
2226
+ function onFocus(datepicker) {
2227
+ if (datepicker.config.showOnFocus && !datepicker._showing) {
2228
+ datepicker.show();
2229
+ }
2230
+ }
2231
+
2232
+ // for the prevention for entering edit mode while getting focus on click
2233
+ function onMousedown(datepicker, ev) {
2234
+ var el = ev.target;
2235
+ if (datepicker.picker.active || datepicker.config.showOnClick) {
2236
+ el._active = el === document.activeElement;
2237
+ el._clicking = setTimeout(function () {
2238
+ delete el._active;
2239
+ delete el._clicking;
2240
+ }, 2000);
2241
+ }
2242
+ }
2243
+ function onClickInput(datepicker, ev) {
2244
+ var el = ev.target;
2245
+ if (!el._clicking) {
2246
+ return;
2247
+ }
2248
+ clearTimeout(el._clicking);
2249
+ delete el._clicking;
2250
+ if (el._active) {
2251
+ datepicker.enterEditMode();
2252
+ }
2253
+ delete el._active;
2254
+ if (datepicker.config.showOnClick) {
2255
+ datepicker.show();
2256
+ }
2257
+ }
2258
+ function onPaste(datepicker, ev) {
2259
+ if (ev.clipboardData.types.includes('text/plain')) {
2260
+ datepicker.enterEditMode();
2261
+ }
2262
+ }
2263
+
2264
+ // for the `document` to delegate the events from outside the picker/input field
2265
+ function onClickOutside(datepicker, ev) {
2266
+ var element = datepicker.element;
2267
+ if (element !== document.activeElement) {
2268
+ return;
2269
+ }
2270
+ var pickerElem = datepicker.picker.element;
2271
+ if (findElementInEventPath(ev, function (el) {
2272
+ return el === element || el === pickerElem;
2273
+ })) {
2274
+ return;
2275
+ }
2276
+ unfocus(datepicker);
2277
+ }
2278
+
2279
+ function stringifyDates(dates, config) {
2280
+ return dates.map(function (dt) {
2281
+ return formatDate(dt, config.format, config.locale);
2282
+ }).join(config.dateDelimiter);
2283
+ }
2284
+
2285
+ // parse input dates and create an array of time values for selection
2286
+ // returns undefined if there are no valid dates in inputDates
2287
+ // when origDates (current selection) is passed, the function works to mix
2288
+ // the input dates into the current selection
2289
+ function processInputDates(datepicker, inputDates) {
2290
+ var clear = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
2291
+ var config = datepicker.config,
2292
+ origDates = datepicker.dates,
2293
+ rangepicker = datepicker.rangepicker;
2294
+ if (inputDates.length === 0) {
2295
+ // empty input is considered valid unless origiDates is passed
2296
+ return clear ? [] : undefined;
2297
+ }
2298
+ var rangeEnd = rangepicker && datepicker === rangepicker.datepickers[1];
2299
+ var newDates = inputDates.reduce(function (dates, dt) {
2300
+ var date = parseDate(dt, config.format, config.locale);
2301
+ if (date === undefined) {
2302
+ return dates;
2303
+ }
2304
+ if (config.pickLevel > 0) {
2305
+ // adjust to 1st of the month/Jan 1st of the year
2306
+ // or to the last day of the monh/Dec 31st of the year if the datepicker
2307
+ // is the range-end picker of a rangepicker
2308
+ var _dt = new Date(date);
2309
+ if (config.pickLevel === 1) {
2310
+ date = rangeEnd ? _dt.setMonth(_dt.getMonth() + 1, 0) : _dt.setDate(1);
2311
+ } else {
2312
+ date = rangeEnd ? _dt.setFullYear(_dt.getFullYear() + 1, 0, 0) : _dt.setMonth(0, 1);
2313
+ }
2314
+ }
2315
+ if (isInRange(date, config.minDate, config.maxDate) && !dates.includes(date) && !config.datesDisabled.includes(date) && !config.daysOfWeekDisabled.includes(new Date(date).getDay())) {
2316
+ dates.push(date);
2317
+ }
2318
+ return dates;
2319
+ }, []);
2320
+ if (newDates.length === 0) {
2321
+ return;
2322
+ }
2323
+ if (config.multidate && !clear) {
2324
+ // get the synmetric difference between origDates and newDates
2325
+ newDates = newDates.reduce(function (dates, date) {
2326
+ if (!origDates.includes(date)) {
2327
+ dates.push(date);
2328
+ }
2329
+ return dates;
2330
+ }, origDates.filter(function (date) {
2331
+ return !newDates.includes(date);
2332
+ }));
2333
+ }
2334
+ // do length check always because user can input multiple dates regardless of the mode
2335
+ return config.maxNumberOfDates && newDates.length > config.maxNumberOfDates ? newDates.slice(config.maxNumberOfDates * -1) : newDates;
2336
+ }
2337
+
2338
+ // refresh the UI elements
2339
+ // modes: 1: input only, 2, picker only, 3 both
2340
+ function refreshUI(datepicker) {
2341
+ var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
2342
+ var quickRender = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
2343
+ var config = datepicker.config,
2344
+ picker = datepicker.picker,
2345
+ inputField = datepicker.inputField;
2346
+ if (mode & 2) {
2347
+ var newView = picker.active ? config.pickLevel : config.startView;
2348
+ picker.update().changeView(newView).render(quickRender);
2349
+ }
2350
+ if (mode & 1 && inputField) {
2351
+ inputField.value = stringifyDates(datepicker.dates, config);
2352
+ }
2353
+ }
2354
+ function _setDate(datepicker, inputDates, options) {
2355
+ var clear = options.clear,
2356
+ render = options.render,
2357
+ autohide = options.autohide;
2358
+ if (render === undefined) {
2359
+ render = true;
2360
+ }
2361
+ if (!render) {
2362
+ autohide = false;
2363
+ } else if (autohide === undefined) {
2364
+ autohide = datepicker.config.autohide;
2365
+ }
2366
+ var newDates = processInputDates(datepicker, inputDates, clear);
2367
+ if (!newDates) {
2368
+ return;
2369
+ }
2370
+ if (newDates.toString() !== datepicker.dates.toString()) {
2371
+ datepicker.dates = newDates;
2372
+ refreshUI(datepicker, render ? 3 : 1);
2373
+ triggerDatepickerEvent(datepicker, 'changeDate');
2374
+ } else {
2375
+ refreshUI(datepicker, 1);
2376
+ }
2377
+ if (autohide) {
2378
+ datepicker.hide();
2379
+ }
2380
+ }
2381
+
2382
+ /**
2383
+ * Class representing a date picker
2384
+ */
2385
+ var Datepicker = /*#__PURE__*/function () {
2386
+ /**
2387
+ * Create a date picker
2388
+ * @param {Element} element - element to bind a date picker
2389
+ * @param {Object} [options] - config options
2390
+ * @param {DateRangePicker} [rangepicker] - DateRangePicker instance the
2391
+ * date picker belongs to. Use this only when creating date picker as a part
2392
+ * of date range picker
2393
+ */
2394
+ function Datepicker(element) {
2395
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2396
+ var rangepicker = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
2397
+ _classCallCheck(this, Datepicker);
2398
+ element.datepicker = this;
2399
+ this.element = element;
2400
+
2401
+ // set up config
2402
+ var config = this.config = Object.assign({
2403
+ buttonClass: options.buttonClass && String(options.buttonClass) || 'button',
2404
+ container: document.body,
2405
+ defaultViewDate: today(),
2406
+ maxDate: undefined,
2407
+ minDate: undefined
2408
+ }, processOptions(defaultOptions, this));
2409
+ this._options = options;
2410
+ Object.assign(config, processOptions(options, this));
2411
+
2412
+ // configure by type
2413
+ var inline = this.inline = element.tagName !== 'INPUT';
2414
+ var inputField;
2415
+ var initialDates;
2416
+ if (inline) {
2417
+ config.container = element;
2418
+ initialDates = stringToArray(element.dataset.date, config.dateDelimiter);
2419
+ delete element.dataset.date;
2420
+ } else {
2421
+ var container = options.container ? document.querySelector(options.container) : null;
2422
+ if (container) {
2423
+ config.container = container;
2424
+ }
2425
+ inputField = this.inputField = element;
2426
+ inputField.classList.add('datepicker-input');
2427
+ initialDates = stringToArray(inputField.value, config.dateDelimiter);
2428
+ }
2429
+ if (rangepicker) {
2430
+ // check validiry
2431
+ var index = rangepicker.inputs.indexOf(inputField);
2432
+ var datepickers = rangepicker.datepickers;
2433
+ if (index < 0 || index > 1 || !Array.isArray(datepickers)) {
2434
+ throw Error('Invalid rangepicker object.');
2435
+ }
2436
+ // attach itaelf to the rangepicker here so that processInputDates() can
2437
+ // determine if this is the range-end picker of the rangepicker while
2438
+ // setting inital values when pickLevel > 0
2439
+ datepickers[index] = this;
2440
+ // add getter for rangepicker
2441
+ Object.defineProperty(this, 'rangepicker', {
2442
+ get: function get() {
2443
+ return rangepicker;
2444
+ }
2445
+ });
2446
+ }
2447
+
2448
+ // set initial dates
2449
+ this.dates = [];
2450
+ // process initial value
2451
+ var inputDateValues = processInputDates(this, initialDates);
2452
+ if (inputDateValues && inputDateValues.length > 0) {
2453
+ this.dates = inputDateValues;
2454
+ }
2455
+ if (inputField) {
2456
+ inputField.value = stringifyDates(this.dates, config);
2457
+ }
2458
+ var picker = this.picker = new Picker(this);
2459
+ if (inline) {
2460
+ this.show();
2461
+ } else {
2462
+ // set up event listeners in other modes
2463
+ var onMousedownDocument = onClickOutside.bind(null, this);
2464
+ var listeners = [[inputField, 'keydown', onKeydown.bind(null, this)], [inputField, 'focus', onFocus.bind(null, this)], [inputField, 'mousedown', onMousedown.bind(null, this)], [inputField, 'click', onClickInput.bind(null, this)], [inputField, 'paste', onPaste.bind(null, this)], [document, 'mousedown', onMousedownDocument], [document, 'touchstart', onMousedownDocument], [window, 'resize', picker.place.bind(picker)]];
2465
+ registerListeners(this, listeners);
2466
+ }
2467
+ }
2468
+
2469
+ /**
2470
+ * Format Date object or time value in given format and language
2471
+ * @param {Date|Number} date - date or time value to format
2472
+ * @param {String|Object} format - format string or object that contains
2473
+ * toDisplay() custom formatter, whose signature is
2474
+ * - args:
2475
+ * - date: {Date} - Date instance of the date passed to the method
2476
+ * - format: {Object} - the format object passed to the method
2477
+ * - locale: {Object} - locale for the language specified by `lang`
2478
+ * - return:
2479
+ * {String} formatted date
2480
+ * @param {String} [lang=en] - language code for the locale to use
2481
+ * @return {String} formatted date
2482
+ */
2483
+ return _createClass(Datepicker, [{
2484
+ key: "active",
2485
+ get:
2486
+ /**
2487
+ * @type {Boolean} - Whether the picker element is shown. `true` whne shown
2488
+ */
2489
+ function get() {
2490
+ return !!(this.picker && this.picker.active);
2491
+ }
2492
+
2493
+ /**
2494
+ * @type {HTMLDivElement} - DOM object of picker element
2495
+ */
2496
+ }, {
2497
+ key: "pickerElement",
2498
+ get: function get() {
2499
+ return this.picker ? this.picker.element : undefined;
2500
+ }
2501
+
2502
+ /**
2503
+ * Set new values to the config options
2504
+ * @param {Object} options - config options to update
2505
+ */
2506
+ }, {
2507
+ key: "setOptions",
2508
+ value: function setOptions(options) {
2509
+ var picker = this.picker;
2510
+ var newOptions = processOptions(options, this);
2511
+ Object.assign(this._options, options);
2512
+ Object.assign(this.config, newOptions);
2513
+ picker.setOptions(newOptions);
2514
+ refreshUI(this, 3);
2515
+ }
2516
+
2517
+ /**
2518
+ * Show the picker element
2519
+ */
2520
+ }, {
2521
+ key: "show",
2522
+ value: function show() {
2523
+ if (this.inputField) {
2524
+ if (this.inputField.disabled) {
2525
+ return;
2526
+ }
2527
+ if (this.inputField !== document.activeElement) {
2528
+ this._showing = true;
2529
+ this.inputField.focus();
2530
+ delete this._showing;
2531
+ }
2532
+ }
2533
+ this.picker.show();
2534
+ }
2535
+
2536
+ /**
2537
+ * Hide the picker element
2538
+ * Not available on inline picker
2539
+ */
2540
+ }, {
2541
+ key: "hide",
2542
+ value: function hide() {
2543
+ if (this.inline) {
2544
+ return;
2545
+ }
2546
+ this.picker.hide();
2547
+ this.picker.update().changeView(this.config.startView).render();
2548
+ }
2549
+
2550
+ /**
2551
+ * Destroy the Datepicker instance
2552
+ * @return {Detepicker} - the instance destroyed
2553
+ */
2554
+ }, {
2555
+ key: "destroy",
2556
+ value: function destroy() {
2557
+ this.hide();
2558
+ unregisterListeners(this);
2559
+ this.picker.detach();
2560
+ if (!this.inline) {
2561
+ this.inputField.classList.remove('datepicker-input');
2562
+ }
2563
+ delete this.element.datepicker;
2564
+ return this;
2565
+ }
2566
+
2567
+ /**
2568
+ * Get the selected date(s)
2569
+ *
2570
+ * The method returns a Date object of selected date by default, and returns
2571
+ * an array of selected dates in multidate mode. If format string is passed,
2572
+ * it returns date string(s) formatted in given format.
2573
+ *
2574
+ * @param {String} [format] - Format string to stringify the date(s)
2575
+ * @return {Date|String|Date[]|String[]} - selected date(s), or if none is
2576
+ * selected, empty array in multidate mode and untitled in sigledate mode
2577
+ */
2578
+ }, {
2579
+ key: "getDate",
2580
+ value: function getDate() {
2581
+ var _this = this;
2582
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
2583
+ var callback = format ? function (date) {
2584
+ return formatDate(date, format, _this.config.locale);
2585
+ } : function (date) {
2586
+ return new Date(date);
2587
+ };
2588
+ if (this.config.multidate) {
2589
+ return this.dates.map(callback);
2590
+ }
2591
+ if (this.dates.length > 0) {
2592
+ return callback(this.dates[0]);
2593
+ }
2594
+ }
2595
+
2596
+ /**
2597
+ * Set selected date(s)
2598
+ *
2599
+ * In multidate mode, you can pass multiple dates as a series of arguments
2600
+ * or an array. (Since each date is parsed individually, the type of the
2601
+ * dates doesn't have to be the same.)
2602
+ * The given dates are used to toggle the select status of each date. The
2603
+ * number of selected dates is kept from exceeding the length set to
2604
+ * maxNumberOfDates.
2605
+ *
2606
+ * With clear: true option, the method can be used to clear the selection
2607
+ * and to replace the selection instead of toggling in multidate mode.
2608
+ * If the option is passed with no date arguments or an empty dates array,
2609
+ * it works as "clear" (clear the selection then set nothing), and if the
2610
+ * option is passed with new dates to select, it works as "replace" (clear
2611
+ * the selection then set the given dates)
2612
+ *
2613
+ * When render: false option is used, the method omits re-rendering the
2614
+ * picker element. In this case, you need to call refresh() method later in
2615
+ * order for the picker element to reflect the changes. The input field is
2616
+ * refreshed always regardless of this option.
2617
+ *
2618
+ * When invalid (unparsable, repeated, disabled or out-of-range) dates are
2619
+ * passed, the method ignores them and applies only valid ones. In the case
2620
+ * that all the given dates are invalid, which is distinguished from passing
2621
+ * no dates, the method considers it as an error and leaves the selection
2622
+ * untouched.
2623
+ *
2624
+ * @param {...(Date|Number|String)|Array} [dates] - Date strings, Date
2625
+ * objects, time values or mix of those for new selection
2626
+ * @param {Object} [options] - function options
2627
+ * - clear: {boolean} - Whether to clear the existing selection
2628
+ * defualt: false
2629
+ * - render: {boolean} - Whether to re-render the picker element
2630
+ * default: true
2631
+ * - autohide: {boolean} - Whether to hide the picker element after re-render
2632
+ * Ignored when used with render: false
2633
+ * default: config.autohide
2634
+ */
2635
+ }, {
2636
+ key: "setDate",
2637
+ value: function setDate() {
2638
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2639
+ args[_key] = arguments[_key];
2640
+ }
2641
+ var dates = [].concat(args);
2642
+ var opts = {};
2643
+ var lastArg = lastItemOf(args);
2644
+ if (_typeof(lastArg) === 'object' && !Array.isArray(lastArg) && !(lastArg instanceof Date) && lastArg) {
2645
+ Object.assign(opts, dates.pop());
2646
+ }
2647
+ var inputDates = Array.isArray(dates[0]) ? dates[0] : dates;
2648
+ _setDate(this, inputDates, opts);
2649
+ }
2650
+
2651
+ /**
2652
+ * Update the selected date(s) with input field's value
2653
+ * Not available on inline picker
2654
+ *
2655
+ * The input field will be refreshed with properly formatted date string.
2656
+ *
2657
+ * @param {Object} [options] - function options
2658
+ * - autohide: {boolean} - whether to hide the picker element after refresh
2659
+ * default: false
2660
+ */
2661
+ }, {
2662
+ key: "update",
2663
+ value: function update() {
2664
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
2665
+ if (this.inline) {
2666
+ return;
2667
+ }
2668
+ var opts = {
2669
+ clear: true,
2670
+ autohide: !!(options && options.autohide)
2671
+ };
2672
+ var inputDates = stringToArray(this.inputField.value, this.config.dateDelimiter);
2673
+ _setDate(this, inputDates, opts);
2674
+ }
2675
+
2676
+ /**
2677
+ * Refresh the picker element and the associated input field
2678
+ * @param {String} [target] - target item when refreshing one item only
2679
+ * 'picker' or 'input'
2680
+ * @param {Boolean} [forceRender] - whether to re-render the picker element
2681
+ * regardless of its state instead of optimized refresh
2682
+ */
2683
+ }, {
2684
+ key: "refresh",
2685
+ value: function refresh() {
2686
+ var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
2687
+ var forceRender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2688
+ if (target && typeof target !== 'string') {
2689
+ forceRender = target;
2690
+ target = undefined;
2691
+ }
2692
+ var mode;
2693
+ if (target === 'picker') {
2694
+ mode = 2;
2695
+ } else if (target === 'input') {
2696
+ mode = 1;
2697
+ } else {
2698
+ mode = 3;
2699
+ }
2700
+ refreshUI(this, mode, !forceRender);
2701
+ }
2702
+
2703
+ /**
2704
+ * Enter edit mode
2705
+ * Not available on inline picker or when the picker element is hidden
2706
+ */
2707
+ }, {
2708
+ key: "enterEditMode",
2709
+ value: function enterEditMode() {
2710
+ if (this.inline || !this.picker.active || this.editMode) {
2711
+ return;
2712
+ }
2713
+ this.editMode = true;
2714
+ this.inputField.classList.add('in-edit', 'border-brand');
2715
+ }
2716
+
2717
+ /**
2718
+ * Exit from edit mode
2719
+ * Not available on inline picker
2720
+ * @param {Object} [options] - function options
2721
+ * - update: {boolean} - whether to call update() after exiting
2722
+ * If false, input field is revert to the existing selection
2723
+ * default: false
2724
+ */
2725
+ }, {
2726
+ key: "exitEditMode",
2727
+ value: function exitEditMode() {
2728
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
2729
+ if (this.inline || !this.editMode) {
2730
+ return;
2731
+ }
2732
+ var opts = Object.assign({
2733
+ update: false
2734
+ }, options);
2735
+ delete this.editMode;
2736
+ this.inputField.classList.remove('in-edit', 'border-brand');
2737
+ if (opts.update) {
2738
+ this.update(opts);
2739
+ }
2740
+ }
2741
+ }], [{
2742
+ key: "formatDate",
2743
+ value: function formatDate$1(date, format, lang) {
2744
+ return formatDate(date, format, lang && locales[lang] || locales.en);
2745
+ }
2746
+
2747
+ /**
2748
+ * Parse date string
2749
+ * @param {String|Date|Number} dateStr - date string, Date object or time
2750
+ * value to parse
2751
+ * @param {String|Object} format - format string or object that contains
2752
+ * toValue() custom parser, whose signature is
2753
+ * - args:
2754
+ * - dateStr: {String|Date|Number} - the dateStr passed to the method
2755
+ * - format: {Object} - the format object passed to the method
2756
+ * - locale: {Object} - locale for the language specified by `lang`
2757
+ * - return:
2758
+ * {Date|Number} parsed date or its time value
2759
+ * @param {String} [lang=en] - language code for the locale to use
2760
+ * @return {Number} time value of parsed date
2761
+ */
2762
+ }, {
2763
+ key: "parseDate",
2764
+ value: function parseDate$1(dateStr, format, lang) {
2765
+ return parseDate(dateStr, format, lang && locales[lang] || locales.en);
2766
+ }
2767
+
2768
+ /**
2769
+ * @type {Object} - Installed locales in `[languageCode]: localeObject` format
2770
+ * en`:_English (US)_ is pre-installed.
2771
+ */
2772
+ }, {
2773
+ key: "locales",
2774
+ get: function get() {
2775
+ return locales;
2776
+ }
2777
+ }]);
2778
+ }();
2779
+
2780
+ // filter out the config options inapproprite to pass to Datepicker
2781
+ function filterOptions(options) {
2782
+ var newOpts = Object.assign({}, options);
2783
+ delete newOpts.inputs;
2784
+ delete newOpts.allowOneSidedRange;
2785
+ delete newOpts.maxNumberOfDates; // to ensure each datepicker handles a single date
2786
+
2787
+ return newOpts;
2788
+ }
2789
+ function setupDatepicker(rangepicker, changeDateListener, el, options) {
2790
+ registerListeners(rangepicker, [[el, 'changeDate', changeDateListener]]);
2791
+ new Datepicker(el, options, rangepicker);
2792
+ }
2793
+ function onChangeDate(rangepicker, ev) {
2794
+ // to prevent both datepickers trigger the other side's update each other
2795
+ if (rangepicker._updating) {
2796
+ return;
2797
+ }
2798
+ rangepicker._updating = true;
2799
+ var target = ev.target;
2800
+ if (target.datepicker === undefined) {
2801
+ return;
2802
+ }
2803
+ var datepickers = rangepicker.datepickers;
2804
+ var setDateOptions = {
2805
+ render: false
2806
+ };
2807
+ var changedSide = rangepicker.inputs.indexOf(target);
2808
+ var otherSide = changedSide === 0 ? 1 : 0;
2809
+ var changedDate = datepickers[changedSide].dates[0];
2810
+ var otherDate = datepickers[otherSide].dates[0];
2811
+ if (changedDate !== undefined && otherDate !== undefined) {
2812
+ // if the start of the range > the end, swap them
2813
+ if (changedSide === 0 && changedDate > otherDate) {
2814
+ datepickers[0].setDate(otherDate, setDateOptions);
2815
+ datepickers[1].setDate(changedDate, setDateOptions);
2816
+ } else if (changedSide === 1 && changedDate < otherDate) {
2817
+ datepickers[0].setDate(changedDate, setDateOptions);
2818
+ datepickers[1].setDate(otherDate, setDateOptions);
2819
+ }
2820
+ } else if (!rangepicker.allowOneSidedRange) {
2821
+ // to prevent the range from becoming one-sided, copy changed side's
2822
+ // selection (no matter if it's empty) to the other side
2823
+ if (changedDate !== undefined || otherDate !== undefined) {
2824
+ setDateOptions.clear = true;
2825
+ datepickers[otherSide].setDate(datepickers[changedSide].dates, setDateOptions);
2826
+ }
2827
+ }
2828
+ datepickers[0].picker.update().render();
2829
+ datepickers[1].picker.update().render();
2830
+ delete rangepicker._updating;
2831
+ }
2832
+
2833
+ /**
2834
+ * Class representing a date range picker
2835
+ */
2836
+ var DateRangePicker = /*#__PURE__*/function () {
2837
+ /**
2838
+ * Create a date range picker
2839
+ * @param {Element} element - element to bind a date range picker
2840
+ * @param {Object} [options] - config options
2841
+ */
2842
+ function DateRangePicker(element) {
2843
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2844
+ _classCallCheck(this, DateRangePicker);
2845
+ var inputs = Array.isArray(options.inputs) ? options.inputs : Array.from(element.querySelectorAll('input'));
2846
+ if (inputs.length < 2) {
2847
+ return;
2848
+ }
2849
+ element.rangepicker = this;
2850
+ this.element = element;
2851
+ this.inputs = inputs.slice(0, 2);
2852
+ this.allowOneSidedRange = !!options.allowOneSidedRange;
2853
+ var changeDateListener = onChangeDate.bind(null, this);
2854
+ var cleanOptions = filterOptions(options);
2855
+ // in order for initial date setup to work right when pcicLvel > 0,
2856
+ // let Datepicker constructor add the instance to the rangepicker
2857
+ var datepickers = [];
2858
+ Object.defineProperty(this, 'datepickers', {
2859
+ get: function get() {
2860
+ return datepickers;
2861
+ }
2862
+ });
2863
+ setupDatepicker(this, changeDateListener, this.inputs[0], cleanOptions);
2864
+ setupDatepicker(this, changeDateListener, this.inputs[1], cleanOptions);
2865
+ Object.freeze(datepickers);
2866
+ // normalize the range if inital dates are given
2867
+ if (datepickers[0].dates.length > 0) {
2868
+ onChangeDate(this, {
2869
+ target: this.inputs[0]
2870
+ });
2871
+ } else if (datepickers[1].dates.length > 0) {
2872
+ onChangeDate(this, {
2873
+ target: this.inputs[1]
2874
+ });
2875
+ }
2876
+ }
2877
+
2878
+ /**
2879
+ * @type {Array} - selected date of the linked date pickers
2880
+ */
2881
+ return _createClass(DateRangePicker, [{
2882
+ key: "dates",
2883
+ get: function get() {
2884
+ return this.datepickers.length === 2 ? [this.datepickers[0].dates[0], this.datepickers[1].dates[0]] : undefined;
2885
+ }
2886
+
2887
+ /**
2888
+ * Set new values to the config options
2889
+ * @param {Object} options - config options to update
2890
+ */
2891
+ }, {
2892
+ key: "setOptions",
2893
+ value: function setOptions(options) {
2894
+ this.allowOneSidedRange = !!options.allowOneSidedRange;
2895
+ var cleanOptions = filterOptions(options);
2896
+ this.datepickers[0].setOptions(cleanOptions);
2897
+ this.datepickers[1].setOptions(cleanOptions);
2898
+ }
2899
+
2900
+ /**
2901
+ * Destroy the DateRangePicker instance
2902
+ * @return {DateRangePicker} - the instance destroyed
2903
+ */
2904
+ }, {
2905
+ key: "destroy",
2906
+ value: function destroy() {
2907
+ this.datepickers[0].destroy();
2908
+ this.datepickers[1].destroy();
2909
+ unregisterListeners(this);
2910
+ delete this.element.rangepicker;
2911
+ }
2912
+
2913
+ /**
2914
+ * Get the start and end dates of the date range
2915
+ *
2916
+ * The method returns Date objects by default. If format string is passed,
2917
+ * it returns date strings formatted in given format.
2918
+ * The result array always contains 2 items (start date/end date) and
2919
+ * undefined is used for unselected side. (e.g. If none is selected,
2920
+ * the result will be [undefined, undefined]. If only the end date is set
2921
+ * when allowOneSidedRange config option is true, [undefined, endDate] will
2922
+ * be returned.)
2923
+ *
2924
+ * @param {String} [format] - Format string to stringify the dates
2925
+ * @return {Array} - Start and end dates
2926
+ */
2927
+ }, {
2928
+ key: "getDates",
2929
+ value: function getDates() {
2930
+ var _this = this;
2931
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
2932
+ var callback = format ? function (date) {
2933
+ return formatDate(date, format, _this.datepickers[0].config.locale);
2934
+ } : function (date) {
2935
+ return new Date(date);
2936
+ };
2937
+ return this.dates.map(function (date) {
2938
+ return date === undefined ? date : callback(date);
2939
+ });
2940
+ }
2941
+
2942
+ /**
2943
+ * Set the start and end dates of the date range
2944
+ *
2945
+ * The method calls datepicker.setDate() internally using each of the
2946
+ * arguments in start→end order.
2947
+ *
2948
+ * When a clear: true option object is passed instead of a date, the method
2949
+ * clears the date.
2950
+ *
2951
+ * If an invalid date, the same date as the current one or an option object
2952
+ * without clear: true is passed, the method considers that argument as an
2953
+ * "ineffective" argument because calling datepicker.setDate() with those
2954
+ * values makes no changes to the date selection.
2955
+ *
2956
+ * When the allowOneSidedRange config option is false, passing {clear: true}
2957
+ * to clear the range works only when it is done to the last effective
2958
+ * argument (in other words, passed to rangeEnd or to rangeStart along with
2959
+ * ineffective rangeEnd). This is because when the date range is changed,
2960
+ * it gets normalized based on the last change at the end of the changing
2961
+ * process.
2962
+ *
2963
+ * @param {Date|Number|String|Object} rangeStart - Start date of the range
2964
+ * or {clear: true} to clear the date
2965
+ * @param {Date|Number|String|Object} rangeEnd - End date of the range
2966
+ * or {clear: true} to clear the date
2967
+ */
2968
+ }, {
2969
+ key: "setDates",
2970
+ value: function setDates(rangeStart, rangeEnd) {
2971
+ var _this$datepickers = _slicedToArray(this.datepickers, 2),
2972
+ datepicker0 = _this$datepickers[0],
2973
+ datepicker1 = _this$datepickers[1];
2974
+ var origDates = this.dates;
2975
+
2976
+ // If range normalization runs on every change, we can't set a new range
2977
+ // that starts after the end of the current range correctly because the
2978
+ // normalization process swaps start↔︎end right after setting the new start
2979
+ // date. To prevent this, the normalization process needs to run once after
2980
+ // both of the new dates are set.
2981
+ this._updating = true;
2982
+ datepicker0.setDate(rangeStart);
2983
+ datepicker1.setDate(rangeEnd);
2984
+ delete this._updating;
2985
+ if (datepicker1.dates[0] !== origDates[1]) {
2986
+ onChangeDate(this, {
2987
+ target: this.inputs[1]
2988
+ });
2989
+ } else if (datepicker0.dates[0] !== origDates[0]) {
2990
+ onChangeDate(this, {
2991
+ target: this.inputs[0]
2992
+ });
2993
+ }
2994
+ }
2995
+ }]);
2996
+ }();
2997
+
2998
+ exports.DateRangePicker = DateRangePicker;
2999
+ exports.Datepicker = Datepicker;