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