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