@xplortech/apollo-core 0.5.2 → 0.5.3

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 (173) hide show
  1. package/dist/apollo-core/apollo-core.css +5468 -9
  2. package/dist/apollo-core/apollo-core.esm.js +125 -1
  3. package/dist/apollo-core/app-globals-0f993ce5.js +3 -0
  4. package/dist/apollo-core/css-shim-bbdf0cc6.js +4 -0
  5. package/dist/apollo-core/dom-1f98a75f.js +73 -0
  6. package/dist/apollo-core/index-3c9f25ef.js +2938 -0
  7. package/dist/apollo-core/index-912d1a21.js +584 -0
  8. package/dist/apollo-core/index.esm.js +1 -0
  9. package/dist/{cjs/regular-872f5226.js → apollo-core/regular-133c23b5.js} +12 -3
  10. package/dist/apollo-core/shadow-css-67b66845.js +389 -0
  11. package/dist/apollo-core/xpl-application-shell.entry.js +50 -0
  12. package/dist/apollo-core/xpl-avatar.entry.js +19 -0
  13. package/dist/apollo-core/xpl-backdrop.entry.js +21 -0
  14. package/dist/{esm → apollo-core}/xpl-badge.entry.js +1 -1
  15. package/dist/{collection/components/xpl-breadcrumbs/xpl-breadcrumb-item/xpl-breadcrumb-item.js → apollo-core/xpl-breadcrumb-item.entry.js} +9 -12
  16. package/dist/apollo-core/xpl-breadcrumbs.entry.js +14 -0
  17. package/dist/{esm → apollo-core}/xpl-button-row.entry.js +1 -1
  18. package/dist/apollo-core/xpl-button.entry.js +34 -0
  19. package/dist/apollo-core/xpl-checkbox.entry.js +25 -0
  20. package/dist/{esm → apollo-core}/xpl-choicelist.entry.js +1 -1
  21. package/dist/apollo-core/xpl-content-area.entry.js +16 -0
  22. package/dist/{esm → apollo-core}/xpl-divider.entry.js +1 -1
  23. package/dist/{esm → apollo-core}/xpl-grid-item.entry.js +1 -1
  24. package/dist/{esm → apollo-core}/xpl-grid.entry.js +1 -1
  25. package/dist/{esm → apollo-core}/xpl-input.entry.js +20 -3
  26. package/dist/{esm → apollo-core}/xpl-list.entry.js +2 -2
  27. package/dist/apollo-core/xpl-main-nav.entry.js +26 -0
  28. package/dist/apollo-core/xpl-nav-item.entry.js +12 -0
  29. package/dist/{esm → apollo-core}/xpl-pagination.entry.js +1 -1
  30. package/dist/apollo-core/xpl-radio.entry.js +25 -0
  31. package/dist/apollo-core/xpl-secondary-nav.entry.js +12 -0
  32. package/dist/{esm → apollo-core}/xpl-select.entry.js +43 -3
  33. package/dist/{esm → apollo-core}/xpl-table.entry.js +1 -1
  34. package/dist/{esm → apollo-core}/xpl-tag.entry.js +1 -1
  35. package/dist/{esm → apollo-core}/xpl-toggle.entry.js +2 -2
  36. package/dist/apollo-core/xpl-utility-bar.entry.js +25 -0
  37. package/dist/types/components/xpl-choicelist/choice.d.ts +1 -1
  38. package/dist/types/components/xpl-choicelist/xpl-choicelist.d.ts +1 -0
  39. package/dist/types/components/xpl-dropdown/dropdownchoice.d.ts +5 -5
  40. package/dist/types/components/xpl-dropdown/xpl-dropdown.d.ts +1 -0
  41. package/dist/types/components/xpl-list/listitem.d.ts +15 -15
  42. package/dist/types/components/xpl-list/xpl-list.d.ts +1 -0
  43. package/dist/types/components/xpl-select/xpl-select.d.ts +1 -0
  44. package/dist/types/components.d.ts +3 -0
  45. package/package.json +1 -1
  46. package/dist/apollo-core/p-0203d4e8.entry.js +0 -1
  47. package/dist/apollo-core/p-0b2c612e.entry.js +0 -1
  48. package/dist/apollo-core/p-128a0240.entry.js +0 -1
  49. package/dist/apollo-core/p-2f90296c.js +0 -10
  50. package/dist/apollo-core/p-30003b15.entry.js +0 -1
  51. package/dist/apollo-core/p-4e56a2ca.entry.js +0 -1
  52. package/dist/apollo-core/p-5854d1e4.entry.js +0 -1
  53. package/dist/apollo-core/p-611536d8.entry.js +0 -1
  54. package/dist/apollo-core/p-7c9fee7e.entry.js +0 -1
  55. package/dist/apollo-core/p-8b6633c7.js +0 -1
  56. package/dist/apollo-core/p-97cd1f73.entry.js +0 -1
  57. package/dist/apollo-core/p-9c5ca308.entry.js +0 -1
  58. package/dist/apollo-core/p-ad90fe4d.js +0 -1
  59. package/dist/apollo-core/p-bd4a7e3c.entry.js +0 -1
  60. package/dist/apollo-core/p-dab8e7a1.entry.js +0 -1
  61. package/dist/apollo-core/p-eb63b401.entry.js +0 -1
  62. package/dist/apollo-core/p-ee2f4422.entry.js +0 -1
  63. package/dist/apollo-core/p-f167aa05.entry.js +0 -1
  64. package/dist/cjs/apollo-core.cjs.js +0 -19
  65. package/dist/cjs/index-944adb2e.js +0 -1609
  66. package/dist/cjs/index.cjs.js +0 -2
  67. package/dist/cjs/loader.cjs.js +0 -21
  68. package/dist/cjs/v4-14140ff3.js +0 -77
  69. package/dist/cjs/xpl-application-shell_11.cjs.entry.js +0 -230
  70. package/dist/cjs/xpl-badge.cjs.entry.js +0 -21
  71. package/dist/cjs/xpl-button-row.cjs.entry.js +0 -24
  72. package/dist/cjs/xpl-checkbox_2.cjs.entry.js +0 -51
  73. package/dist/cjs/xpl-choicelist.cjs.entry.js +0 -36
  74. package/dist/cjs/xpl-divider.cjs.entry.js +0 -18
  75. package/dist/cjs/xpl-grid-item.cjs.entry.js +0 -25
  76. package/dist/cjs/xpl-grid.cjs.entry.js +0 -35
  77. package/dist/cjs/xpl-input.cjs.entry.js +0 -2527
  78. package/dist/cjs/xpl-list.cjs.entry.js +0 -63
  79. package/dist/cjs/xpl-pagination.cjs.entry.js +0 -76
  80. package/dist/cjs/xpl-select.cjs.entry.js +0 -623
  81. package/dist/cjs/xpl-table.cjs.entry.js +0 -89
  82. package/dist/cjs/xpl-tag.cjs.entry.js +0 -21
  83. package/dist/cjs/xpl-toggle.cjs.entry.js +0 -34
  84. package/dist/collection/collection-manifest.json +0 -37
  85. package/dist/collection/components/xpl-application-shell/xpl-application-shell.js +0 -143
  86. package/dist/collection/components/xpl-avatar/xpl-avatar.js +0 -158
  87. package/dist/collection/components/xpl-backdrop/xpl-backdrop.js +0 -41
  88. package/dist/collection/components/xpl-badge/xpl-badge.js +0 -50
  89. package/dist/collection/components/xpl-breadcrumbs/xpl-breadcrumbs/xpl-breadcrumbs.js +0 -15
  90. package/dist/collection/components/xpl-button/xpl-button.js +0 -214
  91. package/dist/collection/components/xpl-button-row/xpl-button-row.js +0 -119
  92. package/dist/collection/components/xpl-checkbox/xpl-checkbox.js +0 -185
  93. package/dist/collection/components/xpl-choicelist/xpl-choicelist.js +0 -143
  94. package/dist/collection/components/xpl-content-area/xpl-content-area.js +0 -39
  95. package/dist/collection/components/xpl-divider/xpl-divider.js +0 -30
  96. package/dist/collection/components/xpl-dropdown/xpl-dropdown.js +0 -32
  97. package/dist/collection/components/xpl-grid/xpl-grid.js +0 -26
  98. package/dist/collection/components/xpl-grid-item/xpl-grid-item.js +0 -93
  99. package/dist/collection/components/xpl-input/xpl-input.js +0 -471
  100. package/dist/collection/components/xpl-list/xpl-list.js +0 -93
  101. package/dist/collection/components/xpl-main-nav/xpl-main-nav.js +0 -72
  102. package/dist/collection/components/xpl-nav-item/xpl-nav-item.js +0 -10
  103. package/dist/collection/components/xpl-pagination/xpl-pagination.js +0 -189
  104. package/dist/collection/components/xpl-radio/xpl-radio.js +0 -168
  105. package/dist/collection/components/xpl-secondary-nav/xpl-secondary-nav.js +0 -9
  106. package/dist/collection/components/xpl-select/xpl-select.js +0 -311
  107. package/dist/collection/components/xpl-table/xpl-table.js +0 -194
  108. package/dist/collection/components/xpl-tag/xpl-tag.js +0 -30
  109. package/dist/collection/components/xpl-toggle/xpl-toggle.js +0 -157
  110. package/dist/collection/components/xpl-utility-bar/xpl-utility-bar.js +0 -70
  111. package/dist/custom-elements/index.js +0 -19959
  112. package/dist/esm/apollo-core.js +0 -17
  113. package/dist/esm/index-899dba3b.js +0 -1580
  114. package/dist/esm/index.js +0 -1
  115. package/dist/esm/loader.js +0 -17
  116. package/dist/esm/polyfills/core-js.js +0 -11
  117. package/dist/esm/polyfills/css-shim.js +0 -1
  118. package/dist/esm/polyfills/dom.js +0 -79
  119. package/dist/esm/polyfills/es5-html-element.js +0 -1
  120. package/dist/esm/polyfills/index.js +0 -34
  121. package/dist/esm/polyfills/system.js +0 -6
  122. package/dist/esm/regular-86225e9d.js +0 -16041
  123. package/dist/esm/v4-929670b7.js +0 -75
  124. package/dist/esm/xpl-application-shell_11.entry.js +0 -216
  125. package/dist/esm/xpl-checkbox_2.entry.js +0 -46
  126. package/dist/index.cjs.js +0 -1
  127. package/dist/index.js +0 -1
  128. package/dist/stories/application-shell.stories.js +0 -766
  129. package/dist/stories/avatar.stories.js +0 -173
  130. package/dist/stories/backdrop.stories.js +0 -18
  131. package/dist/stories/badge.stories.js +0 -48
  132. package/dist/stories/breadcrumbs.stories.js +0 -115
  133. package/dist/stories/button-row.stories.js +0 -64
  134. package/dist/stories/button.stories.js +0 -98
  135. package/dist/stories/checkbox.stories.js +0 -76
  136. package/dist/stories/choicelist.stories.js +0 -112
  137. package/dist/stories/content-area.stories.js +0 -53
  138. package/dist/stories/divider.stories.js +0 -34
  139. package/dist/stories/grid.stories.js +0 -100
  140. package/dist/stories/input.stories.js +0 -252
  141. package/dist/stories/list.stories.js +0 -134
  142. package/dist/stories/main-nav.stories.js +0 -308
  143. package/dist/stories/pagination.stories.js +0 -84
  144. package/dist/stories/radio.stories.js +0 -66
  145. package/dist/stories/secondary-nav.stories.js +0 -76
  146. package/dist/stories/select.stories.js +0 -111
  147. package/dist/stories/table.stories.js +0 -107
  148. package/dist/stories/tabs.stories.js +0 -24
  149. package/dist/stories/toggle.stories.js +0 -80
  150. package/dist/stories/utility-bar.stories.js +0 -94
  151. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/application-shell.stories.d.ts +0 -0
  152. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/avatar.stories.d.ts +0 -0
  153. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/backdrop.stories.d.ts +0 -0
  154. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/badge.stories.d.ts +0 -0
  155. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/breadcrumbs.stories.d.ts +0 -0
  156. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/button-row.stories.d.ts +0 -0
  157. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/button.stories.d.ts +0 -0
  158. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/checkbox.stories.d.ts +0 -0
  159. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/choicelist.stories.d.ts +0 -0
  160. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/content-area.stories.d.ts +0 -0
  161. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/divider.stories.d.ts +0 -0
  162. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/grid.stories.d.ts +0 -0
  163. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/input.stories.d.ts +0 -0
  164. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/list.stories.d.ts +0 -0
  165. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/main-nav.stories.d.ts +0 -0
  166. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/pagination.stories.d.ts +0 -0
  167. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/radio.stories.d.ts +0 -0
  168. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/secondary-nav.stories.d.ts +0 -0
  169. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/select.stories.d.ts +0 -0
  170. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/table.stories.d.ts +0 -0
  171. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/tabs.stories.d.ts +0 -0
  172. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/toggle.stories.d.ts +0 -0
  173. /package/dist/types/Users/{fernandogelin/Projects → roc/Sites}/apollo/.stencil/stories/utility-bar.stories.d.ts +0 -0
@@ -1,2527 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const index = require('./index-944adb2e.js');
6
- require('./regular-872f5226.js');
7
- const v4 = require('./v4-14140ff3.js');
8
-
9
- const HOOKS = [
10
- "onChange",
11
- "onClose",
12
- "onDayCreate",
13
- "onDestroy",
14
- "onKeyDown",
15
- "onMonthChange",
16
- "onOpen",
17
- "onParseConfig",
18
- "onReady",
19
- "onValueUpdate",
20
- "onYearChange",
21
- "onPreCalendarPosition",
22
- ];
23
- const defaults = {
24
- _disable: [],
25
- allowInput: false,
26
- allowInvalidPreload: false,
27
- altFormat: "F j, Y",
28
- altInput: false,
29
- altInputClass: "form-control input",
30
- animate: typeof window === "object" &&
31
- window.navigator.userAgent.indexOf("MSIE") === -1,
32
- ariaDateFormat: "F j, Y",
33
- autoFillDefaultTime: true,
34
- clickOpens: true,
35
- closeOnSelect: true,
36
- conjunction: ", ",
37
- dateFormat: "Y-m-d",
38
- defaultHour: 12,
39
- defaultMinute: 0,
40
- defaultSeconds: 0,
41
- disable: [],
42
- disableMobile: false,
43
- enableSeconds: false,
44
- enableTime: false,
45
- errorHandler: (err) => typeof console !== "undefined" && console.warn(err),
46
- getWeek: (givenDate) => {
47
- const date = new Date(givenDate.getTime());
48
- date.setHours(0, 0, 0, 0);
49
- date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7));
50
- var week1 = new Date(date.getFullYear(), 0, 4);
51
- return (1 +
52
- Math.round(((date.getTime() - week1.getTime()) / 86400000 -
53
- 3 +
54
- ((week1.getDay() + 6) % 7)) /
55
- 7));
56
- },
57
- hourIncrement: 1,
58
- ignoredFocusElements: [],
59
- inline: false,
60
- locale: "default",
61
- minuteIncrement: 5,
62
- mode: "single",
63
- monthSelectorType: "dropdown",
64
- nextArrow: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M13.207 8.472l-7.854 7.854-0.707-0.707 7.146-7.146-7.146-7.148 0.707-0.707 7.854 7.854z' /></svg>",
65
- noCalendar: false,
66
- now: new Date(),
67
- onChange: [],
68
- onClose: [],
69
- onDayCreate: [],
70
- onDestroy: [],
71
- onKeyDown: [],
72
- onMonthChange: [],
73
- onOpen: [],
74
- onParseConfig: [],
75
- onReady: [],
76
- onValueUpdate: [],
77
- onYearChange: [],
78
- onPreCalendarPosition: [],
79
- plugins: [],
80
- position: "auto",
81
- positionElement: undefined,
82
- prevArrow: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M5.207 8.471l7.146 7.147-0.707 0.707-7.853-7.854 7.854-7.853 0.707 0.707-7.147 7.146z' /></svg>",
83
- shorthandCurrentMonth: false,
84
- showMonths: 1,
85
- static: false,
86
- time_24hr: false,
87
- weekNumbers: false,
88
- wrap: false,
89
- };
90
-
91
- const english = {
92
- weekdays: {
93
- shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
94
- longhand: [
95
- "Sunday",
96
- "Monday",
97
- "Tuesday",
98
- "Wednesday",
99
- "Thursday",
100
- "Friday",
101
- "Saturday",
102
- ],
103
- },
104
- months: {
105
- shorthand: [
106
- "Jan",
107
- "Feb",
108
- "Mar",
109
- "Apr",
110
- "May",
111
- "Jun",
112
- "Jul",
113
- "Aug",
114
- "Sep",
115
- "Oct",
116
- "Nov",
117
- "Dec",
118
- ],
119
- longhand: [
120
- "January",
121
- "February",
122
- "March",
123
- "April",
124
- "May",
125
- "June",
126
- "July",
127
- "August",
128
- "September",
129
- "October",
130
- "November",
131
- "December",
132
- ],
133
- },
134
- daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
135
- firstDayOfWeek: 0,
136
- ordinal: (nth) => {
137
- const s = nth % 100;
138
- if (s > 3 && s < 21)
139
- return "th";
140
- switch (s % 10) {
141
- case 1:
142
- return "st";
143
- case 2:
144
- return "nd";
145
- case 3:
146
- return "rd";
147
- default:
148
- return "th";
149
- }
150
- },
151
- rangeSeparator: " to ",
152
- weekAbbreviation: "Wk",
153
- scrollTitle: "Scroll to increment",
154
- toggleTitle: "Click to toggle",
155
- amPM: ["AM", "PM"],
156
- yearAriaLabel: "Year",
157
- monthAriaLabel: "Month",
158
- hourAriaLabel: "Hour",
159
- minuteAriaLabel: "Minute",
160
- time_24hr: false,
161
- };
162
-
163
- const pad = (number, length = 2) => `000${number}`.slice(length * -1);
164
- const int = (bool) => (bool === true ? 1 : 0);
165
- function debounce(fn, wait) {
166
- let t;
167
- return function () {
168
- clearTimeout(t);
169
- t = setTimeout(() => fn.apply(this, arguments), wait);
170
- };
171
- }
172
- const arrayify = (obj) => obj instanceof Array ? obj : [obj];
173
-
174
- function toggleClass(elem, className, bool) {
175
- if (bool === true)
176
- return elem.classList.add(className);
177
- elem.classList.remove(className);
178
- }
179
- function createElement(tag, className, content) {
180
- const e = window.document.createElement(tag);
181
- className = className || "";
182
- content = content || "";
183
- e.className = className;
184
- if (content !== undefined)
185
- e.textContent = content;
186
- return e;
187
- }
188
- function clearNode(node) {
189
- while (node.firstChild)
190
- node.removeChild(node.firstChild);
191
- }
192
- function findParent(node, condition) {
193
- if (condition(node))
194
- return node;
195
- else if (node.parentNode)
196
- return findParent(node.parentNode, condition);
197
- return undefined;
198
- }
199
- function createNumberInput(inputClassName, opts) {
200
- const wrapper = createElement("div", "numInputWrapper"), numInput = createElement("input", "numInput " + inputClassName), arrowUp = createElement("span", "arrowUp"), arrowDown = createElement("span", "arrowDown");
201
- if (navigator.userAgent.indexOf("MSIE 9.0") === -1) {
202
- numInput.type = "number";
203
- }
204
- else {
205
- numInput.type = "text";
206
- numInput.pattern = "\\d*";
207
- }
208
- if (opts !== undefined)
209
- for (const key in opts)
210
- numInput.setAttribute(key, opts[key]);
211
- wrapper.appendChild(numInput);
212
- wrapper.appendChild(arrowUp);
213
- wrapper.appendChild(arrowDown);
214
- return wrapper;
215
- }
216
- function getEventTarget(event) {
217
- try {
218
- if (typeof event.composedPath === "function") {
219
- const path = event.composedPath();
220
- return path[0];
221
- }
222
- return event.target;
223
- }
224
- catch (error) {
225
- return event.target;
226
- }
227
- }
228
-
229
- const doNothing = () => undefined;
230
- const monthToStr = (monthNumber, shorthand, locale) => locale.months[shorthand ? "shorthand" : "longhand"][monthNumber];
231
- const revFormat = {
232
- D: doNothing,
233
- F: function (dateObj, monthName, locale) {
234
- dateObj.setMonth(locale.months.longhand.indexOf(monthName));
235
- },
236
- G: (dateObj, hour) => {
237
- dateObj.setHours(parseFloat(hour));
238
- },
239
- H: (dateObj, hour) => {
240
- dateObj.setHours(parseFloat(hour));
241
- },
242
- J: (dateObj, day) => {
243
- dateObj.setDate(parseFloat(day));
244
- },
245
- K: (dateObj, amPM, locale) => {
246
- dateObj.setHours((dateObj.getHours() % 12) +
247
- 12 * int(new RegExp(locale.amPM[1], "i").test(amPM)));
248
- },
249
- M: function (dateObj, shortMonth, locale) {
250
- dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth));
251
- },
252
- S: (dateObj, seconds) => {
253
- dateObj.setSeconds(parseFloat(seconds));
254
- },
255
- U: (_, unixSeconds) => new Date(parseFloat(unixSeconds) * 1000),
256
- W: function (dateObj, weekNum, locale) {
257
- const weekNumber = parseInt(weekNum);
258
- const date = new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0);
259
- date.setDate(date.getDate() - date.getDay() + locale.firstDayOfWeek);
260
- return date;
261
- },
262
- Y: (dateObj, year) => {
263
- dateObj.setFullYear(parseFloat(year));
264
- },
265
- Z: (_, ISODate) => new Date(ISODate),
266
- d: (dateObj, day) => {
267
- dateObj.setDate(parseFloat(day));
268
- },
269
- h: (dateObj, hour) => {
270
- dateObj.setHours(parseFloat(hour));
271
- },
272
- i: (dateObj, minutes) => {
273
- dateObj.setMinutes(parseFloat(minutes));
274
- },
275
- j: (dateObj, day) => {
276
- dateObj.setDate(parseFloat(day));
277
- },
278
- l: doNothing,
279
- m: (dateObj, month) => {
280
- dateObj.setMonth(parseFloat(month) - 1);
281
- },
282
- n: (dateObj, month) => {
283
- dateObj.setMonth(parseFloat(month) - 1);
284
- },
285
- s: (dateObj, seconds) => {
286
- dateObj.setSeconds(parseFloat(seconds));
287
- },
288
- u: (_, unixMillSeconds) => new Date(parseFloat(unixMillSeconds)),
289
- w: doNothing,
290
- y: (dateObj, year) => {
291
- dateObj.setFullYear(2000 + parseFloat(year));
292
- },
293
- };
294
- const tokenRegex = {
295
- D: "(\\w+)",
296
- F: "(\\w+)",
297
- G: "(\\d\\d|\\d)",
298
- H: "(\\d\\d|\\d)",
299
- J: "(\\d\\d|\\d)\\w+",
300
- K: "",
301
- M: "(\\w+)",
302
- S: "(\\d\\d|\\d)",
303
- U: "(.+)",
304
- W: "(\\d\\d|\\d)",
305
- Y: "(\\d{4})",
306
- Z: "(.+)",
307
- d: "(\\d\\d|\\d)",
308
- h: "(\\d\\d|\\d)",
309
- i: "(\\d\\d|\\d)",
310
- j: "(\\d\\d|\\d)",
311
- l: "(\\w+)",
312
- m: "(\\d\\d|\\d)",
313
- n: "(\\d\\d|\\d)",
314
- s: "(\\d\\d|\\d)",
315
- u: "(.+)",
316
- w: "(\\d\\d|\\d)",
317
- y: "(\\d{2})",
318
- };
319
- const formats = {
320
- Z: (date) => date.toISOString(),
321
- D: function (date, locale, options) {
322
- return locale.weekdays.shorthand[formats.w(date, locale, options)];
323
- },
324
- F: function (date, locale, options) {
325
- return monthToStr(formats.n(date, locale, options) - 1, false, locale);
326
- },
327
- G: function (date, locale, options) {
328
- return pad(formats.h(date, locale, options));
329
- },
330
- H: (date) => pad(date.getHours()),
331
- J: function (date, locale) {
332
- return locale.ordinal !== undefined
333
- ? date.getDate() + locale.ordinal(date.getDate())
334
- : date.getDate();
335
- },
336
- K: (date, locale) => locale.amPM[int(date.getHours() > 11)],
337
- M: function (date, locale) {
338
- return monthToStr(date.getMonth(), true, locale);
339
- },
340
- S: (date) => pad(date.getSeconds()),
341
- U: (date) => date.getTime() / 1000,
342
- W: function (date, _, options) {
343
- return options.getWeek(date);
344
- },
345
- Y: (date) => pad(date.getFullYear(), 4),
346
- d: (date) => pad(date.getDate()),
347
- h: (date) => (date.getHours() % 12 ? date.getHours() % 12 : 12),
348
- i: (date) => pad(date.getMinutes()),
349
- j: (date) => date.getDate(),
350
- l: function (date, locale) {
351
- return locale.weekdays.longhand[date.getDay()];
352
- },
353
- m: (date) => pad(date.getMonth() + 1),
354
- n: (date) => date.getMonth() + 1,
355
- s: (date) => date.getSeconds(),
356
- u: (date) => date.getTime(),
357
- w: (date) => date.getDay(),
358
- y: (date) => String(date.getFullYear()).substring(2),
359
- };
360
-
361
- const createDateFormatter = ({ config = defaults, l10n = english, isMobile = false, }) => (dateObj, frmt, overrideLocale) => {
362
- const locale = overrideLocale || l10n;
363
- if (config.formatDate !== undefined && !isMobile) {
364
- return config.formatDate(dateObj, frmt, locale);
365
- }
366
- return frmt
367
- .split("")
368
- .map((c, i, arr) => formats[c] && arr[i - 1] !== "\\"
369
- ? formats[c](dateObj, locale, config)
370
- : c !== "\\"
371
- ? c
372
- : "")
373
- .join("");
374
- };
375
- const createDateParser = ({ config = defaults, l10n = english }) => (date, givenFormat, timeless, customLocale) => {
376
- if (date !== 0 && !date)
377
- return undefined;
378
- const locale = customLocale || l10n;
379
- let parsedDate;
380
- const dateOrig = date;
381
- if (date instanceof Date)
382
- parsedDate = new Date(date.getTime());
383
- else if (typeof date !== "string" &&
384
- date.toFixed !== undefined)
385
- parsedDate = new Date(date);
386
- else if (typeof date === "string") {
387
- const format = givenFormat || (config || defaults).dateFormat;
388
- const datestr = String(date).trim();
389
- if (datestr === "today") {
390
- parsedDate = new Date();
391
- timeless = true;
392
- }
393
- else if (/Z$/.test(datestr) ||
394
- /GMT$/.test(datestr))
395
- parsedDate = new Date(date);
396
- else if (config && config.parseDate)
397
- parsedDate = config.parseDate(date, format);
398
- else {
399
- parsedDate =
400
- !config || !config.noCalendar
401
- ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0)
402
- : new Date(new Date().setHours(0, 0, 0, 0));
403
- let matched, ops = [];
404
- for (let i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) {
405
- const token = format[i];
406
- const isBackSlash = token === "\\";
407
- const escaped = format[i - 1] === "\\" || isBackSlash;
408
- if (tokenRegex[token] && !escaped) {
409
- regexStr += tokenRegex[token];
410
- const match = new RegExp(regexStr).exec(date);
411
- if (match && (matched = true)) {
412
- ops[token !== "Y" ? "push" : "unshift"]({
413
- fn: revFormat[token],
414
- val: match[++matchIndex],
415
- });
416
- }
417
- }
418
- else if (!isBackSlash)
419
- regexStr += ".";
420
- ops.forEach(({ fn, val }) => (parsedDate = fn(parsedDate, val, locale) || parsedDate));
421
- }
422
- parsedDate = matched ? parsedDate : undefined;
423
- }
424
- }
425
- if (!(parsedDate instanceof Date && !isNaN(parsedDate.getTime()))) {
426
- config.errorHandler(new Error(`Invalid date provided: ${dateOrig}`));
427
- return undefined;
428
- }
429
- if (timeless === true)
430
- parsedDate.setHours(0, 0, 0, 0);
431
- return parsedDate;
432
- };
433
- function compareDates(date1, date2, timeless = true) {
434
- if (timeless !== false) {
435
- return (new Date(date1.getTime()).setHours(0, 0, 0, 0) -
436
- new Date(date2.getTime()).setHours(0, 0, 0, 0));
437
- }
438
- return date1.getTime() - date2.getTime();
439
- }
440
- const isBetween = (ts, ts1, ts2) => {
441
- return ts > Math.min(ts1, ts2) && ts < Math.max(ts1, ts2);
442
- };
443
- const duration = {
444
- DAY: 86400000,
445
- };
446
- function getDefaultHours(config) {
447
- let hours = config.defaultHour;
448
- let minutes = config.defaultMinute;
449
- let seconds = config.defaultSeconds;
450
- if (config.minDate !== undefined) {
451
- const minHour = config.minDate.getHours();
452
- const minMinutes = config.minDate.getMinutes();
453
- const minSeconds = config.minDate.getSeconds();
454
- if (hours < minHour) {
455
- hours = minHour;
456
- }
457
- if (hours === minHour && minutes < minMinutes) {
458
- minutes = minMinutes;
459
- }
460
- if (hours === minHour && minutes === minMinutes && seconds < minSeconds)
461
- seconds = config.minDate.getSeconds();
462
- }
463
- if (config.maxDate !== undefined) {
464
- const maxHr = config.maxDate.getHours();
465
- const maxMinutes = config.maxDate.getMinutes();
466
- hours = Math.min(hours, maxHr);
467
- if (hours === maxHr)
468
- minutes = Math.min(maxMinutes, minutes);
469
- if (hours === maxHr && minutes === maxMinutes)
470
- seconds = config.maxDate.getSeconds();
471
- }
472
- return { hours, minutes, seconds };
473
- }
474
-
475
- if (typeof Object.assign !== "function") {
476
- Object.assign = function (target, ...args) {
477
- if (!target) {
478
- throw TypeError("Cannot convert undefined or null to object");
479
- }
480
- for (const source of args) {
481
- if (source) {
482
- Object.keys(source).forEach((key) => (target[key] = source[key]));
483
- }
484
- }
485
- return target;
486
- };
487
- }
488
-
489
- const DEBOUNCED_CHANGE_MS = 300;
490
- function FlatpickrInstance(element, instanceConfig) {
491
- const self = {
492
- config: Object.assign(Object.assign({}, defaults), flatpickr.defaultConfig),
493
- l10n: english,
494
- };
495
- self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
496
- self._handlers = [];
497
- self.pluginElements = [];
498
- self.loadedPlugins = [];
499
- self._bind = bind;
500
- self._setHoursFromDate = setHoursFromDate;
501
- self._positionCalendar = positionCalendar;
502
- self.changeMonth = changeMonth;
503
- self.changeYear = changeYear;
504
- self.clear = clear;
505
- self.close = close;
506
- self._createElement = createElement;
507
- self.destroy = destroy;
508
- self.isEnabled = isEnabled;
509
- self.jumpToDate = jumpToDate;
510
- self.open = open;
511
- self.redraw = redraw;
512
- self.set = set;
513
- self.setDate = setDate;
514
- self.toggle = toggle;
515
- function setupHelperFunctions() {
516
- self.utils = {
517
- getDaysInMonth(month = self.currentMonth, yr = self.currentYear) {
518
- if (month === 1 && ((yr % 4 === 0 && yr % 100 !== 0) || yr % 400 === 0))
519
- return 29;
520
- return self.l10n.daysInMonth[month];
521
- },
522
- };
523
- }
524
- function init() {
525
- self.element = self.input = element;
526
- self.isOpen = false;
527
- parseConfig();
528
- setupLocale();
529
- setupInputs();
530
- setupDates();
531
- setupHelperFunctions();
532
- if (!self.isMobile)
533
- build();
534
- bindEvents();
535
- if (self.selectedDates.length || self.config.noCalendar) {
536
- if (self.config.enableTime) {
537
- setHoursFromDate(self.config.noCalendar ? self.latestSelectedDateObj : undefined);
538
- }
539
- updateValue(false);
540
- }
541
- setCalendarWidth();
542
- const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
543
- if (!self.isMobile && isSafari) {
544
- positionCalendar();
545
- }
546
- triggerEvent("onReady");
547
- }
548
- function bindToInstance(fn) {
549
- return fn.bind(self);
550
- }
551
- function setCalendarWidth() {
552
- const config = self.config;
553
- if (config.weekNumbers === false && config.showMonths === 1) {
554
- return;
555
- }
556
- else if (config.noCalendar !== true) {
557
- window.requestAnimationFrame(function () {
558
- if (self.calendarContainer !== undefined) {
559
- self.calendarContainer.style.visibility = "hidden";
560
- self.calendarContainer.style.display = "block";
561
- }
562
- if (self.daysContainer !== undefined) {
563
- const daysWidth = (self.days.offsetWidth + 1) * config.showMonths;
564
- self.daysContainer.style.width = daysWidth + "px";
565
- self.calendarContainer.style.width =
566
- daysWidth +
567
- (self.weekWrapper !== undefined
568
- ? self.weekWrapper.offsetWidth
569
- : 0) +
570
- "px";
571
- self.calendarContainer.style.removeProperty("visibility");
572
- self.calendarContainer.style.removeProperty("display");
573
- }
574
- });
575
- }
576
- }
577
- function updateTime(e) {
578
- if (self.selectedDates.length === 0) {
579
- const defaultDate = self.config.minDate === undefined ||
580
- compareDates(new Date(), self.config.minDate) >= 0
581
- ? new Date()
582
- : new Date(self.config.minDate.getTime());
583
- const defaults = getDefaultHours(self.config);
584
- defaultDate.setHours(defaults.hours, defaults.minutes, defaults.seconds, defaultDate.getMilliseconds());
585
- self.selectedDates = [defaultDate];
586
- self.latestSelectedDateObj = defaultDate;
587
- }
588
- if (e !== undefined && e.type !== "blur") {
589
- timeWrapper(e);
590
- }
591
- const prevValue = self._input.value;
592
- setHoursFromInputs();
593
- updateValue();
594
- if (self._input.value !== prevValue) {
595
- self._debouncedChange();
596
- }
597
- }
598
- function ampm2military(hour, amPM) {
599
- return (hour % 12) + 12 * int(amPM === self.l10n.amPM[1]);
600
- }
601
- function military2ampm(hour) {
602
- switch (hour % 24) {
603
- case 0:
604
- case 12:
605
- return 12;
606
- default:
607
- return hour % 12;
608
- }
609
- }
610
- function setHoursFromInputs() {
611
- if (self.hourElement === undefined || self.minuteElement === undefined)
612
- return;
613
- let hours = (parseInt(self.hourElement.value.slice(-2), 10) || 0) % 24, minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60, seconds = self.secondElement !== undefined
614
- ? (parseInt(self.secondElement.value, 10) || 0) % 60
615
- : 0;
616
- if (self.amPM !== undefined) {
617
- hours = ampm2military(hours, self.amPM.textContent);
618
- }
619
- const limitMinHours = self.config.minTime !== undefined ||
620
- (self.config.minDate &&
621
- self.minDateHasTime &&
622
- self.latestSelectedDateObj &&
623
- compareDates(self.latestSelectedDateObj, self.config.minDate, true) ===
624
- 0);
625
- const limitMaxHours = self.config.maxTime !== undefined ||
626
- (self.config.maxDate &&
627
- self.maxDateHasTime &&
628
- self.latestSelectedDateObj &&
629
- compareDates(self.latestSelectedDateObj, self.config.maxDate, true) ===
630
- 0);
631
- if (limitMaxHours) {
632
- const maxTime = self.config.maxTime !== undefined
633
- ? self.config.maxTime
634
- : self.config.maxDate;
635
- hours = Math.min(hours, maxTime.getHours());
636
- if (hours === maxTime.getHours())
637
- minutes = Math.min(minutes, maxTime.getMinutes());
638
- if (minutes === maxTime.getMinutes())
639
- seconds = Math.min(seconds, maxTime.getSeconds());
640
- }
641
- if (limitMinHours) {
642
- const minTime = self.config.minTime !== undefined
643
- ? self.config.minTime
644
- : self.config.minDate;
645
- hours = Math.max(hours, minTime.getHours());
646
- if (hours === minTime.getHours() && minutes < minTime.getMinutes())
647
- minutes = minTime.getMinutes();
648
- if (minutes === minTime.getMinutes())
649
- seconds = Math.max(seconds, minTime.getSeconds());
650
- }
651
- setHours(hours, minutes, seconds);
652
- }
653
- function setHoursFromDate(dateObj) {
654
- const date = dateObj || self.latestSelectedDateObj;
655
- if (date) {
656
- setHours(date.getHours(), date.getMinutes(), date.getSeconds());
657
- }
658
- }
659
- function setHours(hours, minutes, seconds) {
660
- if (self.latestSelectedDateObj !== undefined) {
661
- self.latestSelectedDateObj.setHours(hours % 24, minutes, seconds || 0, 0);
662
- }
663
- if (!self.hourElement || !self.minuteElement || self.isMobile)
664
- return;
665
- self.hourElement.value = pad(!self.config.time_24hr
666
- ? ((12 + hours) % 12) + 12 * int(hours % 12 === 0)
667
- : hours);
668
- self.minuteElement.value = pad(minutes);
669
- if (self.amPM !== undefined)
670
- self.amPM.textContent = self.l10n.amPM[int(hours >= 12)];
671
- if (self.secondElement !== undefined)
672
- self.secondElement.value = pad(seconds);
673
- }
674
- function onYearInput(event) {
675
- const eventTarget = getEventTarget(event);
676
- const year = parseInt(eventTarget.value) + (event.delta || 0);
677
- if (year / 1000 > 1 ||
678
- (event.key === "Enter" && !/[^\d]/.test(year.toString()))) {
679
- changeYear(year);
680
- }
681
- }
682
- function bind(element, event, handler, options) {
683
- if (event instanceof Array)
684
- return event.forEach((ev) => bind(element, ev, handler, options));
685
- if (element instanceof Array)
686
- return element.forEach((el) => bind(el, event, handler, options));
687
- element.addEventListener(event, handler, options);
688
- self._handlers.push({
689
- remove: () => element.removeEventListener(event, handler),
690
- });
691
- }
692
- function triggerChange() {
693
- triggerEvent("onChange");
694
- }
695
- function bindEvents() {
696
- if (self.config.wrap) {
697
- ["open", "close", "toggle", "clear"].forEach((evt) => {
698
- Array.prototype.forEach.call(self.element.querySelectorAll(`[data-${evt}]`), (el) => bind(el, "click", self[evt]));
699
- });
700
- }
701
- if (self.isMobile) {
702
- setupMobile();
703
- return;
704
- }
705
- const debouncedResize = debounce(onResize, 50);
706
- self._debouncedChange = debounce(triggerChange, DEBOUNCED_CHANGE_MS);
707
- if (self.daysContainer && !/iPhone|iPad|iPod/i.test(navigator.userAgent))
708
- bind(self.daysContainer, "mouseover", (e) => {
709
- if (self.config.mode === "range")
710
- onMouseOver(getEventTarget(e));
711
- });
712
- bind(window.document.body, "keydown", onKeyDown);
713
- if (!self.config.inline && !self.config.static)
714
- bind(window, "resize", debouncedResize);
715
- if (window.ontouchstart !== undefined)
716
- bind(window.document, "touchstart", documentClick);
717
- else
718
- bind(window.document, "mousedown", documentClick);
719
- bind(window.document, "focus", documentClick, { capture: true });
720
- if (self.config.clickOpens === true) {
721
- bind(self._input, "focus", self.open);
722
- bind(self._input, "click", self.open);
723
- }
724
- if (self.daysContainer !== undefined) {
725
- bind(self.monthNav, "click", onMonthNavClick);
726
- bind(self.monthNav, ["keyup", "increment"], onYearInput);
727
- bind(self.daysContainer, "click", selectDate);
728
- }
729
- if (self.timeContainer !== undefined &&
730
- self.minuteElement !== undefined &&
731
- self.hourElement !== undefined) {
732
- const selText = (e) => getEventTarget(e).select();
733
- bind(self.timeContainer, ["increment"], updateTime);
734
- bind(self.timeContainer, "blur", updateTime, { capture: true });
735
- bind(self.timeContainer, "click", timeIncrement);
736
- bind([self.hourElement, self.minuteElement], ["focus", "click"], selText);
737
- if (self.secondElement !== undefined)
738
- bind(self.secondElement, "focus", () => self.secondElement && self.secondElement.select());
739
- if (self.amPM !== undefined) {
740
- bind(self.amPM, "click", (e) => {
741
- updateTime(e);
742
- triggerChange();
743
- });
744
- }
745
- }
746
- if (self.config.allowInput) {
747
- bind(self._input, "blur", onBlur);
748
- }
749
- }
750
- function jumpToDate(jumpDate, triggerChange) {
751
- const jumpTo = jumpDate !== undefined
752
- ? self.parseDate(jumpDate)
753
- : self.latestSelectedDateObj ||
754
- (self.config.minDate && self.config.minDate > self.now
755
- ? self.config.minDate
756
- : self.config.maxDate && self.config.maxDate < self.now
757
- ? self.config.maxDate
758
- : self.now);
759
- const oldYear = self.currentYear;
760
- const oldMonth = self.currentMonth;
761
- try {
762
- if (jumpTo !== undefined) {
763
- self.currentYear = jumpTo.getFullYear();
764
- self.currentMonth = jumpTo.getMonth();
765
- }
766
- }
767
- catch (e) {
768
- e.message = "Invalid date supplied: " + jumpTo;
769
- self.config.errorHandler(e);
770
- }
771
- if (triggerChange && self.currentYear !== oldYear) {
772
- triggerEvent("onYearChange");
773
- buildMonthSwitch();
774
- }
775
- if (triggerChange &&
776
- (self.currentYear !== oldYear || self.currentMonth !== oldMonth)) {
777
- triggerEvent("onMonthChange");
778
- }
779
- self.redraw();
780
- }
781
- function timeIncrement(e) {
782
- const eventTarget = getEventTarget(e);
783
- if (~eventTarget.className.indexOf("arrow"))
784
- incrementNumInput(e, eventTarget.classList.contains("arrowUp") ? 1 : -1);
785
- }
786
- function incrementNumInput(e, delta, inputElem) {
787
- const target = e && getEventTarget(e);
788
- const input = inputElem ||
789
- (target && target.parentNode && target.parentNode.firstChild);
790
- const event = createEvent("increment");
791
- event.delta = delta;
792
- input && input.dispatchEvent(event);
793
- }
794
- function build() {
795
- const fragment = window.document.createDocumentFragment();
796
- self.calendarContainer = createElement("div", "flatpickr-calendar");
797
- self.calendarContainer.tabIndex = -1;
798
- if (!self.config.noCalendar) {
799
- fragment.appendChild(buildMonthNav());
800
- self.innerContainer = createElement("div", "flatpickr-innerContainer");
801
- if (self.config.weekNumbers) {
802
- const { weekWrapper, weekNumbers } = buildWeeks();
803
- self.innerContainer.appendChild(weekWrapper);
804
- self.weekNumbers = weekNumbers;
805
- self.weekWrapper = weekWrapper;
806
- }
807
- self.rContainer = createElement("div", "flatpickr-rContainer");
808
- self.rContainer.appendChild(buildWeekdays());
809
- if (!self.daysContainer) {
810
- self.daysContainer = createElement("div", "flatpickr-days");
811
- self.daysContainer.tabIndex = -1;
812
- }
813
- buildDays();
814
- self.rContainer.appendChild(self.daysContainer);
815
- self.innerContainer.appendChild(self.rContainer);
816
- fragment.appendChild(self.innerContainer);
817
- }
818
- if (self.config.enableTime) {
819
- fragment.appendChild(buildTime());
820
- }
821
- toggleClass(self.calendarContainer, "rangeMode", self.config.mode === "range");
822
- toggleClass(self.calendarContainer, "animate", self.config.animate === true);
823
- toggleClass(self.calendarContainer, "multiMonth", self.config.showMonths > 1);
824
- self.calendarContainer.appendChild(fragment);
825
- const customAppend = self.config.appendTo !== undefined &&
826
- self.config.appendTo.nodeType !== undefined;
827
- if (self.config.inline || self.config.static) {
828
- self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");
829
- if (self.config.inline) {
830
- if (!customAppend && self.element.parentNode)
831
- self.element.parentNode.insertBefore(self.calendarContainer, self._input.nextSibling);
832
- else if (self.config.appendTo !== undefined)
833
- self.config.appendTo.appendChild(self.calendarContainer);
834
- }
835
- if (self.config.static) {
836
- const wrapper = createElement("div", "flatpickr-wrapper");
837
- if (self.element.parentNode)
838
- self.element.parentNode.insertBefore(wrapper, self.element);
839
- wrapper.appendChild(self.element);
840
- if (self.altInput)
841
- wrapper.appendChild(self.altInput);
842
- wrapper.appendChild(self.calendarContainer);
843
- }
844
- }
845
- if (!self.config.static && !self.config.inline)
846
- (self.config.appendTo !== undefined
847
- ? self.config.appendTo
848
- : window.document.body).appendChild(self.calendarContainer);
849
- }
850
- function createDay(className, date, dayNumber, i) {
851
- const dateIsEnabled = isEnabled(date, true), dayElement = createElement("span", "flatpickr-day " + className, date.getDate().toString());
852
- dayElement.dateObj = date;
853
- dayElement.$i = i;
854
- dayElement.setAttribute("aria-label", self.formatDate(date, self.config.ariaDateFormat));
855
- if (className.indexOf("hidden") === -1 &&
856
- compareDates(date, self.now) === 0) {
857
- self.todayDateElem = dayElement;
858
- dayElement.classList.add("today");
859
- dayElement.setAttribute("aria-current", "date");
860
- }
861
- if (dateIsEnabled) {
862
- dayElement.tabIndex = -1;
863
- if (isDateSelected(date)) {
864
- dayElement.classList.add("selected");
865
- self.selectedDateElem = dayElement;
866
- if (self.config.mode === "range") {
867
- toggleClass(dayElement, "startRange", self.selectedDates[0] &&
868
- compareDates(date, self.selectedDates[0], true) === 0);
869
- toggleClass(dayElement, "endRange", self.selectedDates[1] &&
870
- compareDates(date, self.selectedDates[1], true) === 0);
871
- if (className === "nextMonthDay")
872
- dayElement.classList.add("inRange");
873
- }
874
- }
875
- }
876
- else {
877
- dayElement.classList.add("flatpickr-disabled");
878
- }
879
- if (self.config.mode === "range") {
880
- if (isDateInRange(date) && !isDateSelected(date))
881
- dayElement.classList.add("inRange");
882
- }
883
- if (self.weekNumbers &&
884
- self.config.showMonths === 1 &&
885
- className !== "prevMonthDay" &&
886
- dayNumber % 7 === 1) {
887
- self.weekNumbers.insertAdjacentHTML("beforeend", "<span class='flatpickr-day'>" + self.config.getWeek(date) + "</span>");
888
- }
889
- triggerEvent("onDayCreate", dayElement);
890
- return dayElement;
891
- }
892
- function focusOnDayElem(targetNode) {
893
- targetNode.focus();
894
- if (self.config.mode === "range")
895
- onMouseOver(targetNode);
896
- }
897
- function getFirstAvailableDay(delta) {
898
- const startMonth = delta > 0 ? 0 : self.config.showMonths - 1;
899
- const endMonth = delta > 0 ? self.config.showMonths : -1;
900
- for (let m = startMonth; m != endMonth; m += delta) {
901
- const month = self.daysContainer.children[m];
902
- const startIndex = delta > 0 ? 0 : month.children.length - 1;
903
- const endIndex = delta > 0 ? month.children.length : -1;
904
- for (let i = startIndex; i != endIndex; i += delta) {
905
- const c = month.children[i];
906
- if (c.className.indexOf("hidden") === -1 && isEnabled(c.dateObj))
907
- return c;
908
- }
909
- }
910
- return undefined;
911
- }
912
- function getNextAvailableDay(current, delta) {
913
- const givenMonth = current.className.indexOf("Month") === -1
914
- ? current.dateObj.getMonth()
915
- : self.currentMonth;
916
- const endMonth = delta > 0 ? self.config.showMonths : -1;
917
- const loopDelta = delta > 0 ? 1 : -1;
918
- for (let m = givenMonth - self.currentMonth; m != endMonth; m += loopDelta) {
919
- const month = self.daysContainer.children[m];
920
- const startIndex = givenMonth - self.currentMonth === m
921
- ? current.$i + delta
922
- : delta < 0
923
- ? month.children.length - 1
924
- : 0;
925
- const numMonthDays = month.children.length;
926
- for (let i = startIndex; i >= 0 && i < numMonthDays && i != (delta > 0 ? numMonthDays : -1); i += loopDelta) {
927
- const c = month.children[i];
928
- if (c.className.indexOf("hidden") === -1 &&
929
- isEnabled(c.dateObj) &&
930
- Math.abs(current.$i - i) >= Math.abs(delta))
931
- return focusOnDayElem(c);
932
- }
933
- }
934
- self.changeMonth(loopDelta);
935
- focusOnDay(getFirstAvailableDay(loopDelta), 0);
936
- return undefined;
937
- }
938
- function focusOnDay(current, offset) {
939
- const dayFocused = isInView(document.activeElement || document.body);
940
- const startElem = current !== undefined
941
- ? current
942
- : dayFocused
943
- ? document.activeElement
944
- : self.selectedDateElem !== undefined && isInView(self.selectedDateElem)
945
- ? self.selectedDateElem
946
- : self.todayDateElem !== undefined && isInView(self.todayDateElem)
947
- ? self.todayDateElem
948
- : getFirstAvailableDay(offset > 0 ? 1 : -1);
949
- if (startElem === undefined) {
950
- self._input.focus();
951
- }
952
- else if (!dayFocused) {
953
- focusOnDayElem(startElem);
954
- }
955
- else {
956
- getNextAvailableDay(startElem, offset);
957
- }
958
- }
959
- function buildMonthDays(year, month) {
960
- const firstOfMonth = (new Date(year, month, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7;
961
- const prevMonthDays = self.utils.getDaysInMonth((month - 1 + 12) % 12, year);
962
- const daysInMonth = self.utils.getDaysInMonth(month, year), days = window.document.createDocumentFragment(), isMultiMonth = self.config.showMonths > 1, prevMonthDayClass = isMultiMonth ? "prevMonthDay hidden" : "prevMonthDay", nextMonthDayClass = isMultiMonth ? "nextMonthDay hidden" : "nextMonthDay";
963
- let dayNumber = prevMonthDays + 1 - firstOfMonth, dayIndex = 0;
964
- for (; dayNumber <= prevMonthDays; dayNumber++, dayIndex++) {
965
- days.appendChild(createDay(prevMonthDayClass, new Date(year, month - 1, dayNumber), dayNumber, dayIndex));
966
- }
967
- for (dayNumber = 1; dayNumber <= daysInMonth; dayNumber++, dayIndex++) {
968
- days.appendChild(createDay("", new Date(year, month, dayNumber), dayNumber, dayIndex));
969
- }
970
- for (let dayNum = daysInMonth + 1; dayNum <= 42 - firstOfMonth &&
971
- (self.config.showMonths === 1 || dayIndex % 7 !== 0); dayNum++, dayIndex++) {
972
- days.appendChild(createDay(nextMonthDayClass, new Date(year, month + 1, dayNum % daysInMonth), dayNum, dayIndex));
973
- }
974
- const dayContainer = createElement("div", "dayContainer");
975
- dayContainer.appendChild(days);
976
- return dayContainer;
977
- }
978
- function buildDays() {
979
- if (self.daysContainer === undefined) {
980
- return;
981
- }
982
- clearNode(self.daysContainer);
983
- if (self.weekNumbers)
984
- clearNode(self.weekNumbers);
985
- const frag = document.createDocumentFragment();
986
- for (let i = 0; i < self.config.showMonths; i++) {
987
- const d = new Date(self.currentYear, self.currentMonth, 1);
988
- d.setMonth(self.currentMonth + i);
989
- frag.appendChild(buildMonthDays(d.getFullYear(), d.getMonth()));
990
- }
991
- self.daysContainer.appendChild(frag);
992
- self.days = self.daysContainer.firstChild;
993
- if (self.config.mode === "range" && self.selectedDates.length === 1) {
994
- onMouseOver();
995
- }
996
- }
997
- function buildMonthSwitch() {
998
- if (self.config.showMonths > 1 ||
999
- self.config.monthSelectorType !== "dropdown")
1000
- return;
1001
- const shouldBuildMonth = function (month) {
1002
- if (self.config.minDate !== undefined &&
1003
- self.currentYear === self.config.minDate.getFullYear() &&
1004
- month < self.config.minDate.getMonth()) {
1005
- return false;
1006
- }
1007
- return !(self.config.maxDate !== undefined &&
1008
- self.currentYear === self.config.maxDate.getFullYear() &&
1009
- month > self.config.maxDate.getMonth());
1010
- };
1011
- self.monthsDropdownContainer.tabIndex = -1;
1012
- self.monthsDropdownContainer.innerHTML = "";
1013
- for (let i = 0; i < 12; i++) {
1014
- if (!shouldBuildMonth(i))
1015
- continue;
1016
- const month = createElement("option", "flatpickr-monthDropdown-month");
1017
- month.value = new Date(self.currentYear, i).getMonth().toString();
1018
- month.textContent = monthToStr(i, self.config.shorthandCurrentMonth, self.l10n);
1019
- month.tabIndex = -1;
1020
- if (self.currentMonth === i) {
1021
- month.selected = true;
1022
- }
1023
- self.monthsDropdownContainer.appendChild(month);
1024
- }
1025
- }
1026
- function buildMonth() {
1027
- const container = createElement("div", "flatpickr-month");
1028
- const monthNavFragment = window.document.createDocumentFragment();
1029
- let monthElement;
1030
- if (self.config.showMonths > 1 ||
1031
- self.config.monthSelectorType === "static") {
1032
- monthElement = createElement("span", "cur-month");
1033
- }
1034
- else {
1035
- self.monthsDropdownContainer = createElement("select", "flatpickr-monthDropdown-months");
1036
- self.monthsDropdownContainer.setAttribute("aria-label", self.l10n.monthAriaLabel);
1037
- bind(self.monthsDropdownContainer, "change", (e) => {
1038
- const target = getEventTarget(e);
1039
- const selectedMonth = parseInt(target.value, 10);
1040
- self.changeMonth(selectedMonth - self.currentMonth);
1041
- triggerEvent("onMonthChange");
1042
- });
1043
- buildMonthSwitch();
1044
- monthElement = self.monthsDropdownContainer;
1045
- }
1046
- const yearInput = createNumberInput("cur-year", { tabindex: "-1" });
1047
- const yearElement = yearInput.getElementsByTagName("input")[0];
1048
- yearElement.setAttribute("aria-label", self.l10n.yearAriaLabel);
1049
- if (self.config.minDate) {
1050
- yearElement.setAttribute("min", self.config.minDate.getFullYear().toString());
1051
- }
1052
- if (self.config.maxDate) {
1053
- yearElement.setAttribute("max", self.config.maxDate.getFullYear().toString());
1054
- yearElement.disabled =
1055
- !!self.config.minDate &&
1056
- self.config.minDate.getFullYear() === self.config.maxDate.getFullYear();
1057
- }
1058
- const currentMonth = createElement("div", "flatpickr-current-month");
1059
- currentMonth.appendChild(monthElement);
1060
- currentMonth.appendChild(yearInput);
1061
- monthNavFragment.appendChild(currentMonth);
1062
- container.appendChild(monthNavFragment);
1063
- return {
1064
- container,
1065
- yearElement,
1066
- monthElement,
1067
- };
1068
- }
1069
- function buildMonths() {
1070
- clearNode(self.monthNav);
1071
- self.monthNav.appendChild(self.prevMonthNav);
1072
- if (self.config.showMonths) {
1073
- self.yearElements = [];
1074
- self.monthElements = [];
1075
- }
1076
- for (let m = self.config.showMonths; m--;) {
1077
- const month = buildMonth();
1078
- self.yearElements.push(month.yearElement);
1079
- self.monthElements.push(month.monthElement);
1080
- self.monthNav.appendChild(month.container);
1081
- }
1082
- self.monthNav.appendChild(self.nextMonthNav);
1083
- }
1084
- function buildMonthNav() {
1085
- self.monthNav = createElement("div", "flatpickr-months");
1086
- self.yearElements = [];
1087
- self.monthElements = [];
1088
- self.prevMonthNav = createElement("span", "flatpickr-prev-month");
1089
- self.prevMonthNav.innerHTML = self.config.prevArrow;
1090
- self.nextMonthNav = createElement("span", "flatpickr-next-month");
1091
- self.nextMonthNav.innerHTML = self.config.nextArrow;
1092
- buildMonths();
1093
- Object.defineProperty(self, "_hidePrevMonthArrow", {
1094
- get: () => self.__hidePrevMonthArrow,
1095
- set(bool) {
1096
- if (self.__hidePrevMonthArrow !== bool) {
1097
- toggleClass(self.prevMonthNav, "flatpickr-disabled", bool);
1098
- self.__hidePrevMonthArrow = bool;
1099
- }
1100
- },
1101
- });
1102
- Object.defineProperty(self, "_hideNextMonthArrow", {
1103
- get: () => self.__hideNextMonthArrow,
1104
- set(bool) {
1105
- if (self.__hideNextMonthArrow !== bool) {
1106
- toggleClass(self.nextMonthNav, "flatpickr-disabled", bool);
1107
- self.__hideNextMonthArrow = bool;
1108
- }
1109
- },
1110
- });
1111
- self.currentYearElement = self.yearElements[0];
1112
- updateNavigationCurrentMonth();
1113
- return self.monthNav;
1114
- }
1115
- function buildTime() {
1116
- self.calendarContainer.classList.add("hasTime");
1117
- if (self.config.noCalendar)
1118
- self.calendarContainer.classList.add("noCalendar");
1119
- const defaults = getDefaultHours(self.config);
1120
- self.timeContainer = createElement("div", "flatpickr-time");
1121
- self.timeContainer.tabIndex = -1;
1122
- const separator = createElement("span", "flatpickr-time-separator", ":");
1123
- const hourInput = createNumberInput("flatpickr-hour", {
1124
- "aria-label": self.l10n.hourAriaLabel,
1125
- });
1126
- self.hourElement = hourInput.getElementsByTagName("input")[0];
1127
- const minuteInput = createNumberInput("flatpickr-minute", {
1128
- "aria-label": self.l10n.minuteAriaLabel,
1129
- });
1130
- self.minuteElement = minuteInput.getElementsByTagName("input")[0];
1131
- self.hourElement.tabIndex = self.minuteElement.tabIndex = -1;
1132
- self.hourElement.value = pad(self.latestSelectedDateObj
1133
- ? self.latestSelectedDateObj.getHours()
1134
- : self.config.time_24hr
1135
- ? defaults.hours
1136
- : military2ampm(defaults.hours));
1137
- self.minuteElement.value = pad(self.latestSelectedDateObj
1138
- ? self.latestSelectedDateObj.getMinutes()
1139
- : defaults.minutes);
1140
- self.hourElement.setAttribute("step", self.config.hourIncrement.toString());
1141
- self.minuteElement.setAttribute("step", self.config.minuteIncrement.toString());
1142
- self.hourElement.setAttribute("min", self.config.time_24hr ? "0" : "1");
1143
- self.hourElement.setAttribute("max", self.config.time_24hr ? "23" : "12");
1144
- self.hourElement.setAttribute("maxlength", "2");
1145
- self.minuteElement.setAttribute("min", "0");
1146
- self.minuteElement.setAttribute("max", "59");
1147
- self.minuteElement.setAttribute("maxlength", "2");
1148
- self.timeContainer.appendChild(hourInput);
1149
- self.timeContainer.appendChild(separator);
1150
- self.timeContainer.appendChild(minuteInput);
1151
- if (self.config.time_24hr)
1152
- self.timeContainer.classList.add("time24hr");
1153
- if (self.config.enableSeconds) {
1154
- self.timeContainer.classList.add("hasSeconds");
1155
- const secondInput = createNumberInput("flatpickr-second");
1156
- self.secondElement = secondInput.getElementsByTagName("input")[0];
1157
- self.secondElement.value = pad(self.latestSelectedDateObj
1158
- ? self.latestSelectedDateObj.getSeconds()
1159
- : defaults.seconds);
1160
- self.secondElement.setAttribute("step", self.minuteElement.getAttribute("step"));
1161
- self.secondElement.setAttribute("min", "0");
1162
- self.secondElement.setAttribute("max", "59");
1163
- self.secondElement.setAttribute("maxlength", "2");
1164
- self.timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":"));
1165
- self.timeContainer.appendChild(secondInput);
1166
- }
1167
- if (!self.config.time_24hr) {
1168
- self.amPM = createElement("span", "flatpickr-am-pm", self.l10n.amPM[int((self.latestSelectedDateObj
1169
- ? self.hourElement.value
1170
- : self.config.defaultHour) > 11)]);
1171
- self.amPM.title = self.l10n.toggleTitle;
1172
- self.amPM.tabIndex = -1;
1173
- self.timeContainer.appendChild(self.amPM);
1174
- }
1175
- return self.timeContainer;
1176
- }
1177
- function buildWeekdays() {
1178
- if (!self.weekdayContainer)
1179
- self.weekdayContainer = createElement("div", "flatpickr-weekdays");
1180
- else
1181
- clearNode(self.weekdayContainer);
1182
- for (let i = self.config.showMonths; i--;) {
1183
- const container = createElement("div", "flatpickr-weekdaycontainer");
1184
- self.weekdayContainer.appendChild(container);
1185
- }
1186
- updateWeekdays();
1187
- return self.weekdayContainer;
1188
- }
1189
- function updateWeekdays() {
1190
- if (!self.weekdayContainer) {
1191
- return;
1192
- }
1193
- const firstDayOfWeek = self.l10n.firstDayOfWeek;
1194
- let weekdays = [...self.l10n.weekdays.shorthand];
1195
- if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
1196
- weekdays = [
1197
- ...weekdays.splice(firstDayOfWeek, weekdays.length),
1198
- ...weekdays.splice(0, firstDayOfWeek),
1199
- ];
1200
- }
1201
- for (let i = self.config.showMonths; i--;) {
1202
- self.weekdayContainer.children[i].innerHTML = `
1203
- <span class='flatpickr-weekday'>
1204
- ${weekdays.join("</span><span class='flatpickr-weekday'>")}
1205
- </span>
1206
- `;
1207
- }
1208
- }
1209
- function buildWeeks() {
1210
- self.calendarContainer.classList.add("hasWeeks");
1211
- const weekWrapper = createElement("div", "flatpickr-weekwrapper");
1212
- weekWrapper.appendChild(createElement("span", "flatpickr-weekday", self.l10n.weekAbbreviation));
1213
- const weekNumbers = createElement("div", "flatpickr-weeks");
1214
- weekWrapper.appendChild(weekNumbers);
1215
- return {
1216
- weekWrapper,
1217
- weekNumbers,
1218
- };
1219
- }
1220
- function changeMonth(value, isOffset = true) {
1221
- const delta = isOffset ? value : value - self.currentMonth;
1222
- if ((delta < 0 && self._hidePrevMonthArrow === true) ||
1223
- (delta > 0 && self._hideNextMonthArrow === true))
1224
- return;
1225
- self.currentMonth += delta;
1226
- if (self.currentMonth < 0 || self.currentMonth > 11) {
1227
- self.currentYear += self.currentMonth > 11 ? 1 : -1;
1228
- self.currentMonth = (self.currentMonth + 12) % 12;
1229
- triggerEvent("onYearChange");
1230
- buildMonthSwitch();
1231
- }
1232
- buildDays();
1233
- triggerEvent("onMonthChange");
1234
- updateNavigationCurrentMonth();
1235
- }
1236
- function clear(triggerChangeEvent = true, toInitial = true) {
1237
- self.input.value = "";
1238
- if (self.altInput !== undefined)
1239
- self.altInput.value = "";
1240
- if (self.mobileInput !== undefined)
1241
- self.mobileInput.value = "";
1242
- self.selectedDates = [];
1243
- self.latestSelectedDateObj = undefined;
1244
- if (toInitial === true) {
1245
- self.currentYear = self._initialDate.getFullYear();
1246
- self.currentMonth = self._initialDate.getMonth();
1247
- }
1248
- if (self.config.enableTime === true) {
1249
- const { hours, minutes, seconds } = getDefaultHours(self.config);
1250
- setHours(hours, minutes, seconds);
1251
- }
1252
- self.redraw();
1253
- if (triggerChangeEvent)
1254
- triggerEvent("onChange");
1255
- }
1256
- function close() {
1257
- self.isOpen = false;
1258
- if (!self.isMobile) {
1259
- if (self.calendarContainer !== undefined) {
1260
- self.calendarContainer.classList.remove("open");
1261
- }
1262
- if (self._input !== undefined) {
1263
- self._input.classList.remove("active");
1264
- }
1265
- }
1266
- triggerEvent("onClose");
1267
- }
1268
- function destroy() {
1269
- if (self.config !== undefined)
1270
- triggerEvent("onDestroy");
1271
- for (let i = self._handlers.length; i--;) {
1272
- self._handlers[i].remove();
1273
- }
1274
- self._handlers = [];
1275
- if (self.mobileInput) {
1276
- if (self.mobileInput.parentNode)
1277
- self.mobileInput.parentNode.removeChild(self.mobileInput);
1278
- self.mobileInput = undefined;
1279
- }
1280
- else if (self.calendarContainer && self.calendarContainer.parentNode) {
1281
- if (self.config.static && self.calendarContainer.parentNode) {
1282
- const wrapper = self.calendarContainer.parentNode;
1283
- wrapper.lastChild && wrapper.removeChild(wrapper.lastChild);
1284
- if (wrapper.parentNode) {
1285
- while (wrapper.firstChild)
1286
- wrapper.parentNode.insertBefore(wrapper.firstChild, wrapper);
1287
- wrapper.parentNode.removeChild(wrapper);
1288
- }
1289
- }
1290
- else
1291
- self.calendarContainer.parentNode.removeChild(self.calendarContainer);
1292
- }
1293
- if (self.altInput) {
1294
- self.input.type = "text";
1295
- if (self.altInput.parentNode)
1296
- self.altInput.parentNode.removeChild(self.altInput);
1297
- delete self.altInput;
1298
- }
1299
- if (self.input) {
1300
- self.input.type = self.input._type;
1301
- self.input.classList.remove("flatpickr-input");
1302
- self.input.removeAttribute("readonly");
1303
- }
1304
- [
1305
- "_showTimeInput",
1306
- "latestSelectedDateObj",
1307
- "_hideNextMonthArrow",
1308
- "_hidePrevMonthArrow",
1309
- "__hideNextMonthArrow",
1310
- "__hidePrevMonthArrow",
1311
- "isMobile",
1312
- "isOpen",
1313
- "selectedDateElem",
1314
- "minDateHasTime",
1315
- "maxDateHasTime",
1316
- "days",
1317
- "daysContainer",
1318
- "_input",
1319
- "_positionElement",
1320
- "innerContainer",
1321
- "rContainer",
1322
- "monthNav",
1323
- "todayDateElem",
1324
- "calendarContainer",
1325
- "weekdayContainer",
1326
- "prevMonthNav",
1327
- "nextMonthNav",
1328
- "monthsDropdownContainer",
1329
- "currentMonthElement",
1330
- "currentYearElement",
1331
- "navigationCurrentMonth",
1332
- "selectedDateElem",
1333
- "config",
1334
- ].forEach((k) => {
1335
- try {
1336
- delete self[k];
1337
- }
1338
- catch (_) { }
1339
- });
1340
- }
1341
- function isCalendarElem(elem) {
1342
- if (self.config.appendTo && self.config.appendTo.contains(elem))
1343
- return true;
1344
- return self.calendarContainer.contains(elem);
1345
- }
1346
- function documentClick(e) {
1347
- if (self.isOpen && !self.config.inline) {
1348
- const eventTarget = getEventTarget(e);
1349
- const isCalendarElement = isCalendarElem(eventTarget);
1350
- const isInput = eventTarget === self.input ||
1351
- eventTarget === self.altInput ||
1352
- self.element.contains(eventTarget) ||
1353
- (e.path &&
1354
- e.path.indexOf &&
1355
- (~e.path.indexOf(self.input) ||
1356
- ~e.path.indexOf(self.altInput)));
1357
- const lostFocus = e.type === "blur"
1358
- ? isInput &&
1359
- e.relatedTarget &&
1360
- !isCalendarElem(e.relatedTarget)
1361
- : !isInput &&
1362
- !isCalendarElement &&
1363
- !isCalendarElem(e.relatedTarget);
1364
- const isIgnored = !self.config.ignoredFocusElements.some((elem) => elem.contains(eventTarget));
1365
- if (lostFocus && isIgnored) {
1366
- if (self.timeContainer !== undefined &&
1367
- self.minuteElement !== undefined &&
1368
- self.hourElement !== undefined &&
1369
- self.input.value !== "" &&
1370
- self.input.value !== undefined) {
1371
- updateTime();
1372
- }
1373
- self.close();
1374
- if (self.config &&
1375
- self.config.mode === "range" &&
1376
- self.selectedDates.length === 1) {
1377
- self.clear(false);
1378
- self.redraw();
1379
- }
1380
- }
1381
- }
1382
- }
1383
- function changeYear(newYear) {
1384
- if (!newYear ||
1385
- (self.config.minDate && newYear < self.config.minDate.getFullYear()) ||
1386
- (self.config.maxDate && newYear > self.config.maxDate.getFullYear()))
1387
- return;
1388
- const newYearNum = newYear, isNewYear = self.currentYear !== newYearNum;
1389
- self.currentYear = newYearNum || self.currentYear;
1390
- if (self.config.maxDate &&
1391
- self.currentYear === self.config.maxDate.getFullYear()) {
1392
- self.currentMonth = Math.min(self.config.maxDate.getMonth(), self.currentMonth);
1393
- }
1394
- else if (self.config.minDate &&
1395
- self.currentYear === self.config.minDate.getFullYear()) {
1396
- self.currentMonth = Math.max(self.config.minDate.getMonth(), self.currentMonth);
1397
- }
1398
- if (isNewYear) {
1399
- self.redraw();
1400
- triggerEvent("onYearChange");
1401
- buildMonthSwitch();
1402
- }
1403
- }
1404
- function isEnabled(date, timeless = true) {
1405
- var _a;
1406
- const dateToCheck = self.parseDate(date, undefined, timeless);
1407
- if ((self.config.minDate &&
1408
- dateToCheck &&
1409
- compareDates(dateToCheck, self.config.minDate, timeless !== undefined ? timeless : !self.minDateHasTime) < 0) ||
1410
- (self.config.maxDate &&
1411
- dateToCheck &&
1412
- compareDates(dateToCheck, self.config.maxDate, timeless !== undefined ? timeless : !self.maxDateHasTime) > 0))
1413
- return false;
1414
- if (!self.config.enable && self.config.disable.length === 0)
1415
- return true;
1416
- if (dateToCheck === undefined)
1417
- return false;
1418
- const bool = !!self.config.enable, array = (_a = self.config.enable) !== null && _a !== void 0 ? _a : self.config.disable;
1419
- for (let i = 0, d; i < array.length; i++) {
1420
- d = array[i];
1421
- if (typeof d === "function" &&
1422
- d(dateToCheck))
1423
- return bool;
1424
- else if (d instanceof Date &&
1425
- dateToCheck !== undefined &&
1426
- d.getTime() === dateToCheck.getTime())
1427
- return bool;
1428
- else if (typeof d === "string") {
1429
- const parsed = self.parseDate(d, undefined, true);
1430
- return parsed && parsed.getTime() === dateToCheck.getTime()
1431
- ? bool
1432
- : !bool;
1433
- }
1434
- else if (typeof d === "object" &&
1435
- dateToCheck !== undefined &&
1436
- d.from &&
1437
- d.to &&
1438
- dateToCheck.getTime() >= d.from.getTime() &&
1439
- dateToCheck.getTime() <= d.to.getTime())
1440
- return bool;
1441
- }
1442
- return !bool;
1443
- }
1444
- function isInView(elem) {
1445
- if (self.daysContainer !== undefined)
1446
- return (elem.className.indexOf("hidden") === -1 &&
1447
- elem.className.indexOf("flatpickr-disabled") === -1 &&
1448
- self.daysContainer.contains(elem));
1449
- return false;
1450
- }
1451
- function onBlur(e) {
1452
- const isInput = e.target === self._input;
1453
- if (isInput &&
1454
- (self.selectedDates.length > 0 || self._input.value.length > 0) &&
1455
- !(e.relatedTarget && isCalendarElem(e.relatedTarget))) {
1456
- self.setDate(self._input.value, true, e.target === self.altInput
1457
- ? self.config.altFormat
1458
- : self.config.dateFormat);
1459
- }
1460
- }
1461
- function onKeyDown(e) {
1462
- const eventTarget = getEventTarget(e);
1463
- const isInput = self.config.wrap
1464
- ? element.contains(eventTarget)
1465
- : eventTarget === self._input;
1466
- const allowInput = self.config.allowInput;
1467
- const allowKeydown = self.isOpen && (!allowInput || !isInput);
1468
- const allowInlineKeydown = self.config.inline && isInput && !allowInput;
1469
- if (e.keyCode === 13 && isInput) {
1470
- if (allowInput) {
1471
- self.setDate(self._input.value, true, eventTarget === self.altInput
1472
- ? self.config.altFormat
1473
- : self.config.dateFormat);
1474
- return eventTarget.blur();
1475
- }
1476
- else {
1477
- self.open();
1478
- }
1479
- }
1480
- else if (isCalendarElem(eventTarget) ||
1481
- allowKeydown ||
1482
- allowInlineKeydown) {
1483
- const isTimeObj = !!self.timeContainer &&
1484
- self.timeContainer.contains(eventTarget);
1485
- switch (e.keyCode) {
1486
- case 13:
1487
- if (isTimeObj) {
1488
- e.preventDefault();
1489
- updateTime();
1490
- focusAndClose();
1491
- }
1492
- else
1493
- selectDate(e);
1494
- break;
1495
- case 27:
1496
- e.preventDefault();
1497
- focusAndClose();
1498
- break;
1499
- case 8:
1500
- case 46:
1501
- if (isInput && !self.config.allowInput) {
1502
- e.preventDefault();
1503
- self.clear();
1504
- }
1505
- break;
1506
- case 37:
1507
- case 39:
1508
- if (!isTimeObj && !isInput) {
1509
- e.preventDefault();
1510
- if (self.daysContainer !== undefined &&
1511
- (allowInput === false ||
1512
- (document.activeElement && isInView(document.activeElement)))) {
1513
- const delta = e.keyCode === 39 ? 1 : -1;
1514
- if (!e.ctrlKey)
1515
- focusOnDay(undefined, delta);
1516
- else {
1517
- e.stopPropagation();
1518
- changeMonth(delta);
1519
- focusOnDay(getFirstAvailableDay(1), 0);
1520
- }
1521
- }
1522
- }
1523
- else if (self.hourElement)
1524
- self.hourElement.focus();
1525
- break;
1526
- case 38:
1527
- case 40:
1528
- e.preventDefault();
1529
- const delta = e.keyCode === 40 ? 1 : -1;
1530
- if ((self.daysContainer &&
1531
- eventTarget.$i !== undefined) ||
1532
- eventTarget === self.input ||
1533
- eventTarget === self.altInput) {
1534
- if (e.ctrlKey) {
1535
- e.stopPropagation();
1536
- changeYear(self.currentYear - delta);
1537
- focusOnDay(getFirstAvailableDay(1), 0);
1538
- }
1539
- else if (!isTimeObj)
1540
- focusOnDay(undefined, delta * 7);
1541
- }
1542
- else if (eventTarget === self.currentYearElement) {
1543
- changeYear(self.currentYear - delta);
1544
- }
1545
- else if (self.config.enableTime) {
1546
- if (!isTimeObj && self.hourElement)
1547
- self.hourElement.focus();
1548
- updateTime(e);
1549
- self._debouncedChange();
1550
- }
1551
- break;
1552
- case 9:
1553
- if (isTimeObj) {
1554
- const elems = [
1555
- self.hourElement,
1556
- self.minuteElement,
1557
- self.secondElement,
1558
- self.amPM,
1559
- ]
1560
- .concat(self.pluginElements)
1561
- .filter((x) => x);
1562
- const i = elems.indexOf(eventTarget);
1563
- if (i !== -1) {
1564
- const target = elems[i + (e.shiftKey ? -1 : 1)];
1565
- e.preventDefault();
1566
- (target || self._input).focus();
1567
- }
1568
- }
1569
- else if (!self.config.noCalendar &&
1570
- self.daysContainer &&
1571
- self.daysContainer.contains(eventTarget) &&
1572
- e.shiftKey) {
1573
- e.preventDefault();
1574
- self._input.focus();
1575
- }
1576
- break;
1577
- }
1578
- }
1579
- if (self.amPM !== undefined && eventTarget === self.amPM) {
1580
- switch (e.key) {
1581
- case self.l10n.amPM[0].charAt(0):
1582
- case self.l10n.amPM[0].charAt(0).toLowerCase():
1583
- self.amPM.textContent = self.l10n.amPM[0];
1584
- setHoursFromInputs();
1585
- updateValue();
1586
- break;
1587
- case self.l10n.amPM[1].charAt(0):
1588
- case self.l10n.amPM[1].charAt(0).toLowerCase():
1589
- self.amPM.textContent = self.l10n.amPM[1];
1590
- setHoursFromInputs();
1591
- updateValue();
1592
- break;
1593
- }
1594
- }
1595
- if (isInput || isCalendarElem(eventTarget)) {
1596
- triggerEvent("onKeyDown", e);
1597
- }
1598
- }
1599
- function onMouseOver(elem) {
1600
- if (self.selectedDates.length !== 1 ||
1601
- (elem &&
1602
- (!elem.classList.contains("flatpickr-day") ||
1603
- elem.classList.contains("flatpickr-disabled"))))
1604
- return;
1605
- const hoverDate = elem
1606
- ? elem.dateObj.getTime()
1607
- : self.days.firstElementChild.dateObj.getTime(), initialDate = self.parseDate(self.selectedDates[0], undefined, true).getTime(), rangeStartDate = Math.min(hoverDate, self.selectedDates[0].getTime()), rangeEndDate = Math.max(hoverDate, self.selectedDates[0].getTime());
1608
- let containsDisabled = false;
1609
- let minRange = 0, maxRange = 0;
1610
- for (let t = rangeStartDate; t < rangeEndDate; t += duration.DAY) {
1611
- if (!isEnabled(new Date(t), true)) {
1612
- containsDisabled =
1613
- containsDisabled || (t > rangeStartDate && t < rangeEndDate);
1614
- if (t < initialDate && (!minRange || t > minRange))
1615
- minRange = t;
1616
- else if (t > initialDate && (!maxRange || t < maxRange))
1617
- maxRange = t;
1618
- }
1619
- }
1620
- for (let m = 0; m < self.config.showMonths; m++) {
1621
- const month = self.daysContainer.children[m];
1622
- for (let i = 0, l = month.children.length; i < l; i++) {
1623
- const dayElem = month.children[i], date = dayElem.dateObj;
1624
- const timestamp = date.getTime();
1625
- const outOfRange = (minRange > 0 && timestamp < minRange) ||
1626
- (maxRange > 0 && timestamp > maxRange);
1627
- if (outOfRange) {
1628
- dayElem.classList.add("notAllowed");
1629
- ["inRange", "startRange", "endRange"].forEach((c) => {
1630
- dayElem.classList.remove(c);
1631
- });
1632
- continue;
1633
- }
1634
- else if (containsDisabled && !outOfRange)
1635
- continue;
1636
- ["startRange", "inRange", "endRange", "notAllowed"].forEach((c) => {
1637
- dayElem.classList.remove(c);
1638
- });
1639
- if (elem !== undefined) {
1640
- elem.classList.add(hoverDate <= self.selectedDates[0].getTime()
1641
- ? "startRange"
1642
- : "endRange");
1643
- if (initialDate < hoverDate && timestamp === initialDate)
1644
- dayElem.classList.add("startRange");
1645
- else if (initialDate > hoverDate && timestamp === initialDate)
1646
- dayElem.classList.add("endRange");
1647
- if (timestamp >= minRange &&
1648
- (maxRange === 0 || timestamp <= maxRange) &&
1649
- isBetween(timestamp, initialDate, hoverDate))
1650
- dayElem.classList.add("inRange");
1651
- }
1652
- }
1653
- }
1654
- }
1655
- function onResize() {
1656
- if (self.isOpen && !self.config.static && !self.config.inline)
1657
- positionCalendar();
1658
- }
1659
- function open(e, positionElement = self._positionElement) {
1660
- if (self.isMobile === true) {
1661
- if (e) {
1662
- e.preventDefault();
1663
- const eventTarget = getEventTarget(e);
1664
- if (eventTarget) {
1665
- eventTarget.blur();
1666
- }
1667
- }
1668
- if (self.mobileInput !== undefined) {
1669
- self.mobileInput.focus();
1670
- self.mobileInput.click();
1671
- }
1672
- triggerEvent("onOpen");
1673
- return;
1674
- }
1675
- else if (self._input.disabled || self.config.inline) {
1676
- return;
1677
- }
1678
- const wasOpen = self.isOpen;
1679
- self.isOpen = true;
1680
- if (!wasOpen) {
1681
- self.calendarContainer.classList.add("open");
1682
- self._input.classList.add("active");
1683
- triggerEvent("onOpen");
1684
- positionCalendar(positionElement);
1685
- }
1686
- if (self.config.enableTime === true && self.config.noCalendar === true) {
1687
- if (self.config.allowInput === false &&
1688
- (e === undefined ||
1689
- !self.timeContainer.contains(e.relatedTarget))) {
1690
- setTimeout(() => self.hourElement.select(), 50);
1691
- }
1692
- }
1693
- }
1694
- function minMaxDateSetter(type) {
1695
- return (date) => {
1696
- const dateObj = (self.config[`_${type}Date`] = self.parseDate(date, self.config.dateFormat));
1697
- const inverseDateObj = self.config[`_${type === "min" ? "max" : "min"}Date`];
1698
- if (dateObj !== undefined) {
1699
- self[type === "min" ? "minDateHasTime" : "maxDateHasTime"] =
1700
- dateObj.getHours() > 0 ||
1701
- dateObj.getMinutes() > 0 ||
1702
- dateObj.getSeconds() > 0;
1703
- }
1704
- if (self.selectedDates) {
1705
- self.selectedDates = self.selectedDates.filter((d) => isEnabled(d));
1706
- if (!self.selectedDates.length && type === "min")
1707
- setHoursFromDate(dateObj);
1708
- updateValue();
1709
- }
1710
- if (self.daysContainer) {
1711
- redraw();
1712
- if (dateObj !== undefined)
1713
- self.currentYearElement[type] = dateObj.getFullYear().toString();
1714
- else
1715
- self.currentYearElement.removeAttribute(type);
1716
- self.currentYearElement.disabled =
1717
- !!inverseDateObj &&
1718
- dateObj !== undefined &&
1719
- inverseDateObj.getFullYear() === dateObj.getFullYear();
1720
- }
1721
- };
1722
- }
1723
- function parseConfig() {
1724
- const boolOpts = [
1725
- "wrap",
1726
- "weekNumbers",
1727
- "allowInput",
1728
- "allowInvalidPreload",
1729
- "clickOpens",
1730
- "time_24hr",
1731
- "enableTime",
1732
- "noCalendar",
1733
- "altInput",
1734
- "shorthandCurrentMonth",
1735
- "inline",
1736
- "static",
1737
- "enableSeconds",
1738
- "disableMobile",
1739
- ];
1740
- const userConfig = Object.assign(Object.assign({}, JSON.parse(JSON.stringify(element.dataset || {}))), instanceConfig);
1741
- const formats = {};
1742
- self.config.parseDate = userConfig.parseDate;
1743
- self.config.formatDate = userConfig.formatDate;
1744
- Object.defineProperty(self.config, "enable", {
1745
- get: () => self.config._enable,
1746
- set: (dates) => {
1747
- self.config._enable = parseDateRules(dates);
1748
- },
1749
- });
1750
- Object.defineProperty(self.config, "disable", {
1751
- get: () => self.config._disable,
1752
- set: (dates) => {
1753
- self.config._disable = parseDateRules(dates);
1754
- },
1755
- });
1756
- const timeMode = userConfig.mode === "time";
1757
- if (!userConfig.dateFormat && (userConfig.enableTime || timeMode)) {
1758
- const defaultDateFormat = flatpickr.defaultConfig.dateFormat || defaults.dateFormat;
1759
- formats.dateFormat =
1760
- userConfig.noCalendar || timeMode
1761
- ? "H:i" + (userConfig.enableSeconds ? ":S" : "")
1762
- : defaultDateFormat + " H:i" + (userConfig.enableSeconds ? ":S" : "");
1763
- }
1764
- if (userConfig.altInput &&
1765
- (userConfig.enableTime || timeMode) &&
1766
- !userConfig.altFormat) {
1767
- const defaultAltFormat = flatpickr.defaultConfig.altFormat || defaults.altFormat;
1768
- formats.altFormat =
1769
- userConfig.noCalendar || timeMode
1770
- ? "h:i" + (userConfig.enableSeconds ? ":S K" : " K")
1771
- : defaultAltFormat + ` h:i${userConfig.enableSeconds ? ":S" : ""} K`;
1772
- }
1773
- Object.defineProperty(self.config, "minDate", {
1774
- get: () => self.config._minDate,
1775
- set: minMaxDateSetter("min"),
1776
- });
1777
- Object.defineProperty(self.config, "maxDate", {
1778
- get: () => self.config._maxDate,
1779
- set: minMaxDateSetter("max"),
1780
- });
1781
- const minMaxTimeSetter = (type) => (val) => {
1782
- self.config[type === "min" ? "_minTime" : "_maxTime"] = self.parseDate(val, "H:i:S");
1783
- };
1784
- Object.defineProperty(self.config, "minTime", {
1785
- get: () => self.config._minTime,
1786
- set: minMaxTimeSetter("min"),
1787
- });
1788
- Object.defineProperty(self.config, "maxTime", {
1789
- get: () => self.config._maxTime,
1790
- set: minMaxTimeSetter("max"),
1791
- });
1792
- if (userConfig.mode === "time") {
1793
- self.config.noCalendar = true;
1794
- self.config.enableTime = true;
1795
- }
1796
- Object.assign(self.config, formats, userConfig);
1797
- for (let i = 0; i < boolOpts.length; i++)
1798
- self.config[boolOpts[i]] =
1799
- self.config[boolOpts[i]] === true ||
1800
- self.config[boolOpts[i]] === "true";
1801
- HOOKS.filter((hook) => self.config[hook] !== undefined).forEach((hook) => {
1802
- self.config[hook] = arrayify(self.config[hook] || []).map(bindToInstance);
1803
- });
1804
- self.isMobile =
1805
- !self.config.disableMobile &&
1806
- !self.config.inline &&
1807
- self.config.mode === "single" &&
1808
- !self.config.disable.length &&
1809
- !self.config.enable &&
1810
- !self.config.weekNumbers &&
1811
- /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1812
- for (let i = 0; i < self.config.plugins.length; i++) {
1813
- const pluginConf = self.config.plugins[i](self) || {};
1814
- for (const key in pluginConf) {
1815
- if (HOOKS.indexOf(key) > -1) {
1816
- self.config[key] = arrayify(pluginConf[key])
1817
- .map(bindToInstance)
1818
- .concat(self.config[key]);
1819
- }
1820
- else if (typeof userConfig[key] === "undefined")
1821
- self.config[key] = pluginConf[key];
1822
- }
1823
- }
1824
- if (!userConfig.altInputClass) {
1825
- self.config.altInputClass =
1826
- getInputElem().className + " " + self.config.altInputClass;
1827
- }
1828
- triggerEvent("onParseConfig");
1829
- }
1830
- function getInputElem() {
1831
- return self.config.wrap
1832
- ? element.querySelector("[data-input]")
1833
- : element;
1834
- }
1835
- function setupLocale() {
1836
- if (typeof self.config.locale !== "object" &&
1837
- typeof flatpickr.l10ns[self.config.locale] === "undefined")
1838
- self.config.errorHandler(new Error(`flatpickr: invalid locale ${self.config.locale}`));
1839
- self.l10n = Object.assign(Object.assign({}, flatpickr.l10ns.default), (typeof self.config.locale === "object"
1840
- ? self.config.locale
1841
- : self.config.locale !== "default"
1842
- ? flatpickr.l10ns[self.config.locale]
1843
- : undefined));
1844
- tokenRegex.K = `(${self.l10n.amPM[0]}|${self.l10n.amPM[1]}|${self.l10n.amPM[0].toLowerCase()}|${self.l10n.amPM[1].toLowerCase()})`;
1845
- const userConfig = Object.assign(Object.assign({}, instanceConfig), JSON.parse(JSON.stringify(element.dataset || {})));
1846
- if (userConfig.time_24hr === undefined &&
1847
- flatpickr.defaultConfig.time_24hr === undefined) {
1848
- self.config.time_24hr = self.l10n.time_24hr;
1849
- }
1850
- self.formatDate = createDateFormatter(self);
1851
- self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
1852
- }
1853
- function positionCalendar(customPositionElement) {
1854
- if (typeof self.config.position === "function") {
1855
- return void self.config.position(self, customPositionElement);
1856
- }
1857
- if (self.calendarContainer === undefined)
1858
- return;
1859
- triggerEvent("onPreCalendarPosition");
1860
- const positionElement = customPositionElement || self._positionElement;
1861
- const calendarHeight = Array.prototype.reduce.call(self.calendarContainer.children, ((acc, child) => acc + child.offsetHeight), 0), calendarWidth = self.calendarContainer.offsetWidth, configPos = self.config.position.split(" "), configPosVertical = configPos[0], configPosHorizontal = configPos.length > 1 ? configPos[1] : null, inputBounds = positionElement.getBoundingClientRect(), distanceFromBottom = window.innerHeight - inputBounds.bottom, showOnTop = configPosVertical === "above" ||
1862
- (configPosVertical !== "below" &&
1863
- distanceFromBottom < calendarHeight &&
1864
- inputBounds.top > calendarHeight);
1865
- const top = window.pageYOffset +
1866
- inputBounds.top +
1867
- (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);
1868
- toggleClass(self.calendarContainer, "arrowTop", !showOnTop);
1869
- toggleClass(self.calendarContainer, "arrowBottom", showOnTop);
1870
- if (self.config.inline)
1871
- return;
1872
- let left = window.pageXOffset + inputBounds.left;
1873
- let isCenter = false;
1874
- let isRight = false;
1875
- if (configPosHorizontal === "center") {
1876
- left -= (calendarWidth - inputBounds.width) / 2;
1877
- isCenter = true;
1878
- }
1879
- else if (configPosHorizontal === "right") {
1880
- left -= calendarWidth - inputBounds.width;
1881
- isRight = true;
1882
- }
1883
- toggleClass(self.calendarContainer, "arrowLeft", !isCenter && !isRight);
1884
- toggleClass(self.calendarContainer, "arrowCenter", isCenter);
1885
- toggleClass(self.calendarContainer, "arrowRight", isRight);
1886
- const right = window.document.body.offsetWidth -
1887
- (window.pageXOffset + inputBounds.right);
1888
- const rightMost = left + calendarWidth > window.document.body.offsetWidth;
1889
- const centerMost = right + calendarWidth > window.document.body.offsetWidth;
1890
- toggleClass(self.calendarContainer, "rightMost", rightMost);
1891
- if (self.config.static)
1892
- return;
1893
- self.calendarContainer.style.top = `${top}px`;
1894
- if (!rightMost) {
1895
- self.calendarContainer.style.left = `${left}px`;
1896
- self.calendarContainer.style.right = "auto";
1897
- }
1898
- else if (!centerMost) {
1899
- self.calendarContainer.style.left = "auto";
1900
- self.calendarContainer.style.right = `${right}px`;
1901
- }
1902
- else {
1903
- const doc = getDocumentStyleSheet();
1904
- if (doc === undefined)
1905
- return;
1906
- const bodyWidth = window.document.body.offsetWidth;
1907
- const centerLeft = Math.max(0, bodyWidth / 2 - calendarWidth / 2);
1908
- const centerBefore = ".flatpickr-calendar.centerMost:before";
1909
- const centerAfter = ".flatpickr-calendar.centerMost:after";
1910
- const centerIndex = doc.cssRules.length;
1911
- const centerStyle = `{left:${inputBounds.left}px;right:auto;}`;
1912
- toggleClass(self.calendarContainer, "rightMost", false);
1913
- toggleClass(self.calendarContainer, "centerMost", true);
1914
- doc.insertRule(`${centerBefore},${centerAfter}${centerStyle}`, centerIndex);
1915
- self.calendarContainer.style.left = `${centerLeft}px`;
1916
- self.calendarContainer.style.right = "auto";
1917
- }
1918
- }
1919
- function getDocumentStyleSheet() {
1920
- let editableSheet = null;
1921
- for (let i = 0; i < document.styleSheets.length; i++) {
1922
- const sheet = document.styleSheets[i];
1923
- editableSheet = sheet;
1924
- break;
1925
- }
1926
- return editableSheet != null ? editableSheet : createStyleSheet();
1927
- }
1928
- function createStyleSheet() {
1929
- const style = document.createElement("style");
1930
- document.head.appendChild(style);
1931
- return style.sheet;
1932
- }
1933
- function redraw() {
1934
- if (self.config.noCalendar || self.isMobile)
1935
- return;
1936
- buildMonthSwitch();
1937
- updateNavigationCurrentMonth();
1938
- buildDays();
1939
- }
1940
- function focusAndClose() {
1941
- self._input.focus();
1942
- if (window.navigator.userAgent.indexOf("MSIE") !== -1 ||
1943
- navigator.msMaxTouchPoints !== undefined) {
1944
- setTimeout(self.close, 0);
1945
- }
1946
- else {
1947
- self.close();
1948
- }
1949
- }
1950
- function selectDate(e) {
1951
- e.preventDefault();
1952
- e.stopPropagation();
1953
- const isSelectable = (day) => day.classList &&
1954
- day.classList.contains("flatpickr-day") &&
1955
- !day.classList.contains("flatpickr-disabled") &&
1956
- !day.classList.contains("notAllowed");
1957
- const t = findParent(getEventTarget(e), isSelectable);
1958
- if (t === undefined)
1959
- return;
1960
- const target = t;
1961
- const selectedDate = (self.latestSelectedDateObj = new Date(target.dateObj.getTime()));
1962
- const shouldChangeMonth = (selectedDate.getMonth() < self.currentMonth ||
1963
- selectedDate.getMonth() >
1964
- self.currentMonth + self.config.showMonths - 1) &&
1965
- self.config.mode !== "range";
1966
- self.selectedDateElem = target;
1967
- if (self.config.mode === "single")
1968
- self.selectedDates = [selectedDate];
1969
- else if (self.config.mode === "multiple") {
1970
- const selectedIndex = isDateSelected(selectedDate);
1971
- if (selectedIndex)
1972
- self.selectedDates.splice(parseInt(selectedIndex), 1);
1973
- else
1974
- self.selectedDates.push(selectedDate);
1975
- }
1976
- else if (self.config.mode === "range") {
1977
- if (self.selectedDates.length === 2) {
1978
- self.clear(false, false);
1979
- }
1980
- self.latestSelectedDateObj = selectedDate;
1981
- self.selectedDates.push(selectedDate);
1982
- if (compareDates(selectedDate, self.selectedDates[0], true) !== 0)
1983
- self.selectedDates.sort((a, b) => a.getTime() - b.getTime());
1984
- }
1985
- setHoursFromInputs();
1986
- if (shouldChangeMonth) {
1987
- const isNewYear = self.currentYear !== selectedDate.getFullYear();
1988
- self.currentYear = selectedDate.getFullYear();
1989
- self.currentMonth = selectedDate.getMonth();
1990
- if (isNewYear) {
1991
- triggerEvent("onYearChange");
1992
- buildMonthSwitch();
1993
- }
1994
- triggerEvent("onMonthChange");
1995
- }
1996
- updateNavigationCurrentMonth();
1997
- buildDays();
1998
- updateValue();
1999
- if (!shouldChangeMonth &&
2000
- self.config.mode !== "range" &&
2001
- self.config.showMonths === 1)
2002
- focusOnDayElem(target);
2003
- else if (self.selectedDateElem !== undefined &&
2004
- self.hourElement === undefined) {
2005
- self.selectedDateElem && self.selectedDateElem.focus();
2006
- }
2007
- if (self.hourElement !== undefined)
2008
- self.hourElement !== undefined && self.hourElement.focus();
2009
- if (self.config.closeOnSelect) {
2010
- const single = self.config.mode === "single" && !self.config.enableTime;
2011
- const range = self.config.mode === "range" &&
2012
- self.selectedDates.length === 2 &&
2013
- !self.config.enableTime;
2014
- if (single || range) {
2015
- focusAndClose();
2016
- }
2017
- }
2018
- triggerChange();
2019
- }
2020
- const CALLBACKS = {
2021
- locale: [setupLocale, updateWeekdays],
2022
- showMonths: [buildMonths, setCalendarWidth, buildWeekdays],
2023
- minDate: [jumpToDate],
2024
- maxDate: [jumpToDate],
2025
- clickOpens: [
2026
- () => {
2027
- if (self.config.clickOpens === true) {
2028
- bind(self._input, "focus", self.open);
2029
- bind(self._input, "click", self.open);
2030
- }
2031
- else {
2032
- self._input.removeEventListener("focus", self.open);
2033
- self._input.removeEventListener("click", self.open);
2034
- }
2035
- },
2036
- ],
2037
- };
2038
- function set(option, value) {
2039
- if (option !== null && typeof option === "object") {
2040
- Object.assign(self.config, option);
2041
- for (const key in option) {
2042
- if (CALLBACKS[key] !== undefined)
2043
- CALLBACKS[key].forEach((x) => x());
2044
- }
2045
- }
2046
- else {
2047
- self.config[option] = value;
2048
- if (CALLBACKS[option] !== undefined)
2049
- CALLBACKS[option].forEach((x) => x());
2050
- else if (HOOKS.indexOf(option) > -1)
2051
- self.config[option] = arrayify(value);
2052
- }
2053
- self.redraw();
2054
- updateValue(true);
2055
- }
2056
- function setSelectedDate(inputDate, format) {
2057
- let dates = [];
2058
- if (inputDate instanceof Array)
2059
- dates = inputDate.map((d) => self.parseDate(d, format));
2060
- else if (inputDate instanceof Date || typeof inputDate === "number")
2061
- dates = [self.parseDate(inputDate, format)];
2062
- else if (typeof inputDate === "string") {
2063
- switch (self.config.mode) {
2064
- case "single":
2065
- case "time":
2066
- dates = [self.parseDate(inputDate, format)];
2067
- break;
2068
- case "multiple":
2069
- dates = inputDate
2070
- .split(self.config.conjunction)
2071
- .map((date) => self.parseDate(date, format));
2072
- break;
2073
- case "range":
2074
- dates = inputDate
2075
- .split(self.l10n.rangeSeparator)
2076
- .map((date) => self.parseDate(date, format));
2077
- break;
2078
- }
2079
- }
2080
- else
2081
- self.config.errorHandler(new Error(`Invalid date supplied: ${JSON.stringify(inputDate)}`));
2082
- self.selectedDates = (self.config.allowInvalidPreload
2083
- ? dates
2084
- : dates.filter((d) => d instanceof Date && isEnabled(d, false)));
2085
- if (self.config.mode === "range")
2086
- self.selectedDates.sort((a, b) => a.getTime() - b.getTime());
2087
- }
2088
- function setDate(date, triggerChange = false, format = self.config.dateFormat) {
2089
- if ((date !== 0 && !date) || (date instanceof Array && date.length === 0))
2090
- return self.clear(triggerChange);
2091
- setSelectedDate(date, format);
2092
- self.latestSelectedDateObj =
2093
- self.selectedDates[self.selectedDates.length - 1];
2094
- self.redraw();
2095
- jumpToDate(undefined, triggerChange);
2096
- setHoursFromDate();
2097
- if (self.selectedDates.length === 0) {
2098
- self.clear(false);
2099
- }
2100
- updateValue(triggerChange);
2101
- if (triggerChange)
2102
- triggerEvent("onChange");
2103
- }
2104
- function parseDateRules(arr) {
2105
- return arr
2106
- .slice()
2107
- .map((rule) => {
2108
- if (typeof rule === "string" ||
2109
- typeof rule === "number" ||
2110
- rule instanceof Date) {
2111
- return self.parseDate(rule, undefined, true);
2112
- }
2113
- else if (rule &&
2114
- typeof rule === "object" &&
2115
- rule.from &&
2116
- rule.to)
2117
- return {
2118
- from: self.parseDate(rule.from, undefined),
2119
- to: self.parseDate(rule.to, undefined),
2120
- };
2121
- return rule;
2122
- })
2123
- .filter((x) => x);
2124
- }
2125
- function setupDates() {
2126
- self.selectedDates = [];
2127
- self.now = self.parseDate(self.config.now) || new Date();
2128
- const preloadedDate = self.config.defaultDate ||
2129
- ((self.input.nodeName === "INPUT" ||
2130
- self.input.nodeName === "TEXTAREA") &&
2131
- self.input.placeholder &&
2132
- self.input.value === self.input.placeholder
2133
- ? null
2134
- : self.input.value);
2135
- if (preloadedDate)
2136
- setSelectedDate(preloadedDate, self.config.dateFormat);
2137
- self._initialDate =
2138
- self.selectedDates.length > 0
2139
- ? self.selectedDates[0]
2140
- : self.config.minDate &&
2141
- self.config.minDate.getTime() > self.now.getTime()
2142
- ? self.config.minDate
2143
- : self.config.maxDate &&
2144
- self.config.maxDate.getTime() < self.now.getTime()
2145
- ? self.config.maxDate
2146
- : self.now;
2147
- self.currentYear = self._initialDate.getFullYear();
2148
- self.currentMonth = self._initialDate.getMonth();
2149
- if (self.selectedDates.length > 0)
2150
- self.latestSelectedDateObj = self.selectedDates[0];
2151
- if (self.config.minTime !== undefined)
2152
- self.config.minTime = self.parseDate(self.config.minTime, "H:i");
2153
- if (self.config.maxTime !== undefined)
2154
- self.config.maxTime = self.parseDate(self.config.maxTime, "H:i");
2155
- self.minDateHasTime =
2156
- !!self.config.minDate &&
2157
- (self.config.minDate.getHours() > 0 ||
2158
- self.config.minDate.getMinutes() > 0 ||
2159
- self.config.minDate.getSeconds() > 0);
2160
- self.maxDateHasTime =
2161
- !!self.config.maxDate &&
2162
- (self.config.maxDate.getHours() > 0 ||
2163
- self.config.maxDate.getMinutes() > 0 ||
2164
- self.config.maxDate.getSeconds() > 0);
2165
- }
2166
- function setupInputs() {
2167
- self.input = getInputElem();
2168
- if (!self.input) {
2169
- self.config.errorHandler(new Error("Invalid input element specified"));
2170
- return;
2171
- }
2172
- self.input._type = self.input.type;
2173
- self.input.type = "text";
2174
- self.input.classList.add("flatpickr-input");
2175
- self._input = self.input;
2176
- if (self.config.altInput) {
2177
- self.altInput = createElement(self.input.nodeName, self.config.altInputClass);
2178
- self._input = self.altInput;
2179
- self.altInput.placeholder = self.input.placeholder;
2180
- self.altInput.disabled = self.input.disabled;
2181
- self.altInput.required = self.input.required;
2182
- self.altInput.tabIndex = self.input.tabIndex;
2183
- self.altInput.type = "text";
2184
- self.input.setAttribute("type", "hidden");
2185
- if (!self.config.static && self.input.parentNode)
2186
- self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
2187
- }
2188
- if (!self.config.allowInput)
2189
- self._input.setAttribute("readonly", "readonly");
2190
- self._positionElement = self.config.positionElement || self._input;
2191
- }
2192
- function setupMobile() {
2193
- const inputType = self.config.enableTime
2194
- ? self.config.noCalendar
2195
- ? "time"
2196
- : "datetime-local"
2197
- : "date";
2198
- self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
2199
- self.mobileInput.tabIndex = 1;
2200
- self.mobileInput.type = inputType;
2201
- self.mobileInput.disabled = self.input.disabled;
2202
- self.mobileInput.required = self.input.required;
2203
- self.mobileInput.placeholder = self.input.placeholder;
2204
- self.mobileFormatStr =
2205
- inputType === "datetime-local"
2206
- ? "Y-m-d\\TH:i:S"
2207
- : inputType === "date"
2208
- ? "Y-m-d"
2209
- : "H:i:S";
2210
- if (self.selectedDates.length > 0) {
2211
- self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr);
2212
- }
2213
- if (self.config.minDate)
2214
- self.mobileInput.min = self.formatDate(self.config.minDate, "Y-m-d");
2215
- if (self.config.maxDate)
2216
- self.mobileInput.max = self.formatDate(self.config.maxDate, "Y-m-d");
2217
- if (self.input.getAttribute("step"))
2218
- self.mobileInput.step = String(self.input.getAttribute("step"));
2219
- self.input.type = "hidden";
2220
- if (self.altInput !== undefined)
2221
- self.altInput.type = "hidden";
2222
- try {
2223
- if (self.input.parentNode)
2224
- self.input.parentNode.insertBefore(self.mobileInput, self.input.nextSibling);
2225
- }
2226
- catch (_a) { }
2227
- bind(self.mobileInput, "change", (e) => {
2228
- self.setDate(getEventTarget(e).value, false, self.mobileFormatStr);
2229
- triggerEvent("onChange");
2230
- triggerEvent("onClose");
2231
- });
2232
- }
2233
- function toggle(e) {
2234
- if (self.isOpen === true)
2235
- return self.close();
2236
- self.open(e);
2237
- }
2238
- function triggerEvent(event, data) {
2239
- if (self.config === undefined)
2240
- return;
2241
- const hooks = self.config[event];
2242
- if (hooks !== undefined && hooks.length > 0) {
2243
- for (let i = 0; hooks[i] && i < hooks.length; i++)
2244
- hooks[i](self.selectedDates, self.input.value, self, data);
2245
- }
2246
- if (event === "onChange") {
2247
- self.input.dispatchEvent(createEvent("change"));
2248
- self.input.dispatchEvent(createEvent("input"));
2249
- }
2250
- }
2251
- function createEvent(name) {
2252
- const e = document.createEvent("Event");
2253
- e.initEvent(name, true, true);
2254
- return e;
2255
- }
2256
- function isDateSelected(date) {
2257
- for (let i = 0; i < self.selectedDates.length; i++) {
2258
- if (compareDates(self.selectedDates[i], date) === 0)
2259
- return "" + i;
2260
- }
2261
- return false;
2262
- }
2263
- function isDateInRange(date) {
2264
- if (self.config.mode !== "range" || self.selectedDates.length < 2)
2265
- return false;
2266
- return (compareDates(date, self.selectedDates[0]) >= 0 &&
2267
- compareDates(date, self.selectedDates[1]) <= 0);
2268
- }
2269
- function updateNavigationCurrentMonth() {
2270
- if (self.config.noCalendar || self.isMobile || !self.monthNav)
2271
- return;
2272
- self.yearElements.forEach((yearElement, i) => {
2273
- const d = new Date(self.currentYear, self.currentMonth, 1);
2274
- d.setMonth(self.currentMonth + i);
2275
- if (self.config.showMonths > 1 ||
2276
- self.config.monthSelectorType === "static") {
2277
- self.monthElements[i].textContent =
2278
- monthToStr(d.getMonth(), self.config.shorthandCurrentMonth, self.l10n) + " ";
2279
- }
2280
- else {
2281
- self.monthsDropdownContainer.value = d.getMonth().toString();
2282
- }
2283
- yearElement.value = d.getFullYear().toString();
2284
- });
2285
- self._hidePrevMonthArrow =
2286
- self.config.minDate !== undefined &&
2287
- (self.currentYear === self.config.minDate.getFullYear()
2288
- ? self.currentMonth <= self.config.minDate.getMonth()
2289
- : self.currentYear < self.config.minDate.getFullYear());
2290
- self._hideNextMonthArrow =
2291
- self.config.maxDate !== undefined &&
2292
- (self.currentYear === self.config.maxDate.getFullYear()
2293
- ? self.currentMonth + 1 > self.config.maxDate.getMonth()
2294
- : self.currentYear > self.config.maxDate.getFullYear());
2295
- }
2296
- function getDateStr(format) {
2297
- return self.selectedDates
2298
- .map((dObj) => self.formatDate(dObj, format))
2299
- .filter((d, i, arr) => self.config.mode !== "range" ||
2300
- self.config.enableTime ||
2301
- arr.indexOf(d) === i)
2302
- .join(self.config.mode !== "range"
2303
- ? self.config.conjunction
2304
- : self.l10n.rangeSeparator);
2305
- }
2306
- function updateValue(triggerChange = true) {
2307
- if (self.mobileInput !== undefined && self.mobileFormatStr) {
2308
- self.mobileInput.value =
2309
- self.latestSelectedDateObj !== undefined
2310
- ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr)
2311
- : "";
2312
- }
2313
- self.input.value = getDateStr(self.config.dateFormat);
2314
- if (self.altInput !== undefined) {
2315
- self.altInput.value = getDateStr(self.config.altFormat);
2316
- }
2317
- if (triggerChange !== false)
2318
- triggerEvent("onValueUpdate");
2319
- }
2320
- function onMonthNavClick(e) {
2321
- const eventTarget = getEventTarget(e);
2322
- const isPrevMonth = self.prevMonthNav.contains(eventTarget);
2323
- const isNextMonth = self.nextMonthNav.contains(eventTarget);
2324
- if (isPrevMonth || isNextMonth) {
2325
- changeMonth(isPrevMonth ? -1 : 1);
2326
- }
2327
- else if (self.yearElements.indexOf(eventTarget) >= 0) {
2328
- eventTarget.select();
2329
- }
2330
- else if (eventTarget.classList.contains("arrowUp")) {
2331
- self.changeYear(self.currentYear + 1);
2332
- }
2333
- else if (eventTarget.classList.contains("arrowDown")) {
2334
- self.changeYear(self.currentYear - 1);
2335
- }
2336
- }
2337
- function timeWrapper(e) {
2338
- e.preventDefault();
2339
- const isKeyDown = e.type === "keydown", eventTarget = getEventTarget(e), input = eventTarget;
2340
- if (self.amPM !== undefined && eventTarget === self.amPM) {
2341
- self.amPM.textContent =
2342
- self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2343
- }
2344
- const min = parseFloat(input.getAttribute("min")), max = parseFloat(input.getAttribute("max")), step = parseFloat(input.getAttribute("step")), curValue = parseInt(input.value, 10), delta = e.delta ||
2345
- (isKeyDown ? (e.which === 38 ? 1 : -1) : 0);
2346
- let newValue = curValue + step * delta;
2347
- if (typeof input.value !== "undefined" && input.value.length === 2) {
2348
- const isHourElem = input === self.hourElement, isMinuteElem = input === self.minuteElement;
2349
- if (newValue < min) {
2350
- newValue =
2351
- max +
2352
- newValue +
2353
- int(!isHourElem) +
2354
- (int(isHourElem) && int(!self.amPM));
2355
- if (isMinuteElem)
2356
- incrementNumInput(undefined, -1, self.hourElement);
2357
- }
2358
- else if (newValue > max) {
2359
- newValue =
2360
- input === self.hourElement ? newValue - max - int(!self.amPM) : min;
2361
- if (isMinuteElem)
2362
- incrementNumInput(undefined, 1, self.hourElement);
2363
- }
2364
- if (self.amPM &&
2365
- isHourElem &&
2366
- (step === 1
2367
- ? newValue + curValue === 23
2368
- : Math.abs(newValue - curValue) > step)) {
2369
- self.amPM.textContent =
2370
- self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2371
- }
2372
- input.value = pad(newValue);
2373
- }
2374
- }
2375
- init();
2376
- return self;
2377
- }
2378
- function _flatpickr(nodeList, config) {
2379
- const nodes = Array.prototype.slice
2380
- .call(nodeList)
2381
- .filter((x) => x instanceof HTMLElement);
2382
- const instances = [];
2383
- for (let i = 0; i < nodes.length; i++) {
2384
- const node = nodes[i];
2385
- try {
2386
- if (node.getAttribute("data-fp-omit") !== null)
2387
- continue;
2388
- if (node._flatpickr !== undefined) {
2389
- node._flatpickr.destroy();
2390
- node._flatpickr = undefined;
2391
- }
2392
- node._flatpickr = FlatpickrInstance(node, config || {});
2393
- instances.push(node._flatpickr);
2394
- }
2395
- catch (e) {
2396
- console.error(e);
2397
- }
2398
- }
2399
- return instances.length === 1 ? instances[0] : instances;
2400
- }
2401
- if (typeof HTMLElement !== "undefined" &&
2402
- typeof HTMLCollection !== "undefined" &&
2403
- typeof NodeList !== "undefined") {
2404
- HTMLCollection.prototype.flatpickr = NodeList.prototype.flatpickr = function (config) {
2405
- return _flatpickr(this, config);
2406
- };
2407
- HTMLElement.prototype.flatpickr = function (config) {
2408
- return _flatpickr([this], config);
2409
- };
2410
- }
2411
- var flatpickr = function (selector, config) {
2412
- if (typeof selector === "string") {
2413
- return _flatpickr(window.document.querySelectorAll(selector), config);
2414
- }
2415
- else if (selector instanceof Node) {
2416
- return _flatpickr([selector], config);
2417
- }
2418
- else {
2419
- return _flatpickr(selector, config);
2420
- }
2421
- };
2422
- flatpickr.defaultConfig = {};
2423
- flatpickr.l10ns = {
2424
- en: Object.assign({}, english),
2425
- default: Object.assign({}, english),
2426
- };
2427
- flatpickr.localize = (l10n) => {
2428
- flatpickr.l10ns.default = Object.assign(Object.assign({}, flatpickr.l10ns.default), l10n);
2429
- };
2430
- flatpickr.setDefaults = (config) => {
2431
- flatpickr.defaultConfig = Object.assign(Object.assign({}, flatpickr.defaultConfig), config);
2432
- };
2433
- flatpickr.parseDate = createDateParser({});
2434
- flatpickr.formatDate = createDateFormatter({});
2435
- flatpickr.compareDates = compareDates;
2436
- if (typeof jQuery !== "undefined" && typeof jQuery.fn !== "undefined") {
2437
- jQuery.fn.flatpickr = function (config) {
2438
- return _flatpickr(this, config);
2439
- };
2440
- }
2441
- Date.prototype.fp_incr = function (days) {
2442
- return new Date(this.getFullYear(), this.getMonth(), this.getDate() + (typeof days === "string" ? parseInt(days, 10) : days));
2443
- };
2444
- if (typeof window !== "undefined") {
2445
- window.flatpickr = flatpickr;
2446
- }
2447
-
2448
- const arrowSvg = (rotate = false) => `<svg width="8" height="12" viewBox="0 0 8 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="${rotate ? 'M0.557948 5.6813L6.06209 0.132167C6.23831 -0.0440556 6.52327 -0.0440556 6.69949 0.132167L7.44187 0.874551C7.61809 1.05077 7.61809 1.33573 7.44187 1.51195L2.99882 6L7.44187 10.488C7.61809 10.6643 7.61809 10.9492 7.44187 11.1254L6.69949 11.8678C6.52327 12.0441 6.23831 12.0441 6.06209 11.8678L0.557948 6.3187C0.381726 6.14248 0.381726 5.85752 0.557948 5.6813Z' : 'M7.44187 6.3187L1.93773 11.8678C1.76151 12.0441 1.47655 12.0441 1.30033 11.8678L0.557948 11.1254C0.381726 10.9492 0.381726 10.6643 0.557948 10.488L5.001 6L0.557948 1.51195C0.381726 1.33573 0.381726 1.05077 0.557948 0.874551L1.30033 0.132167C1.47655 -0.0440556 1.76151 -0.0440556 1.93773 0.132167L7.44187 5.6813C7.6181 5.85752 7.6181 6.14248 7.44187 6.3187Z'}" /></svg>`;
2449
- const XplInput = class {
2450
- constructor(hostRef) {
2451
- index.registerInstance(this, hostRef);
2452
- /**
2453
- * See https://flatpickr.js.org/formatting/
2454
- */
2455
- this.dateFormat = "Y-m-d";
2456
- /**
2457
- * For datepicker inputs, whether to allow only a single
2458
- * date or a range of dates. (Multiple non-consecutive
2459
- * dates planned to be supported in the future.)
2460
- */
2461
- this.mode = "single";
2462
- /**
2463
- * Whether to render as a singleline text input or
2464
- * as a multiline textarea. (If `true`, `pre` and `post`
2465
- * values will be ignored, if present.)
2466
- */
2467
- this.multiline = false;
2468
- this.type = "text";
2469
- this.characterCount = 0;
2470
- this.passwordVisible = false;
2471
- }
2472
- updateCharacterCount() {
2473
- this.characterCount = this.input.value.length;
2474
- }
2475
- componentWillLoad() {
2476
- if (this._id === undefined || this._id === null || this._id === "")
2477
- this._id = v4.v4();
2478
- if (this.multiline && this.maxCharacterCount !== undefined) {
2479
- this.characterCount = this.value !== undefined ? this.value.length : 0;
2480
- }
2481
- }
2482
- componentDidLoad() {
2483
- if (this.type === "date") {
2484
- flatpickr(this.input, {
2485
- allowInput: true,
2486
- dateFormat: this.dateFormat,
2487
- defaultDate: this.value,
2488
- maxDate: this.max,
2489
- minDate: this.min,
2490
- mode: this.mode,
2491
- nextArrow: arrowSvg(),
2492
- prevArrow: arrowSvg(true)
2493
- });
2494
- }
2495
- }
2496
- render() {
2497
- let className = "xpl-input";
2498
- if (this.disabled)
2499
- className += " xpl-input--disabled";
2500
- let hasError = false;
2501
- if (this.error !== undefined)
2502
- hasError = true;
2503
- if (this.multiline && this.maxCharacterCount !== undefined && this.characterCount > this.maxCharacterCount)
2504
- hasError = true;
2505
- if (hasError)
2506
- className += " xpl-input--error";
2507
- let type = this.type;
2508
- if (type === "password" && this.passwordVisible) {
2509
- type = "text";
2510
- }
2511
- return (index.h(index.Host, { class: className }, index.h("label", { class: "xpl-input-label", htmlFor: this._id }, this.label, this.description && index.h("small", null, this.description)), index.h("div", { class: "xpl-input-wrapper" }, this.pre && !this.multiline && index.h("label", { class: "xpl-input-pre", htmlFor: this._id }, this.pre), !this.multiline ?
2512
- index.h("input", { autocomplete: this.type === "date" ? "off" : this.autocomplete, disabled: this.disabled, id: this._id, max: this.max, min: this.min, name: this.name, placeholder: this.placeholder, readonly: this.readonly, ref: (el) => {
2513
- this.input = el;
2514
- }, required: this.required, step: this.step, type: type, value: this.value }) :
2515
- index.h("textarea", { disabled: this.disabled, id: this._id, name: this.name, onInput: () => this.updateCharacterCount(), placeholder: this.placeholder, readonly: this.readonly, ref: (el) => {
2516
- this.input = el;
2517
- }, required: this.required }, this.value), this.type === "date" && index.h("span", { class: "xpl-input-calendar" }, index.h("i", { class: "far fa-calendar-alt" })), this.type === "password" && index.h("button", { class: "xpl-input-password", onClick: () => {
2518
- this.passwordVisible = !this.passwordVisible;
2519
- }, role: "presentation" }, index.h("span", { class: "sr-only" }, "Toggle password visibility"), index.h("i", { class: "far fa-eye", style: {
2520
- display: this.passwordVisible ? "none" : "block"
2521
- } }), index.h("i", { class: "far fa-eye-slash", style: {
2522
- display: this.passwordVisible ? "block" : "none"
2523
- } })), this.post && !this.multiline && index.h("label", { class: "xpl-input-post", htmlFor: this._id }, this.post), this.multiline && this.maxCharacterCount !== undefined && index.h("span", { class: "xpl-input-characters" }, this.characterCount, "/", this.maxCharacterCount)), this.error !== undefined && this.error.length > 0 && index.h("label", { class: "xpl-input-error", htmlFor: this._id }, index.h("svg", { width: "10", height: "11", viewBox: "0 0 10 11", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, index.h("path", { d: "M9.84375 5.25C9.84375 2.59375 7.65625 0.40625 5 0.40625C2.32422 0.40625 0.15625 2.59375 0.15625 5.25C0.15625 7.92578 2.32422 10.0938 5 10.0938C7.65625 10.0938 9.84375 7.92578 9.84375 5.25ZM5 6.22656C5.48828 6.22656 5.89844 6.63672 5.89844 7.125C5.89844 7.63281 5.48828 8.02344 5 8.02344C4.49219 8.02344 4.10156 7.63281 4.10156 7.125C4.10156 6.63672 4.49219 6.22656 5 6.22656ZM4.14062 3.00391C4.12109 2.86719 4.23828 2.75 4.375 2.75H5.60547C5.74219 2.75 5.85938 2.86719 5.83984 3.00391L5.70312 5.66016C5.68359 5.79688 5.58594 5.875 5.46875 5.875H4.51172C4.39453 5.875 4.29688 5.79688 4.27734 5.66016L4.14062 3.00391Z" })), this.error)));
2524
- }
2525
- };
2526
-
2527
- exports.xpl_input = XplInput;