@ohos-ports/flowbite-datepicker 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +73 -0
  3. package/.stylelintrc +12 -0
  4. package/CHANGELOG.md +72 -0
  5. package/LICENSE +21 -0
  6. package/README.md +71 -0
  7. package/demo/index.html +582 -0
  8. package/demo/live-demo.js +471 -0
  9. package/dist/DateRangePicker.cjs.js +2996 -0
  10. package/dist/DateRangePicker.esm.js +2994 -0
  11. package/dist/DateRangePicker.umd.js +3002 -0
  12. package/dist/Datepicker.cjs.js +2778 -0
  13. package/dist/Datepicker.esm.js +2776 -0
  14. package/dist/Datepicker.umd.js +2784 -0
  15. package/dist/css/datepicker-bs4.css +276 -0
  16. package/dist/css/datepicker-bs4.min.css +1 -0
  17. package/dist/css/datepicker-bs5.css +276 -0
  18. package/dist/css/datepicker-bs5.min.css +1 -0
  19. package/dist/css/datepicker-bulma.css +258 -0
  20. package/dist/css/datepicker-bulma.min.css +1 -0
  21. package/dist/css/datepicker-foundation.css +262 -0
  22. package/dist/css/datepicker-foundation.min.css +1 -0
  23. package/dist/css/datepicker.css +306 -0
  24. package/dist/css/datepicker.min.css +1403 -0
  25. package/dist/js/datepicker-full.js +2777 -0
  26. package/dist/js/datepicker-full.min.js +1 -0
  27. package/dist/js/datepicker.js +2569 -0
  28. package/dist/js/datepicker.min.js +1 -0
  29. package/dist/js/locales/ar-tn.js +15 -0
  30. package/dist/js/locales/ar.js +15 -0
  31. package/dist/js/locales/az.js +14 -0
  32. package/dist/js/locales/bg.js +14 -0
  33. package/dist/js/locales/bm.js +18 -0
  34. package/dist/js/locales/bn.js +19 -0
  35. package/dist/js/locales/br.js +18 -0
  36. package/dist/js/locales/bs.js +15 -0
  37. package/dist/js/locales/ca.js +18 -0
  38. package/dist/js/locales/cs.js +19 -0
  39. package/dist/js/locales/cy.js +14 -0
  40. package/dist/js/locales/da.js +19 -0
  41. package/dist/js/locales/de.js +18 -0
  42. package/dist/js/locales/el.js +16 -0
  43. package/dist/js/locales/en-AU.js +18 -0
  44. package/dist/js/locales/en-CA.js +18 -0
  45. package/dist/js/locales/en-GB.js +18 -0
  46. package/dist/js/locales/en-IE.js +17 -0
  47. package/dist/js/locales/en-NZ.js +17 -0
  48. package/dist/js/locales/en-ZA.js +17 -0
  49. package/dist/js/locales/eo.js +17 -0
  50. package/dist/js/locales/es.js +18 -0
  51. package/dist/js/locales/et.js +18 -0
  52. package/dist/js/locales/eu.js +18 -0
  53. package/dist/js/locales/fa.js +17 -0
  54. package/dist/js/locales/fi.js +17 -0
  55. package/dist/js/locales/fo.js +15 -0
  56. package/dist/js/locales/fr-CH.js +21 -0
  57. package/dist/js/locales/fr.js +18 -0
  58. package/dist/js/locales/gl.js +16 -0
  59. package/dist/js/locales/he.js +15 -0
  60. package/dist/js/locales/hi.js +18 -0
  61. package/dist/js/locales/hr.js +13 -0
  62. package/dist/js/locales/hu.js +18 -0
  63. package/dist/js/locales/hy.js +18 -0
  64. package/dist/js/locales/id.js +15 -0
  65. package/dist/js/locales/is.js +14 -0
  66. package/dist/js/locales/it-CH.js +20 -0
  67. package/dist/js/locales/it.js +18 -0
  68. package/dist/js/locales/ja.js +17 -0
  69. package/dist/js/locales/ka.js +17 -0
  70. package/dist/js/locales/kk.js +15 -0
  71. package/dist/js/locales/km.js +15 -0
  72. package/dist/js/locales/ko.js +18 -0
  73. package/dist/js/locales/lt.js +19 -0
  74. package/dist/js/locales/lv.js +18 -0
  75. package/dist/js/locales/me.js +17 -0
  76. package/dist/js/locales/mk.js +15 -0
  77. package/dist/js/locales/mn.js +17 -0
  78. package/dist/js/locales/mr.js +18 -0
  79. package/dist/js/locales/ms.js +15 -0
  80. package/dist/js/locales/nl-BE.js +18 -0
  81. package/dist/js/locales/nl.js +18 -0
  82. package/dist/js/locales/no.js +18 -0
  83. package/dist/js/locales/oc.js +17 -0
  84. package/dist/js/locales/pl.js +17 -0
  85. package/dist/js/locales/pt-BR.js +17 -0
  86. package/dist/js/locales/pt.js +18 -0
  87. package/dist/js/locales/ro.js +17 -0
  88. package/dist/js/locales/ru.js +18 -0
  89. package/dist/js/locales/si.js +18 -0
  90. package/dist/js/locales/sk.js +18 -0
  91. package/dist/js/locales/sl.js +15 -0
  92. package/dist/js/locales/sq.js +18 -0
  93. package/dist/js/locales/sr-latn.js +16 -0
  94. package/dist/js/locales/sr.js +16 -0
  95. package/dist/js/locales/sv.js +17 -0
  96. package/dist/js/locales/sw.js +15 -0
  97. package/dist/js/locales/ta.js +18 -0
  98. package/dist/js/locales/tg.js +19 -0
  99. package/dist/js/locales/th.js +14 -0
  100. package/dist/js/locales/tk.js +18 -0
  101. package/dist/js/locales/tr.js +17 -0
  102. package/dist/js/locales/uk.js +17 -0
  103. package/dist/js/locales/uz-cyrl.js +18 -0
  104. package/dist/js/locales/uz-latn.js +18 -0
  105. package/dist/js/locales/vi.js +16 -0
  106. package/dist/js/locales/zh-CN.js +19 -0
  107. package/dist/js/locales/zh-TW.js +18 -0
  108. package/dist/locales/index.cjs.js +1028 -0
  109. package/dist/locales/index.esm.js +1028 -0
  110. package/dist/main.cjs.js +2999 -0
  111. package/dist/main.esm.js +2994 -0
  112. package/dist/main.umd.js +3005 -0
  113. package/docs/.nojekyll +0 -0
  114. package/docs/README.md +266 -0
  115. package/docs/_sidebar.md +6 -0
  116. package/docs/api.md +284 -0
  117. package/docs/date-string+format.md +90 -0
  118. package/docs/i18n.md +99 -0
  119. package/docs/images/datepicker-inline.jpg +0 -0
  120. package/docs/images/datepicker.jpg +0 -0
  121. package/docs/images/multidate.jpg +0 -0
  122. package/docs/images/picker-structure.jpg +0 -0
  123. package/docs/images/rangepicker.jpg +0 -0
  124. package/docs/images/view-days.jpg +0 -0
  125. package/docs/images/view-decades.jpg +0 -0
  126. package/docs/images/view-months.jpg +0 -0
  127. package/docs/images/view-years.jpg +0 -0
  128. package/docs/index.html +26 -0
  129. package/docs/options.md +354 -0
  130. package/docs/overview.md +174 -0
  131. package/extras/twoDigitToFullYear/test/twoDigitToFullYear.js +58 -0
  132. package/extras/twoDigitToFullYear/twoDigitToFullYear.js +26 -0
  133. package/js/DateRangePicker.js +210 -0
  134. package/js/Datepicker.js +487 -0
  135. package/js/datepicker-full.js +5 -0
  136. package/js/events/functions.js +48 -0
  137. package/js/events/inputFieldListeners.js +206 -0
  138. package/js/events/otherListeners.js +15 -0
  139. package/js/events/pickerListeners.js +70 -0
  140. package/js/i18n/base-locales.js +13 -0
  141. package/js/i18n/locales/ar-tn.js +15 -0
  142. package/js/i18n/locales/ar.js +15 -0
  143. package/js/i18n/locales/az.js +14 -0
  144. package/js/i18n/locales/bg.js +14 -0
  145. package/js/i18n/locales/bm.js +18 -0
  146. package/js/i18n/locales/bn.js +19 -0
  147. package/js/i18n/locales/br.js +18 -0
  148. package/js/i18n/locales/bs.js +15 -0
  149. package/js/i18n/locales/ca.js +18 -0
  150. package/js/i18n/locales/cs.js +19 -0
  151. package/js/i18n/locales/cy.js +14 -0
  152. package/js/i18n/locales/da.js +19 -0
  153. package/js/i18n/locales/de.js +18 -0
  154. package/js/i18n/locales/el.js +16 -0
  155. package/js/i18n/locales/en-AU.js +18 -0
  156. package/js/i18n/locales/en-CA.js +18 -0
  157. package/js/i18n/locales/en-GB.js +18 -0
  158. package/js/i18n/locales/en-IE.js +17 -0
  159. package/js/i18n/locales/en-NZ.js +17 -0
  160. package/js/i18n/locales/en-ZA.js +17 -0
  161. package/js/i18n/locales/eo.js +17 -0
  162. package/js/i18n/locales/es.js +18 -0
  163. package/js/i18n/locales/et.js +18 -0
  164. package/js/i18n/locales/eu.js +18 -0
  165. package/js/i18n/locales/fa.js +17 -0
  166. package/js/i18n/locales/fi.js +17 -0
  167. package/js/i18n/locales/fo.js +15 -0
  168. package/js/i18n/locales/fr-CH.js +21 -0
  169. package/js/i18n/locales/fr.js +18 -0
  170. package/js/i18n/locales/gl.js +16 -0
  171. package/js/i18n/locales/he.js +15 -0
  172. package/js/i18n/locales/hi.js +18 -0
  173. package/js/i18n/locales/hr.js +13 -0
  174. package/js/i18n/locales/hu.js +18 -0
  175. package/js/i18n/locales/hy.js +18 -0
  176. package/js/i18n/locales/id.js +15 -0
  177. package/js/i18n/locales/is.js +14 -0
  178. package/js/i18n/locales/it-CH.js +20 -0
  179. package/js/i18n/locales/it.js +18 -0
  180. package/js/i18n/locales/ja.js +17 -0
  181. package/js/i18n/locales/ka.js +17 -0
  182. package/js/i18n/locales/kk.js +15 -0
  183. package/js/i18n/locales/km.js +15 -0
  184. package/js/i18n/locales/ko.js +18 -0
  185. package/js/i18n/locales/lt.js +19 -0
  186. package/js/i18n/locales/lv.js +18 -0
  187. package/js/i18n/locales/me.js +17 -0
  188. package/js/i18n/locales/mk.js +15 -0
  189. package/js/i18n/locales/mn.js +17 -0
  190. package/js/i18n/locales/mr.js +18 -0
  191. package/js/i18n/locales/ms.js +15 -0
  192. package/js/i18n/locales/nl-BE.js +18 -0
  193. package/js/i18n/locales/nl.js +18 -0
  194. package/js/i18n/locales/no.js +18 -0
  195. package/js/i18n/locales/oc.js +17 -0
  196. package/js/i18n/locales/pl.js +17 -0
  197. package/js/i18n/locales/pt-BR.js +17 -0
  198. package/js/i18n/locales/pt.js +18 -0
  199. package/js/i18n/locales/ro.js +17 -0
  200. package/js/i18n/locales/ru.js +18 -0
  201. package/js/i18n/locales/si.js +18 -0
  202. package/js/i18n/locales/sk.js +18 -0
  203. package/js/i18n/locales/sl.js +15 -0
  204. package/js/i18n/locales/sq.js +18 -0
  205. package/js/i18n/locales/sr-latn.js +16 -0
  206. package/js/i18n/locales/sr.js +16 -0
  207. package/js/i18n/locales/sv.js +17 -0
  208. package/js/i18n/locales/sw.js +15 -0
  209. package/js/i18n/locales/ta.js +18 -0
  210. package/js/i18n/locales/tg.js +19 -0
  211. package/js/i18n/locales/th.js +14 -0
  212. package/js/i18n/locales/tk.js +18 -0
  213. package/js/i18n/locales/tr.js +17 -0
  214. package/js/i18n/locales/uk.js +17 -0
  215. package/js/i18n/locales/uz-cyrl.js +18 -0
  216. package/js/i18n/locales/uz-latn.js +18 -0
  217. package/js/i18n/locales/vi.js +16 -0
  218. package/js/i18n/locales/zh-CN.js +19 -0
  219. package/js/i18n/locales/zh-TW.js +18 -0
  220. package/js/lib/date-format.js +185 -0
  221. package/js/lib/date.js +82 -0
  222. package/js/lib/dom.js +55 -0
  223. package/js/lib/event.js +68 -0
  224. package/js/lib/utils.js +61 -0
  225. package/js/main.js +4 -0
  226. package/js/options/defaultOptions.js +38 -0
  227. package/js/options/processOptions.js +263 -0
  228. package/js/picker/Picker.js +334 -0
  229. package/js/picker/templates/calendarWeeksTemplate.js +8 -0
  230. package/js/picker/templates/daysTemplate.js +8 -0
  231. package/js/picker/templates/pickerTemplate.js +23 -0
  232. package/js/picker/views/DaysView.js +250 -0
  233. package/js/picker/views/MonthsView.js +198 -0
  234. package/js/picker/views/View.js +55 -0
  235. package/js/picker/views/YearsView.js +170 -0
  236. package/package.json +81 -0
  237. package/postcss.config.js +5 -0
  238. package/rollup.config.js +75 -0
  239. package/sass/_mixins.scss +12 -0
  240. package/sass/datepicker-bs4.scss +91 -0
  241. package/sass/datepicker-bs5.scss +91 -0
  242. package/sass/datepicker-bulma.scss +69 -0
  243. package/sass/datepicker-foundation.scss +66 -0
  244. package/sass/datepicker.scss +436 -0
  245. package/sass/index-bs4.scss +5 -0
  246. package/sass/index-bs5.scss +5 -0
  247. package/sass/index-bulma.scss +6 -0
  248. package/sass/index-foundation.scss +3 -0
  249. package/scripts/build-css.js +39 -0
  250. package/scripts/build-locales.js +57 -0
  251. package/scripts/convert-bsdp-locales.js +65 -0
  252. package/scripts/minify-css.js +31 -0
  253. package/scripts/minify-js.js +17 -0
  254. package/style.css +10 -0
  255. package/tailwind.config.js +16 -0
  256. package/tailwind.css +1389 -0
  257. package/test/DateRangePicker/DateRangePicker.js +547 -0
  258. package/test/DateRangePicker/api-methods.js +415 -0
  259. package/test/DateRangePicker/date-selection.js +472 -0
  260. package/test/DateRangePicker/options.js +308 -0
  261. package/test/Datepicker/Datepicker-object.js +236 -0
  262. package/test/Datepicker/api-methods.js +328 -0
  263. package/test/_utils/date.js +102 -0
  264. package/test/_utils/dom.js +70 -0
  265. package/test/events.js +785 -0
  266. package/test/inline-mode.js +45 -0
  267. package/test/keyboard-operation/arrow-down.js +293 -0
  268. package/test/keyboard-operation/arrow-left.js +255 -0
  269. package/test/keyboard-operation/arrow-right.js +215 -0
  270. package/test/keyboard-operation/arrow-up.js +461 -0
  271. package/test/keyboard-operation/edit-mode.js +458 -0
  272. package/test/keyboard-operation/keyboard-operation.js +146 -0
  273. package/test/mouse-operation.js +580 -0
  274. package/test/options/before-show.js +635 -0
  275. package/test/options/bulma-datepicker.sublime-workspace +1280 -0
  276. package/test/options/buttons.js +383 -0
  277. package/test/options/date-restrictions.js +802 -0
  278. package/test/options/format.js +281 -0
  279. package/test/options/multidate.js +380 -0
  280. package/test/options/options.js +727 -0
  281. package/test/options/orientation.js +410 -0
  282. package/test/options/pick-levle+view.js +357 -0
  283. package/test/test.html +94 -0
  284. package/test/unit/DateRangePicker.js +192 -0
  285. package/test/unit/Datepicker.js +307 -0
  286. package/test/unit/_setup.js +28 -0
  287. package/test/unit/lib/date-format.js +310 -0
  288. package/test/unit/lib/date.js +211 -0
  289. package/test/unit/lib/dom.js +142 -0
  290. package/test/unit/lib/event.js +207 -0
  291. package/test/unit/lib/utils.js +135 -0
@@ -0,0 +1,58 @@
1
+ import {twoDigitToFullYear} from '../twoDigitToFullYear.js';
2
+
3
+ const expect = require('unexpected');
4
+ const sinon = require('sinon');
5
+
6
+ describe('twoDigitToFullYear()', function () {
7
+ it('converts 2-digit year to full year using 50 for the future years range by default', function () {
8
+ let clock = sinon.useFakeTimers({now: new Date().setFullYear(2020)});
9
+
10
+ expect(twoDigitToFullYear(0), 'to be', 2000);
11
+ expect(twoDigitToFullYear(20), 'to be', 2020);
12
+ expect(twoDigitToFullYear(70), 'to be', 2070);
13
+ expect(twoDigitToFullYear(71), 'to be', 1971);
14
+
15
+ clock.restore();
16
+ clock = sinon.useFakeTimers({now: new Date().setFullYear(2080)});
17
+
18
+ expect(twoDigitToFullYear(0), 'to be', 2100);
19
+ expect(twoDigitToFullYear(30), 'to be', 2130);
20
+ expect(twoDigitToFullYear(31), 'to be', 2031);
21
+ expect(twoDigitToFullYear(80), 'to be', 2080);
22
+
23
+ clock.restore();
24
+ });
25
+
26
+ it('uses sepecified future year range if it is given', function () {
27
+ let clock = sinon.useFakeTimers({now: new Date().setFullYear(2020)});
28
+
29
+ expect(twoDigitToFullYear(40, 20), 'to be', 2040);
30
+ expect(twoDigitToFullYear(40, 19), 'to be', 1940);
31
+ expect(twoDigitToFullYear(95, 75), 'to be', 2095);
32
+ expect(twoDigitToFullYear(95, 74), 'to be', 1995);
33
+
34
+ clock.restore();
35
+ clock = sinon.useFakeTimers({now: new Date().setFullYear(2080)});
36
+
37
+ expect(twoDigitToFullYear(0, 20), 'to be', 2100);
38
+ expect(twoDigitToFullYear(0, 19), 'to be', 2000);
39
+ expect(twoDigitToFullYear(55, 75), 'to be', 2155);
40
+ expect(twoDigitToFullYear(55, 74), 'to be', 2055);
41
+
42
+ clock.restore();
43
+ });
44
+
45
+ it('uses the century of baseDate for conversion if it is given', function () {
46
+ const year2020 = new Date(2020, 0, 1);
47
+ expect(twoDigitToFullYear(40, 20, year2020), 'to be', 2040);
48
+ expect(twoDigitToFullYear(40, 19, year2020), 'to be', 1940);
49
+ expect(twoDigitToFullYear(95, 75, year2020), 'to be', 2095);
50
+ expect(twoDigitToFullYear(95, 74, year2020), 'to be', 1995);
51
+
52
+ const year2280 = new Date(2280, 0, 1);
53
+ expect(twoDigitToFullYear(0, 20, year2280), 'to be', 2300);
54
+ expect(twoDigitToFullYear(0, 19, year2280), 'to be', 2200);
55
+ expect(twoDigitToFullYear(55, 75, year2280), 'to be', 2355);
56
+ expect(twoDigitToFullYear(55, 74, year2280), 'to be', 2255);
57
+ });
58
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Convert 2-digit year to 4-digit year
3
+ * By default, 2-digit year will be converted to a year in the 100-year
4
+ * period ending 50 years after the current year. The target 100-year period
5
+ * can be changed by specifying base date and the length of the future side.
6
+ * @param {Number} year - 2-digit year
7
+ * @param {Number} [futureSideSpan] - number of yeas in the future side of
8
+ * the target 100-year period. Default: 50
9
+ * @param {Date} [baseDate] - base date to caliculate the target 100-year
10
+ * period. if omitted, the current date is used.
11
+ * @return {Number} 4-digit year
12
+ */
13
+ export function twoDigitToFullYear(year, futureSideSpan = 50, baseDate = undefined) {
14
+ if (isNaN(year) || year > 99 || year < 0) {
15
+ return year;
16
+ }
17
+
18
+ const date = baseDate instanceof Date && !isNaN(baseDate) ? baseDate : new Date();
19
+ const currentYear = date.getFullYear();
20
+ const endOfCurrent = currentYear + futureSideSpan;
21
+ let century = Math.floor(endOfCurrent / 100) * 100;
22
+ if (year > endOfCurrent % 100) {
23
+ century -= 100;
24
+ }
25
+ return year + century;
26
+ }
@@ -0,0 +1,210 @@
1
+ import {registerListeners, unregisterListeners} from './lib/event.js';
2
+ import {formatDate} from './lib/date-format.js';
3
+ import Datepicker from './Datepicker.js';
4
+
5
+ // filter out the config options inapproprite to pass to Datepicker
6
+ function filterOptions(options) {
7
+ const newOpts = Object.assign({}, options);
8
+
9
+ delete newOpts.inputs;
10
+ delete newOpts.allowOneSidedRange;
11
+ delete newOpts.maxNumberOfDates; // to ensure each datepicker handles a single date
12
+
13
+ return newOpts;
14
+ }
15
+
16
+ function setupDatepicker(rangepicker, changeDateListener, el, options) {
17
+ registerListeners(rangepicker, [
18
+ [el, 'changeDate', changeDateListener],
19
+ ]);
20
+ new Datepicker(el, options, rangepicker);
21
+ }
22
+
23
+ function onChangeDate(rangepicker, ev) {
24
+ // to prevent both datepickers trigger the other side's update each other
25
+ if (rangepicker._updating) {
26
+ return;
27
+ }
28
+ rangepicker._updating = true;
29
+
30
+ const target = ev.target;
31
+ if (target.datepicker === undefined) {
32
+ return;
33
+ }
34
+
35
+ const datepickers = rangepicker.datepickers;
36
+ const setDateOptions = {render: false};
37
+ const changedSide = rangepicker.inputs.indexOf(target);
38
+ const otherSide = changedSide === 0 ? 1 : 0;
39
+ const changedDate = datepickers[changedSide].dates[0];
40
+ const otherDate = datepickers[otherSide].dates[0];
41
+
42
+ if (changedDate !== undefined && otherDate !== undefined) {
43
+ // if the start of the range > the end, swap them
44
+ if (changedSide === 0 && changedDate > otherDate) {
45
+ datepickers[0].setDate(otherDate, setDateOptions);
46
+ datepickers[1].setDate(changedDate, setDateOptions);
47
+ } else if (changedSide === 1 && changedDate < otherDate) {
48
+ datepickers[0].setDate(changedDate, setDateOptions);
49
+ datepickers[1].setDate(otherDate, setDateOptions);
50
+ }
51
+ } else if (!rangepicker.allowOneSidedRange) {
52
+ // to prevent the range from becoming one-sided, copy changed side's
53
+ // selection (no matter if it's empty) to the other side
54
+ if (changedDate !== undefined || otherDate !== undefined) {
55
+ setDateOptions.clear = true;
56
+ datepickers[otherSide].setDate(datepickers[changedSide].dates, setDateOptions);
57
+ }
58
+ }
59
+ datepickers[0].picker.update().render();
60
+ datepickers[1].picker.update().render();
61
+ delete rangepicker._updating;
62
+ }
63
+
64
+ /**
65
+ * Class representing a date range picker
66
+ */
67
+ export default class DateRangePicker {
68
+ /**
69
+ * Create a date range picker
70
+ * @param {Element} element - element to bind a date range picker
71
+ * @param {Object} [options] - config options
72
+ */
73
+ constructor(element, options = {}) {
74
+ const inputs = Array.isArray(options.inputs)
75
+ ? options.inputs
76
+ : Array.from(element.querySelectorAll('input'));
77
+ if (inputs.length < 2) {
78
+ return;
79
+ }
80
+
81
+ element.rangepicker = this;
82
+ this.element = element;
83
+ this.inputs = inputs.slice(0, 2);
84
+ this.allowOneSidedRange = !!options.allowOneSidedRange;
85
+
86
+ const changeDateListener = onChangeDate.bind(null, this);
87
+ const cleanOptions = filterOptions(options);
88
+ // in order for initial date setup to work right when pcicLvel > 0,
89
+ // let Datepicker constructor add the instance to the rangepicker
90
+ const datepickers = [];
91
+ Object.defineProperty(this, 'datepickers', {
92
+ get() {
93
+ return datepickers;
94
+ },
95
+ });
96
+ setupDatepicker(this, changeDateListener, this.inputs[0], cleanOptions);
97
+ setupDatepicker(this, changeDateListener, this.inputs[1], cleanOptions);
98
+ Object.freeze(datepickers);
99
+ // normalize the range if inital dates are given
100
+ if (datepickers[0].dates.length > 0) {
101
+ onChangeDate(this, {target: this.inputs[0]});
102
+ } else if (datepickers[1].dates.length > 0) {
103
+ onChangeDate(this, {target: this.inputs[1]});
104
+ }
105
+ }
106
+
107
+ /**
108
+ * @type {Array} - selected date of the linked date pickers
109
+ */
110
+ get dates() {
111
+ return this.datepickers.length === 2
112
+ ? [
113
+ this.datepickers[0].dates[0],
114
+ this.datepickers[1].dates[0],
115
+ ]
116
+ : undefined;
117
+ }
118
+
119
+ /**
120
+ * Set new values to the config options
121
+ * @param {Object} options - config options to update
122
+ */
123
+ setOptions(options) {
124
+ this.allowOneSidedRange = !!options.allowOneSidedRange;
125
+
126
+ const cleanOptions = filterOptions(options);
127
+ this.datepickers[0].setOptions(cleanOptions);
128
+ this.datepickers[1].setOptions(cleanOptions);
129
+ }
130
+
131
+ /**
132
+ * Destroy the DateRangePicker instance
133
+ * @return {DateRangePicker} - the instance destroyed
134
+ */
135
+ destroy() {
136
+ this.datepickers[0].destroy();
137
+ this.datepickers[1].destroy();
138
+ unregisterListeners(this);
139
+ delete this.element.rangepicker;
140
+ }
141
+
142
+ /**
143
+ * Get the start and end dates of the date range
144
+ *
145
+ * The method returns Date objects by default. If format string is passed,
146
+ * it returns date strings formatted in given format.
147
+ * The result array always contains 2 items (start date/end date) and
148
+ * undefined is used for unselected side. (e.g. If none is selected,
149
+ * the result will be [undefined, undefined]. If only the end date is set
150
+ * when allowOneSidedRange config option is true, [undefined, endDate] will
151
+ * be returned.)
152
+ *
153
+ * @param {String} [format] - Format string to stringify the dates
154
+ * @return {Array} - Start and end dates
155
+ */
156
+ getDates(format = undefined) {
157
+ const callback = format
158
+ ? date => formatDate(date, format, this.datepickers[0].config.locale)
159
+ : date => new Date(date);
160
+
161
+ return this.dates.map(date => date === undefined ? date : callback(date));
162
+ }
163
+
164
+ /**
165
+ * Set the start and end dates of the date range
166
+ *
167
+ * The method calls datepicker.setDate() internally using each of the
168
+ * arguments in start→end order.
169
+ *
170
+ * When a clear: true option object is passed instead of a date, the method
171
+ * clears the date.
172
+ *
173
+ * If an invalid date, the same date as the current one or an option object
174
+ * without clear: true is passed, the method considers that argument as an
175
+ * "ineffective" argument because calling datepicker.setDate() with those
176
+ * values makes no changes to the date selection.
177
+ *
178
+ * When the allowOneSidedRange config option is false, passing {clear: true}
179
+ * to clear the range works only when it is done to the last effective
180
+ * argument (in other words, passed to rangeEnd or to rangeStart along with
181
+ * ineffective rangeEnd). This is because when the date range is changed,
182
+ * it gets normalized based on the last change at the end of the changing
183
+ * process.
184
+ *
185
+ * @param {Date|Number|String|Object} rangeStart - Start date of the range
186
+ * or {clear: true} to clear the date
187
+ * @param {Date|Number|String|Object} rangeEnd - End date of the range
188
+ * or {clear: true} to clear the date
189
+ */
190
+ setDates(rangeStart, rangeEnd) {
191
+ const [datepicker0, datepicker1] = this.datepickers;
192
+ const origDates = this.dates;
193
+
194
+ // If range normalization runs on every change, we can't set a new range
195
+ // that starts after the end of the current range correctly because the
196
+ // normalization process swaps start↔︎end right after setting the new start
197
+ // date. To prevent this, the normalization process needs to run once after
198
+ // both of the new dates are set.
199
+ this._updating = true;
200
+ datepicker0.setDate(rangeStart);
201
+ datepicker1.setDate(rangeEnd);
202
+ delete this._updating;
203
+
204
+ if (datepicker1.dates[0] !== origDates[1]) {
205
+ onChangeDate(this, {target: this.inputs[1]});
206
+ } else if (datepicker0.dates[0] !== origDates[0]) {
207
+ onChangeDate(this, {target: this.inputs[0]});
208
+ }
209
+ }
210
+ }