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