aloha-vue 2.74.0 → 2.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +22 -21
  3. package/dist/aloha-vue.css +13594 -13594
  4. package/dist/aloha-vue.css.map +1 -1
  5. package/dist/aloha-vue.es.js +59266 -64918
  6. package/dist/aloha-vue.umd.js +338 -211
  7. package/package.json +27 -34
  8. package/scss/components/ATable.scss +2 -2
  9. package/scss/utils/button.scss +362 -362
  10. package/scss/utils/funktions.scss +162 -162
  11. package/src/AAccordion/AAccordionItem/AAccordionItem.js +235 -230
  12. package/src/ACarousel/ACarousel.js +7 -2
  13. package/src/ADropdown/ADropdown.js +4 -1
  14. package/src/AFilters/AFilterCenter/AFilterCenter.js +5 -1
  15. package/src/AFilters/AFilterCenter/AFilterCenterItem/AFilterCenterItem.js +7 -2
  16. package/src/AFilters/AFiltersHorizontal/AFiltersHorizontal.js +412 -396
  17. package/src/AFilters/AFiltersHorizontal/AFiltersHorizontalFilter/AFiltersHorizontalFilter.js +102 -99
  18. package/src/AFilters/AFiltersHorizontal/compositionAPI/FiltersSavedDeleteAPI.js +108 -108
  19. package/src/AFilters/AFiltersMain/AFiltersMain.js +114 -111
  20. package/src/AFilters/AFiltersSaveModal/compositionAPI/SaveAPI.js +65 -65
  21. package/src/ALinkCopy/ALinkCopy.js +98 -95
  22. package/src/ALinkCopy/compositionAPI/CopyAPI.js +48 -48
  23. package/src/AList/__tests__/AList.test.js +33 -33
  24. package/src/AList/compositionAPI/__tests__/TagAPI.test.js +43 -43
  25. package/src/AMenu/AMenu.js +4 -1
  26. package/src/AMenu/AMenuBreadcrumbs/AMenuBreadcrumbs.js +240 -237
  27. package/src/AMenu/AMenuPanelLink/AMenuPanelLink.js +4 -1
  28. package/src/AMenu/AMenuSearchPanelBreadcrumbs/AMenuSearchPanelBreadcrumbs.js +122 -119
  29. package/src/AModalWizard/AModalWizard.js +58 -53
  30. package/src/AModalWizard/compositionAPI/__tests__/ScrollAPI.test.js +46 -46
  31. package/src/APagination/APaginationPages/APaginationPages.js +15 -4
  32. package/src/ARate/ARate.js +254 -249
  33. package/src/ARate/ARateIcon/ADecimalIcon/ADecimalIcon.js +53 -50
  34. package/src/ARate/ARateIcon/ARateIcon.js +109 -104
  35. package/src/AResizer/AResizer.js +167 -162
  36. package/src/ATable/ATableHeaderTh/compositionAPI/SortAPI.js +172 -167
  37. package/src/ATable/ATableHeaderThAction/ATableHeaderThAction.js +14 -4
  38. package/src/ATable/ATableHeaderThAction/ATableHeaderThActionItem/ATableHeaderThActionItem.js +191 -184
  39. package/src/ATable/ATablePreviewDown/ATablePreviewDown.js +72 -69
  40. package/src/ATable/ATablePreviewRight/ATablePreviewRight.js +265 -258
  41. package/src/ATable/ATableSortingAdditional/ATableSortingAdditional.js +224 -219
  42. package/src/ATable/ATableSortingAdditional/__tests__/ATableSortingAdditional.AttributesAPI.test.js +39 -39
  43. package/src/ATable/ATableSortingAdditional/__tests__/ATableSortingAdditional.ColumnsAPI.test.js +68 -68
  44. package/src/ATable/ATableSortingAdditional/__tests__/ATableSortingAdditional.DropdownAPI.test.js +45 -45
  45. package/src/ATable/ATableSortingAdditional/__tests__/ATableSortingAdditional.FormAPI.test.js +95 -95
  46. package/src/ATable/ATableSortingAdditional/__tests__/ATableSortingAdditional.ModelAPI.test.js +1 -1
  47. package/src/ATable/ATableTd/ATableTd.js +4 -1
  48. package/src/ATable/ATableTdAction/ATableTdAction.js +19 -12
  49. package/src/ATable/ATableTopPanel/ATableTopPanel.js +11 -3
  50. package/src/ATable/ATableTr/ATableTr.js +408 -405
  51. package/src/ATable/__tests__/ATable.HeaderSlot.test.js +102 -97
  52. package/src/ATable/__tests__/ATable.RowIdsAPI.test.js +66 -66
  53. package/src/ATableForm/ATableForm.js +88 -85
  54. package/src/ATableForm/ATableFormCellAction/ATableFormCellAction.js +14 -4
  55. package/src/ATableForm/ATableFormCellDnd/ATableFormCellDnd.js +196 -187
  56. package/src/ATableForm/ATableFormRow/compositionAPI/EditAPI.js +104 -104
  57. package/src/ATableForm/__tests__/ATableForm.DragAndDropAPI.test.js +200 -212
  58. package/src/ATableForm/__tests__/ATableForm.ListView.test.js +134 -174
  59. package/src/ATableForm/compositionAPI/IconsAPI.js +24 -21
  60. package/src/AVerticalScroll/AVerticalScroll.js +182 -177
  61. package/src/AWizard/AWizard.js +26 -21
  62. package/src/AWizard/AWizardStep/AWizardStep.js +275 -270
  63. package/src/AWizard/compositionAPI/__tests__/ChangeStepAPI.test.js +32 -32
  64. package/src/AWizard/compositionAPI/__tests__/LocalAPI.test.js +55 -55
  65. package/src/PuxDatepicker/PuxDatepickerCalendarPanel/PuxDatepickerCalendarPanel.js +646 -648
  66. package/src/PuxDatepicker/panel/PanelDate/PanelDate.js +300 -301
  67. package/src/PuxDatepicker/panel/PanelMonth/PanelMonth.js +148 -149
  68. package/src/PuxDatepicker/panel/PanelTime/PanelTime.js +256 -257
  69. package/src/PuxDatepicker/panel/PanelYear/PanelYear.js +136 -137
  70. package/src/PuxDatepicker/utils/index.js +100 -100
  71. package/src/compositionAPI/AHttpAPI.js +593 -593
  72. package/src/compositionAPI/__tests__/AHttpAPI.test.js +42 -42
  73. package/src/filters/__tests__/filterBoolean.test.js +38 -38
  74. package/src/filters/__tests__/filterCapitalize.test.js +38 -38
  75. package/src/filters/__tests__/filterCurrency.test.js +21 -21
  76. package/src/filters/__tests__/filterDate.test.js +42 -42
  77. package/src/filters/__tests__/filterDefaultForEmpty.test.js +24 -24
  78. package/src/filters/__tests__/filterEmail.test.js +42 -42
  79. package/src/filters/__tests__/filterEscapeHtml.test.js +45 -45
  80. package/src/filters/__tests__/filterFileSize.test.js +45 -45
  81. package/src/filters/__tests__/filterFloat.test.js +74 -74
  82. package/src/filters/__tests__/filterJson.test.js +74 -74
  83. package/src/filters/__tests__/filterKeyValue.test.js +50 -50
  84. package/src/filters/__tests__/filterLimitTo.test.js +39 -39
  85. package/src/filters/__tests__/filterLink.test.js +41 -41
  86. package/src/filters/__tests__/filterList.test.js +149 -149
  87. package/src/filters/__tests__/filterLowerCase.test.js +38 -38
  88. package/src/filters/__tests__/filterMask.test.js +80 -80
  89. package/src/filters/__tests__/filterPropertyByValue.test.js +27 -27
  90. package/src/filters/__tests__/filterSearchHighlight.test.js +129 -129
  91. package/src/filters/__tests__/filterUpperCase.test.js +38 -38
  92. package/src/filters/__tests__/filterValueByCondition.test.js +3 -3
  93. package/src/filters/filterJson.js +39 -39
  94. package/src/filters/filterValueByCondition.js +2 -2
  95. package/src/plugins/AAlertPlugin.js +16 -5
  96. package/src/plugins/AMultiselectOrderedPlugin.js +88 -81
  97. package/src/plugins/ASelectPlugin.js +12 -10
  98. package/src/ui/ACheckbox/ACheckbox.js +82 -79
  99. package/src/ui/ADatepicker/compositionAPI/EventsAPI.js +297 -297
  100. package/src/ui/ADatepicker/utils/index.js +76 -76
  101. package/src/ui/ADatepickerAlt/ADatepicker.js +912 -912
  102. package/src/ui/ADatepickerAlt/utils/index.js +98 -98
  103. package/src/ui/AFieldset/__tests__/AFieldset.ClassColumn.test.js +113 -114
  104. package/src/ui/AFormElementBtnClear/AFormElementBtnClear.js +4 -1
  105. package/src/ui/AInputCurrency/AInputCurrency.js +20 -15
  106. package/src/ui/AInputCurrency/__tests__/AInputCurrency.ModelAPI.test.js +73 -73
  107. package/src/ui/AInputNumber/AInputNumber.js +17 -12
  108. package/src/ui/AJson/AJson.js +12 -3
  109. package/src/ui/AJson/compositionAPI/JsonAPI.js +116 -116
  110. package/src/ui/ALabel/__tests__/ALabel.IdAPI.test.js +42 -42
  111. package/src/ui/ALabel/__tests__/ALabel.LabelAPI.test.js +33 -33
  112. package/src/ui/ARadio/ARadio.js +80 -77
  113. package/src/ui/ASelect/ASelect.js +390 -383
  114. package/src/ui/ASelect/ASelectElement/ASelectElement.js +179 -176
  115. package/src/ui/ASelect/ASelectValueCloseable/ASelectValueCloseable.js +143 -141
  116. package/src/ui/ASelect/__tests__/SelectedFirstAPI.test.js +101 -101
  117. package/src/ui/ASelect/__tests__/SelectedVisibleAPI.test.js +98 -98
  118. package/src/ui/ASlider/compositionAPI/SliderAPI.js +23 -23
  119. package/src/ui/AValidatedJson/AValidatedJson.js +4 -1
  120. package/src/ui/AValidatedJson/AValidatedJsonItem/AValidatedJsonItem.js +308 -298
  121. package/src/ui/compositionApi/UiCollapseAPI.js +68 -63
  122. package/src/ui/compositionApi/UiInputAutofillAPI.js +41 -41
  123. package/src/ui/compositionApi/__tests__/UIDataGroupAPI.test.js +106 -106
  124. package/src/ui/compositionApi/__tests__/UIExcludeRenderAttributesAPI.test.js +39 -39
  125. package/src/ui/compositionApi/__tests__/UiDataWithKeyIdAndLabelAPI.test.js +128 -128
  126. package/src/ui/compositionApi/__tests__/UiSearchAPI.test.js +71 -71
  127. package/src/utils/EventBus.js +51 -8
  128. package/src/utils/__tests__/EventBus.test.js +138 -0
  129. package/src/utils/__tests__/utils.aOrderBy.test.js +1 -1
  130. package/src/utils/__tests__/utils.aSortBy.test.js +1 -1
  131. package/src/utils/__tests__/utils.getTotalNestedCount.test.js +56 -56
  132. package/src/utils/__tests__/utils.isArrayOfArrays.test.js +44 -44
  133. package/src/utils/__tests__/utils.isArrayOfStrings.test.js +36 -36
  134. package/src/utils/__tests__/utilsArray.aFirst.test.js +1 -1
  135. package/src/utils/__tests__/utilsArray.aLast.test.js +1 -1
  136. package/src/utils/__tests__/utilsLang.isArguments.test.js +1 -1
  137. package/src/utils/__tests__/utilsLang.isArray.test.js +1 -1
  138. package/src/utils/__tests__/utilsLang.isArrayBuffer.test.js +1 -1
  139. package/src/utils/__tests__/utilsLang.isBoolean.test.js +1 -1
  140. package/src/utils/__tests__/utilsLang.isBuffer.test.js +1 -1
  141. package/src/utils/__tests__/utilsLang.isDate.test.js +1 -1
  142. package/src/utils/__tests__/utilsLang.isElement.test.js +5 -3
  143. package/src/utils/__tests__/utilsLang.isError.test.js +1 -1
  144. package/src/utils/__tests__/utilsLang.isFinite.test.js +1 -1
  145. package/src/utils/__tests__/utilsLang.isFunction.test.js +1 -1
  146. package/src/utils/__tests__/utilsLang.isInteger.test.js +1 -1
  147. package/src/utils/__tests__/utilsLang.isMap.test.js +1 -1
  148. package/src/utils/__tests__/utilsLang.isNaN.test.js +1 -1
  149. package/src/utils/__tests__/utilsLang.isNil.test.js +1 -1
  150. package/src/utils/__tests__/utilsLang.isNull.test.js +1 -1
  151. package/src/utils/__tests__/utilsLang.isNumber.test.js +1 -1
  152. package/src/utils/__tests__/utilsLang.isObject.test.js +1 -1
  153. package/src/utils/__tests__/utilsLang.isObjectLike.test.js +5 -3
  154. package/src/utils/__tests__/utilsLang.isPlainObject.test.js +3 -2
  155. package/src/utils/__tests__/utilsLang.isPromise.test.js +5 -2
  156. package/src/utils/__tests__/utilsLang.isRegExp.test.js +1 -1
  157. package/src/utils/__tests__/utilsLang.isSet.test.js +1 -1
  158. package/src/utils/__tests__/utilsLang.isString.test.js +1 -1
  159. package/src/utils/__tests__/utilsLang.isSymbol.test.js +5 -3
  160. package/src/utils/__tests__/utilsLang.isUndefined.test.js +1 -1
  161. package/src/utils/__tests__/utilsLang.isWeakMap.test.js +1 -1
  162. package/src/utils/__tests__/utilsLang.isWeakSet.test.js +1 -1
  163. package/src/utils/__tests__/utilsMath.isEven.test.js +43 -43
  164. package/src/utils/__tests__/utilsMath.isOdd.test.js +43 -43
  165. package/src/utils/__tests__/utilsUi.isModelForFilterNotEmpty.test.js +65 -65
  166. package/src/utils/autosize.js +1 -1
@@ -1,648 +1,646 @@
1
- import {
2
- AButton,
3
- } from "aloha-vue";
4
-
5
- import PanelDate from "../panel/PanelDate/PanelDate.vue";
6
- import PanelMonth from "../panel/PanelMonth/PanelMonth.vue";
7
- import PanelTime from "../panel/PanelTime/PanelTime.vue";
8
- import PanelYear from "../panel/PanelYear/PanelYear.vue";
9
-
10
- import PanelMixin from "../mixins/PanelMixin";
11
-
12
- import keysCode from "../utils/keysCode";
13
- import scrollIntoView from "../utils/scroll-into-view";
14
- import {
15
- formatDate,
16
- isDateObject,
17
- isValidDate,
18
- } from "../utils";
19
- import {
20
- forEach,
21
- } from "lodash-es";
22
-
23
-
24
- // @vue/component
25
- export default {
26
- name: "CalendarPanel",
27
- components: {
28
- AButton,
29
- PanelDate,
30
- PanelMonth,
31
- PanelTime,
32
- PanelYear,
33
- },
34
- mixins: [
35
- PanelMixin,
36
- ],
37
- props: {
38
- id: {
39
- type: String,
40
- required: true,
41
- },
42
- value: {
43
- default: null,
44
- validator: function(val) {
45
- return val === null || isValidDate(val);
46
- },
47
- },
48
- startAt: {
49
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
50
- required: false,
51
- default: undefined,
52
- },
53
- endAt: {
54
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
55
- required: false,
56
- default: undefined,
57
- },
58
- visible: {
59
- type: Boolean,
60
- default: false,
61
- },
62
- type: {
63
- type: String,
64
- default: "date", // ["date", "datetime"]
65
- },
66
- dateFormat: {
67
- type: String,
68
- default: "YYYY-MM-DD",
69
- },
70
- index: {
71
- type: Number,
72
- default: undefined,
73
- },
74
- defaultValue: {
75
- validator: function(val) {
76
- return isValidDate(val);
77
- },
78
- default: undefined,
79
- },
80
- firstDayOfWeek: {
81
- default: 7,
82
- type: Number,
83
- validator: val => val >= 1 && val <= 7,
84
- },
85
- notBefore: {
86
- default: null,
87
- validator: function(val) {
88
- return !val || isValidDate(val);
89
- },
90
- },
91
- notAfter: {
92
- default: null,
93
- validator: function(val) {
94
- return !val || isValidDate(val);
95
- },
96
- },
97
- disabledDays: {
98
- type: [Array, Function],
99
- default: function() {
100
- return [];
101
- },
102
- },
103
- minuteStep: {
104
- type: Number,
105
- default: 0,
106
- validator: val => val >= 0 && val <= 60,
107
- },
108
- currentLanguage: {
109
- type: Object,
110
- required: true,
111
- },
112
- },
113
- emits: [
114
- "closePopup",
115
- "selectDate",
116
- "selectTime",
117
- ],
118
- data() {
119
- const now = this.getNow(this.value);
120
- const calendarYear = now.getFullYear();
121
- const calendarMonth = now.getMonth();
122
- const firstYear = Math.floor(calendarYear / 10) * 10;
123
- return {
124
- panel: "NONE",
125
- dates: [],
126
- calendarMonth,
127
- calendarYear,
128
- firstYear,
129
- isFocusPanelChild: false,
130
- isWorkWithKeyboard: false,
131
- };
132
- },
133
- computed: {
134
- now: {
135
- get() {
136
- return new Date(this.calendarYear, this.calendarMonth).getTime();
137
- },
138
- set(val) {
139
- const now = new Date(val);
140
- this.calendarYear = now.getFullYear();
141
- this.calendarMonth = now.getMonth();
142
- },
143
- },
144
-
145
- timeType() {
146
- const h = /h+/.test(this.$parent.format) ? "12" : "24";
147
- const a = /A/.test(this.$parent.format) ? "A" : "a";
148
- return [h, a];
149
- },
150
-
151
- timeHeader() {
152
- if (this.type === "time") {
153
- return this.$parent.format;
154
- }
155
- return this.value && formatDate(this.value, this.dateFormat);
156
- },
157
-
158
- yearHeader() {
159
- const LAST_YEAR = this.firstYear + 9;
160
- return this.currentLanguage.headerYears(this.firstYear, LAST_YEAR);
161
- },
162
-
163
- months() {
164
- return this.currentLanguage.months;
165
- },
166
-
167
- notBeforeTime() {
168
- return this.getCriticalTime(this.notBefore);
169
- },
170
-
171
- notAfterTime() {
172
- return this.getCriticalTime(this.notAfter);
173
- },
174
-
175
- suffixForHeader() {
176
- if (this.panel === "TIME") {
177
- return this.currentLanguage.placeholder.regionTime;
178
- }
179
- return this.currentLanguage.placeholder.regionDate;
180
- },
181
-
182
- idForHeaderParent() {
183
- return `${ this.idForHeader }_parent`;
184
- },
185
-
186
- ariaLabelForButtonLastYear() {
187
- if (this.panel === "YEAR") {
188
- return this.currentLanguage.buttons.lastYears;
189
- }
190
- return this.currentLanguage.buttons.lastYear;
191
- },
192
-
193
- ariaLabelForButtonLastMonth() {
194
- return this.currentLanguage.buttons.lastMonth;
195
- },
196
-
197
- ariaLabelForButtonNextMonth() {
198
- return this.currentLanguage.buttons.nextMonth;
199
- },
200
-
201
- ariaLabelForButtonNextYear() {
202
- if (this.panel === "YEAR") {
203
- return this.currentLanguage.buttons.nextYears;
204
- }
205
- return this.currentLanguage.buttons.nextYear;
206
- },
207
-
208
- ariaLabelForButtonCurrentMonth() {
209
- return this.currentLanguage.buttons.toMonthsView;
210
- },
211
-
212
- ariaLabelForButtonCurrentYear() {
213
- return this.currentLanguage.buttons.toYearsView;
214
- },
215
-
216
- ariaLabelForButtonToDays() {
217
- return this.currentLanguage.buttons.toDaysView;
218
- },
219
- },
220
- watch: {
221
- value: {
222
- immediate: true,
223
- handler: "updateNow",
224
- },
225
- defaultValue: {
226
- handler: "updateNow",
227
- },
228
- visible: {
229
- immediate: true,
230
- handler: "init",
231
- },
232
- panel: {
233
- handler: "handelPanelChange",
234
- },
235
- },
236
- beforeUnmount() {
237
- this.destroyListenerForPressTabButton();
238
- this.destroyListenerForPressEscapeButton();
239
- },
240
- methods: {
241
- handelPanelChange(panel) {
242
- if (panel === "YEAR") {
243
- this.firstYear = Math.floor(this.calendarYear / 10) * 10;
244
- } else if (panel === "TIME") {
245
- this.$nextTick().then(() => {
246
- const list = this.$el.querySelectorAll(".pux_datepicker__panel_time .pux_datepicker__time_list");
247
- for (let i = 0, len = list.length; i < len; i++) {
248
- const el = list[i];
249
- scrollIntoView(el, el.querySelector(".actived"));
250
- }
251
- });
252
- }
253
- },
254
-
255
- init(val) {
256
- if (val) {
257
- const type = this.type;
258
- if (type === "month") {
259
- this.showPanelMonth();
260
- } else if (type === "year") {
261
- this.showPanelYear();
262
- } else if (type === "time") {
263
- this.showPanelTime();
264
- } else {
265
- this.showPanelDate();
266
- }
267
- this.setListenerForPressEscapeButton();
268
- } else {
269
- this.showPanelNone();
270
- this.updateNow(this.value);
271
- this.destroyListenerForPressEscapeButton();
272
- }
273
- this.emitEventBusDestroyAllListenerForPressButtonsForPanels();
274
- },
275
-
276
- getNow(value) {
277
- return value
278
- ? new Date(value)
279
- : this.defaultValue && isValidDate(this.defaultValue)
280
- ? new Date(this.defaultValue)
281
- : new Date();
282
- },
283
-
284
- updateNow(value) {
285
- this.now = this.getNow(value);
286
- },
287
-
288
- getCriticalTime(value) {
289
- if (!value) {
290
- return null;
291
- }
292
- const date = new Date(value);
293
- if (this.type === "year") {
294
- return new Date(date.getFullYear(), 0).getTime();
295
- } else if (this.type === "month") {
296
- return new Date(date.getFullYear(), date.getMonth()).getTime();
297
- } else if (this.type === "date") {
298
- return date.setHours(0, 0, 0, 0);
299
- }
300
- return date.getTime();
301
- },
302
-
303
- inBefore(time, startAt) {
304
- if (startAt === undefined) {
305
- startAt = this.startAt;
306
- }
307
- return (
308
- (this.notBeforeTime && time < this.notBeforeTime) ||
309
- (startAt && time < this.getCriticalTime(startAt))
310
- );
311
- },
312
-
313
- inAfter(time, endAt) {
314
- if (endAt === undefined) {
315
- endAt = this.endAt;
316
- }
317
- return (
318
- (this.notAfterTime && time > this.notAfterTime) ||
319
- (endAt && time > this.getCriticalTime(endAt))
320
- );
321
- },
322
-
323
- inDisabledDays(time) {
324
- if (Array.isArray(this.disabledDays)) {
325
- return this.disabledDays.some(v => this.getCriticalTime(v) === time);
326
- }
327
- if (typeof this.disabledDays === "function") {
328
- return this.disabledDays(new Date(time));
329
- }
330
- return false;
331
- },
332
-
333
- isDisabledYear(year) {
334
- const time = new Date(year, 0).getTime();
335
- const maxTime = new Date(year + 1, 0).getTime() - 1;
336
- return (
337
- this.inBefore(maxTime) ||
338
- this.inAfter(time) ||
339
- (this.type === "year" && this.inDisabledDays(time))
340
- );
341
- },
342
-
343
- isDisabledMonth(month) {
344
- const time = new Date(this.calendarYear, month).getTime();
345
- const maxTime = new Date(this.calendarYear, month + 1).getTime() - 1;
346
- return (
347
- this.inBefore(maxTime) ||
348
- this.inAfter(time) ||
349
- (this.type === "month" && this.inDisabledDays(time))
350
- );
351
- },
352
-
353
- isDisabledDate(date) {
354
- const time = new Date(date).getTime();
355
- const maxTime = new Date(date).setHours(23, 59, 59, 999);
356
- return (
357
- this.inBefore(maxTime) ||
358
- this.inAfter(time) ||
359
- this.inDisabledDays(time)
360
- );
361
- },
362
-
363
- isDisabledTime(date, startAt, endAt) {
364
- const time = new Date(date).getTime();
365
- return (
366
- this.inBefore(time, startAt) ||
367
- this.inAfter(time, endAt) ||
368
- this.inDisabledDays(time)
369
- );
370
- },
371
-
372
- selectDate(date) {
373
- if (this.type === "datetime") {
374
- let time = new Date(date);
375
- if (isDateObject(this.value)) {
376
- time.setHours(
377
- this.value.getHours(),
378
- this.value.getMinutes(),
379
- this.value.getSeconds(),
380
- );
381
- }
382
- if (this.isDisabledTime(time)) {
383
- time.setHours(0, 0, 0, 0);
384
- if (
385
- this.notBefore &&
386
- time.getTime() < new Date(this.notBefore).getTime()
387
- ) {
388
- time = new Date(this.notBefore);
389
- }
390
- if (
391
- this.startAt &&
392
- time.getTime() < new Date(this.startAt).getTime()
393
- ) {
394
- time = new Date(this.startAt);
395
- }
396
- }
397
- this.selectTime(time);
398
- this.showPanelTime();
399
- return;
400
- }
401
- this.$emit("selectDate", date);
402
- },
403
-
404
- selectYear({ year, isButtonClick }) {
405
- this.changeCalendarYear(year);
406
- if (this.type.toLowerCase() === "year") {
407
- return this.selectDate(new Date(this.now));
408
- }
409
- this.showPanelMonth();
410
- if (isButtonClick) {
411
- this.setFocusToActivePanel();
412
- }
413
- },
414
-
415
- selectMonth({ month, isButtonClick }) {
416
- this.changeCalendarMonth(month);
417
- if (this.type.toLowerCase() === "month") {
418
- return this.selectDate(new Date(this.now));
419
- }
420
- this.showPanelDate();
421
- if (isButtonClick) {
422
- this.setFocusToActivePanel();
423
- }
424
- },
425
-
426
- selectTime(time, statusClose = false) {
427
- this.$emit("selectTime", time, statusClose);
428
- },
429
-
430
- changeCalendarYear(year) {
431
- this.updateNow(new Date(year, this.calendarMonth));
432
- },
433
-
434
- changeCalendarMonth(month) {
435
- this.updateNow(new Date(this.calendarYear, month));
436
- },
437
-
438
- getSibling() {
439
- const PANELS = [
440
- this.$parent.$refs.calendarPanel,
441
- ];
442
- if (this.$parent.$refs.calendarPanel2) {
443
- PANELS.push(this.$parent.$refs.calendarPanel2);
444
- }
445
- const calendars = PANELS.filter(
446
- v => v.$options.name === this.$options.name,
447
- );
448
- const index = calendars.indexOf(this);
449
- /* eslint-disable-next-line no-bitwise */
450
- return calendars[index ^ 1];
451
- },
452
-
453
- handleIconMonth(flag) {
454
- const month = this.calendarMonth;
455
- this.changeCalendarMonth(month + flag);
456
- this.$parent.$emit("changeCalendarMonth", {
457
- month,
458
- flag,
459
- vm: this,
460
- sibling: this.getSibling(),
461
- });
462
- },
463
-
464
- handleIconYear(flag) {
465
- if (this.panel === "YEAR") {
466
- this.changePanelYears(flag);
467
- } else {
468
- const year = this.calendarYear;
469
- this.changeCalendarYear(year + flag);
470
- this.$parent.$emit("changeCalendarYear", {
471
- year,
472
- flag,
473
- vm: this,
474
- sibling: this.getSibling(),
475
- });
476
- }
477
- },
478
-
479
- handleBtnYear() {
480
- this.showPanelYear();
481
- if (this.isWorkWithKeyboard) {
482
- this.setFocusToActivePanel();
483
- }
484
- },
485
-
486
- handleBtnMonth() {
487
- this.showPanelMonth();
488
- if (this.isWorkWithKeyboard) {
489
- this.setFocusToActivePanel();
490
- }
491
- },
492
-
493
- handleTimeHeader() {
494
- if (this.type === "time") {
495
- return;
496
- }
497
- this.showPanelDate();
498
- if (this.isWorkWithKeyboard) {
499
- this.setFocusToActivePanel();
500
- }
501
- },
502
-
503
- changePanelYears(flag) {
504
- this.firstYear = this.firstYear + flag * 10;
505
- },
506
-
507
- showPanelNone() {
508
- this.panel = "NONE";
509
- this.isFocusPanelChild = false;
510
- this.destroyListenerForPressTabButton();
511
- this.emitEventBusDestroyAllListenerForPressButtonsForPanels();
512
- this.setWorkWithoutKeyboard();
513
- },
514
-
515
- showPanelTime() {
516
- this.panel = "TIME";
517
- },
518
-
519
- showPanelDate() {
520
- this.panel = "DATE";
521
- },
522
-
523
- showPanelYear() {
524
- this.panel = "YEAR";
525
- },
526
-
527
- showPanelMonth() {
528
- this.panel = "MONTH";
529
- },
530
-
531
- setFocusToActivePanelFromParent() {
532
- this.setWorkWithKeyboard();
533
- this.setFocusToActivePanel();
534
- this.setListenerForPressTabButton();
535
- },
536
-
537
- setFocusToActivePanel() {
538
- this.isFocusPanelChild = true;
539
- this.setFocusToActiveElementInChild();
540
- },
541
-
542
- removeFocusFromActivePanel() {
543
- if (this.isFocusPanelChild) {
544
- this.isFocusPanelChild = false;
545
- this.emitEventBusDestroyAllListenerForPressButtonsForPanels();
546
- }
547
- },
548
-
549
- setFocusToActiveElementInChild() {
550
- if (this.panel === "DATE") {
551
- this.$refs.panelDate.setFocusToActiveDay();
552
- } else if (this.panel === "TIME") {
553
- this.$refs.panelTime.setFocusToActiveTime();
554
- } else if (this.panel === "YEAR") {
555
- this.$refs.panelYear.setFocusToActiveYear();
556
- } else if (this.panel === "MONTH") {
557
- this.$refs.panelMonth.setFocusToActiveMonth();
558
- }
559
- },
560
-
561
- setListenerForPressTabButton() {
562
- document.addEventListener("keydown", this.pressTabButton);
563
- },
564
-
565
- destroyListenerForPressTabButton() {
566
- document.removeEventListener("keydown", this.pressTabButton);
567
- },
568
-
569
- pressTabButton($event) {
570
- const KEY_CODE = $event.keyCode;
571
- if (KEY_CODE === keysCode.tab) {
572
- this.trapFocus($event);
573
- this.stopCurrentEvent($event);
574
- }
575
- },
576
-
577
- trapFocus(EVENT) {
578
- const FOCUSABLE_ELEMENTS = this.$el.querySelectorAll(".pux_datepicker__calendar__tab");
579
- if (FOCUSABLE_ELEMENTS.length <= 1) {
580
- return;
581
- }
582
- let isFocused = false;
583
- let isFocusedPanel = false;
584
- forEach(FOCUSABLE_ELEMENTS, (element, elementIndex) => {
585
- if (document.activeElement === element) {
586
- if (EVENT.shiftKey) {
587
- if (elementIndex === 0) {
588
- FOCUSABLE_ELEMENTS[FOCUSABLE_ELEMENTS.length - 1].focus();
589
- isFocusedPanel = true;
590
- } else {
591
- FOCUSABLE_ELEMENTS[elementIndex - 1].focus();
592
- }
593
- } else {
594
- if (elementIndex === FOCUSABLE_ELEMENTS.length - 1) {
595
- FOCUSABLE_ELEMENTS[0].focus();
596
- } else {
597
- FOCUSABLE_ELEMENTS[elementIndex + 1].focus();
598
- }
599
- if (elementIndex === FOCUSABLE_ELEMENTS.length - 2) {
600
- isFocusedPanel = true;
601
- }
602
- }
603
- isFocused = true;
604
- return false;
605
- }
606
- });
607
- if (!isFocused) {
608
- if (EVENT.shiftKey) {
609
- FOCUSABLE_ELEMENTS[FOCUSABLE_ELEMENTS.length - 2].focus();
610
- } else {
611
- FOCUSABLE_ELEMENTS[0].focus();
612
- }
613
- }
614
- if (isFocusedPanel) {
615
- this.setFocusToActivePanel();
616
- } else {
617
- this.removeFocusFromActivePanel();
618
- }
619
- },
620
-
621
- setWorkWithKeyboard() {
622
- this.isWorkWithKeyboard = true;
623
- },
624
-
625
- setWorkWithoutKeyboard() {
626
- this.isWorkWithKeyboard = false;
627
- },
628
-
629
- setListenerForPressEscapeButton() {
630
- document.addEventListener("keydown", this.pressEscapeButton);
631
- },
632
-
633
- destroyListenerForPressEscapeButton() {
634
- document.removeEventListener("keydown", this.pressEscapeButton);
635
- },
636
-
637
- closePopup() {
638
- this.$emit("closePopup", true);
639
- },
640
-
641
- pressEscapeButton($event) {
642
- const KEY_CODE = $event.keyCode;
643
- if (KEY_CODE === keysCode.escape) {
644
- this.closePopup();
645
- }
646
- },
647
- },
648
- };
1
+ import PanelDate from "../panel/PanelDate/PanelDate.vue";
2
+ import PanelMonth from "../panel/PanelMonth/PanelMonth.vue";
3
+ import PanelTime from "../panel/PanelTime/PanelTime.vue";
4
+ import PanelYear from "../panel/PanelYear/PanelYear.vue";
5
+ import {
6
+ AButton,
7
+ } from "aloha-vue";
8
+
9
+ import PanelMixin from "../mixins/PanelMixin";
10
+ import keysCode from "../utils/keysCode";
11
+ import scrollIntoView from "../utils/scroll-into-view";
12
+ import {
13
+ formatDate,
14
+ isDateObject,
15
+ isValidDate,
16
+ } from "../utils";
17
+ import {
18
+ forEach,
19
+ } from "lodash-es";
20
+
21
+
22
+ // @vue/component
23
+ export default {
24
+ name: "CalendarPanel",
25
+ components: {
26
+ AButton,
27
+ PanelDate,
28
+ PanelMonth,
29
+ PanelTime,
30
+ PanelYear,
31
+ },
32
+ mixins: [
33
+ PanelMixin,
34
+ ],
35
+ props: {
36
+ id: {
37
+ type: String,
38
+ required: true,
39
+ },
40
+ value: {
41
+ default: null,
42
+ validator: function(val) {
43
+ return val === null || isValidDate(val);
44
+ },
45
+ },
46
+ startAt: {
47
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
48
+ required: false,
49
+ default: undefined,
50
+ },
51
+ endAt: {
52
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
53
+ required: false,
54
+ default: undefined,
55
+ },
56
+ visible: {
57
+ type: Boolean,
58
+ default: false,
59
+ },
60
+ type: {
61
+ type: String,
62
+ default: "date", // ["date", "datetime"]
63
+ },
64
+ dateFormat: {
65
+ type: String,
66
+ default: "YYYY-MM-DD",
67
+ },
68
+ index: {
69
+ type: Number,
70
+ default: undefined,
71
+ },
72
+ defaultValue: {
73
+ validator: function(val) {
74
+ return isValidDate(val);
75
+ },
76
+ default: undefined,
77
+ },
78
+ firstDayOfWeek: {
79
+ default: 7,
80
+ type: Number,
81
+ validator: val => val >= 1 && val <= 7,
82
+ },
83
+ notBefore: {
84
+ default: null,
85
+ validator: function(val) {
86
+ return !val || isValidDate(val);
87
+ },
88
+ },
89
+ notAfter: {
90
+ default: null,
91
+ validator: function(val) {
92
+ return !val || isValidDate(val);
93
+ },
94
+ },
95
+ disabledDays: {
96
+ type: [Array, Function],
97
+ default: function() {
98
+ return [];
99
+ },
100
+ },
101
+ minuteStep: {
102
+ type: Number,
103
+ default: 0,
104
+ validator: val => val >= 0 && val <= 60,
105
+ },
106
+ currentLanguage: {
107
+ type: Object,
108
+ required: true,
109
+ },
110
+ },
111
+ emits: [
112
+ "closePopup",
113
+ "selectDate",
114
+ "selectTime",
115
+ ],
116
+ data() {
117
+ const now = this.getNow(this.value);
118
+ const calendarYear = now.getFullYear();
119
+ const calendarMonth = now.getMonth();
120
+ const firstYear = Math.floor(calendarYear / 10) * 10;
121
+ return {
122
+ panel: "NONE",
123
+ dates: [],
124
+ calendarMonth,
125
+ calendarYear,
126
+ firstYear,
127
+ isFocusPanelChild: false,
128
+ isWorkWithKeyboard: false,
129
+ };
130
+ },
131
+ computed: {
132
+ now: {
133
+ get() {
134
+ return new Date(this.calendarYear, this.calendarMonth).getTime();
135
+ },
136
+ set(val) {
137
+ const now = new Date(val);
138
+ this.calendarYear = now.getFullYear();
139
+ this.calendarMonth = now.getMonth();
140
+ },
141
+ },
142
+
143
+ timeType() {
144
+ const h = /h+/.test(this.$parent.format) ? "12" : "24";
145
+ const a = /A/.test(this.$parent.format) ? "A" : "a";
146
+ return [h, a];
147
+ },
148
+
149
+ timeHeader() {
150
+ if (this.type === "time") {
151
+ return this.$parent.format;
152
+ }
153
+ return this.value && formatDate(this.value, this.dateFormat);
154
+ },
155
+
156
+ yearHeader() {
157
+ const LAST_YEAR = this.firstYear + 9;
158
+ return this.currentLanguage.headerYears(this.firstYear, LAST_YEAR);
159
+ },
160
+
161
+ months() {
162
+ return this.currentLanguage.months;
163
+ },
164
+
165
+ notBeforeTime() {
166
+ return this.getCriticalTime(this.notBefore);
167
+ },
168
+
169
+ notAfterTime() {
170
+ return this.getCriticalTime(this.notAfter);
171
+ },
172
+
173
+ suffixForHeader() {
174
+ if (this.panel === "TIME") {
175
+ return this.currentLanguage.placeholder.regionTime;
176
+ }
177
+ return this.currentLanguage.placeholder.regionDate;
178
+ },
179
+
180
+ idForHeaderParent() {
181
+ return `${ this.idForHeader }_parent`;
182
+ },
183
+
184
+ ariaLabelForButtonLastYear() {
185
+ if (this.panel === "YEAR") {
186
+ return this.currentLanguage.buttons.lastYears;
187
+ }
188
+ return this.currentLanguage.buttons.lastYear;
189
+ },
190
+
191
+ ariaLabelForButtonLastMonth() {
192
+ return this.currentLanguage.buttons.lastMonth;
193
+ },
194
+
195
+ ariaLabelForButtonNextMonth() {
196
+ return this.currentLanguage.buttons.nextMonth;
197
+ },
198
+
199
+ ariaLabelForButtonNextYear() {
200
+ if (this.panel === "YEAR") {
201
+ return this.currentLanguage.buttons.nextYears;
202
+ }
203
+ return this.currentLanguage.buttons.nextYear;
204
+ },
205
+
206
+ ariaLabelForButtonCurrentMonth() {
207
+ return this.currentLanguage.buttons.toMonthsView;
208
+ },
209
+
210
+ ariaLabelForButtonCurrentYear() {
211
+ return this.currentLanguage.buttons.toYearsView;
212
+ },
213
+
214
+ ariaLabelForButtonToDays() {
215
+ return this.currentLanguage.buttons.toDaysView;
216
+ },
217
+ },
218
+ watch: {
219
+ value: {
220
+ immediate: true,
221
+ handler: "updateNow",
222
+ },
223
+ defaultValue: {
224
+ handler: "updateNow",
225
+ },
226
+ visible: {
227
+ immediate: true,
228
+ handler: "init",
229
+ },
230
+ panel: {
231
+ handler: "handelPanelChange",
232
+ },
233
+ },
234
+ beforeUnmount() {
235
+ this.destroyListenerForPressTabButton();
236
+ this.destroyListenerForPressEscapeButton();
237
+ },
238
+ methods: {
239
+ handelPanelChange(panel) {
240
+ if (panel === "YEAR") {
241
+ this.firstYear = Math.floor(this.calendarYear / 10) * 10;
242
+ } else if (panel === "TIME") {
243
+ this.$nextTick().then(() => {
244
+ const list = this.$el.querySelectorAll(".pux_datepicker__panel_time .pux_datepicker__time_list");
245
+ for (let i = 0, len = list.length; i < len; i++) {
246
+ const el = list[i];
247
+ scrollIntoView(el, el.querySelector(".actived"));
248
+ }
249
+ });
250
+ }
251
+ },
252
+
253
+ init(val) {
254
+ if (val) {
255
+ const type = this.type;
256
+ if (type === "month") {
257
+ this.showPanelMonth();
258
+ } else if (type === "year") {
259
+ this.showPanelYear();
260
+ } else if (type === "time") {
261
+ this.showPanelTime();
262
+ } else {
263
+ this.showPanelDate();
264
+ }
265
+ this.setListenerForPressEscapeButton();
266
+ } else {
267
+ this.showPanelNone();
268
+ this.updateNow(this.value);
269
+ this.destroyListenerForPressEscapeButton();
270
+ }
271
+ this.emitEventBusDestroyAllListenerForPressButtonsForPanels();
272
+ },
273
+
274
+ getNow(value) {
275
+ return value
276
+ ? new Date(value)
277
+ : this.defaultValue && isValidDate(this.defaultValue)
278
+ ? new Date(this.defaultValue)
279
+ : new Date();
280
+ },
281
+
282
+ updateNow(value) {
283
+ this.now = this.getNow(value);
284
+ },
285
+
286
+ getCriticalTime(value) {
287
+ if (!value) {
288
+ return null;
289
+ }
290
+ const date = new Date(value);
291
+ if (this.type === "year") {
292
+ return new Date(date.getFullYear(), 0).getTime();
293
+ } else if (this.type === "month") {
294
+ return new Date(date.getFullYear(), date.getMonth()).getTime();
295
+ } else if (this.type === "date") {
296
+ return date.setHours(0, 0, 0, 0);
297
+ }
298
+ return date.getTime();
299
+ },
300
+
301
+ inBefore(time, startAt) {
302
+ if (startAt === undefined) {
303
+ startAt = this.startAt;
304
+ }
305
+ return (
306
+ (this.notBeforeTime && time < this.notBeforeTime) ||
307
+ (startAt && time < this.getCriticalTime(startAt))
308
+ );
309
+ },
310
+
311
+ inAfter(time, endAt) {
312
+ if (endAt === undefined) {
313
+ endAt = this.endAt;
314
+ }
315
+ return (
316
+ (this.notAfterTime && time > this.notAfterTime) ||
317
+ (endAt && time > this.getCriticalTime(endAt))
318
+ );
319
+ },
320
+
321
+ inDisabledDays(time) {
322
+ if (Array.isArray(this.disabledDays)) {
323
+ return this.disabledDays.some(v => this.getCriticalTime(v) === time);
324
+ }
325
+ if (typeof this.disabledDays === "function") {
326
+ return this.disabledDays(new Date(time));
327
+ }
328
+ return false;
329
+ },
330
+
331
+ isDisabledYear(year) {
332
+ const time = new Date(year, 0).getTime();
333
+ const maxTime = new Date(year + 1, 0).getTime() - 1;
334
+ return (
335
+ this.inBefore(maxTime) ||
336
+ this.inAfter(time) ||
337
+ (this.type === "year" && this.inDisabledDays(time))
338
+ );
339
+ },
340
+
341
+ isDisabledMonth(month) {
342
+ const time = new Date(this.calendarYear, month).getTime();
343
+ const maxTime = new Date(this.calendarYear, month + 1).getTime() - 1;
344
+ return (
345
+ this.inBefore(maxTime) ||
346
+ this.inAfter(time) ||
347
+ (this.type === "month" && this.inDisabledDays(time))
348
+ );
349
+ },
350
+
351
+ isDisabledDate(date) {
352
+ const time = new Date(date).getTime();
353
+ const maxTime = new Date(date).setHours(23, 59, 59, 999);
354
+ return (
355
+ this.inBefore(maxTime) ||
356
+ this.inAfter(time) ||
357
+ this.inDisabledDays(time)
358
+ );
359
+ },
360
+
361
+ isDisabledTime(date, startAt, endAt) {
362
+ const time = new Date(date).getTime();
363
+ return (
364
+ this.inBefore(time, startAt) ||
365
+ this.inAfter(time, endAt) ||
366
+ this.inDisabledDays(time)
367
+ );
368
+ },
369
+
370
+ selectDate(date) {
371
+ if (this.type === "datetime") {
372
+ let time = new Date(date);
373
+ if (isDateObject(this.value)) {
374
+ time.setHours(
375
+ this.value.getHours(),
376
+ this.value.getMinutes(),
377
+ this.value.getSeconds(),
378
+ );
379
+ }
380
+ if (this.isDisabledTime(time)) {
381
+ time.setHours(0, 0, 0, 0);
382
+ if (
383
+ this.notBefore &&
384
+ time.getTime() < new Date(this.notBefore).getTime()
385
+ ) {
386
+ time = new Date(this.notBefore);
387
+ }
388
+ if (
389
+ this.startAt &&
390
+ time.getTime() < new Date(this.startAt).getTime()
391
+ ) {
392
+ time = new Date(this.startAt);
393
+ }
394
+ }
395
+ this.selectTime(time);
396
+ this.showPanelTime();
397
+ return;
398
+ }
399
+ this.$emit("selectDate", date);
400
+ },
401
+
402
+ selectYear({ year, isButtonClick }) {
403
+ this.changeCalendarYear(year);
404
+ if (this.type.toLowerCase() === "year") {
405
+ return this.selectDate(new Date(this.now));
406
+ }
407
+ this.showPanelMonth();
408
+ if (isButtonClick) {
409
+ this.setFocusToActivePanel();
410
+ }
411
+ },
412
+
413
+ selectMonth({ month, isButtonClick }) {
414
+ this.changeCalendarMonth(month);
415
+ if (this.type.toLowerCase() === "month") {
416
+ return this.selectDate(new Date(this.now));
417
+ }
418
+ this.showPanelDate();
419
+ if (isButtonClick) {
420
+ this.setFocusToActivePanel();
421
+ }
422
+ },
423
+
424
+ selectTime(time, statusClose = false) {
425
+ this.$emit("selectTime", time, statusClose);
426
+ },
427
+
428
+ changeCalendarYear(year) {
429
+ this.updateNow(new Date(year, this.calendarMonth));
430
+ },
431
+
432
+ changeCalendarMonth(month) {
433
+ this.updateNow(new Date(this.calendarYear, month));
434
+ },
435
+
436
+ getSibling() {
437
+ const PANELS = [
438
+ this.$parent.$refs.calendarPanel,
439
+ ];
440
+ if (this.$parent.$refs.calendarPanel2) {
441
+ PANELS.push(this.$parent.$refs.calendarPanel2);
442
+ }
443
+ const calendars = PANELS.filter(
444
+ v => v.$options.name === this.$options.name,
445
+ );
446
+ const index = calendars.indexOf(this);
447
+ /* eslint-disable-next-line no-bitwise */
448
+ return calendars[index ^ 1];
449
+ },
450
+
451
+ handleIconMonth(flag) {
452
+ const month = this.calendarMonth;
453
+ this.changeCalendarMonth(month + flag);
454
+ this.$parent.$emit("changeCalendarMonth", {
455
+ month,
456
+ flag,
457
+ vm: this,
458
+ sibling: this.getSibling(),
459
+ });
460
+ },
461
+
462
+ handleIconYear(flag) {
463
+ if (this.panel === "YEAR") {
464
+ this.changePanelYears(flag);
465
+ } else {
466
+ const year = this.calendarYear;
467
+ this.changeCalendarYear(year + flag);
468
+ this.$parent.$emit("changeCalendarYear", {
469
+ year,
470
+ flag,
471
+ vm: this,
472
+ sibling: this.getSibling(),
473
+ });
474
+ }
475
+ },
476
+
477
+ handleBtnYear() {
478
+ this.showPanelYear();
479
+ if (this.isWorkWithKeyboard) {
480
+ this.setFocusToActivePanel();
481
+ }
482
+ },
483
+
484
+ handleBtnMonth() {
485
+ this.showPanelMonth();
486
+ if (this.isWorkWithKeyboard) {
487
+ this.setFocusToActivePanel();
488
+ }
489
+ },
490
+
491
+ handleTimeHeader() {
492
+ if (this.type === "time") {
493
+ return;
494
+ }
495
+ this.showPanelDate();
496
+ if (this.isWorkWithKeyboard) {
497
+ this.setFocusToActivePanel();
498
+ }
499
+ },
500
+
501
+ changePanelYears(flag) {
502
+ this.firstYear = this.firstYear + flag * 10;
503
+ },
504
+
505
+ showPanelNone() {
506
+ this.panel = "NONE";
507
+ this.isFocusPanelChild = false;
508
+ this.destroyListenerForPressTabButton();
509
+ this.emitEventBusDestroyAllListenerForPressButtonsForPanels();
510
+ this.setWorkWithoutKeyboard();
511
+ },
512
+
513
+ showPanelTime() {
514
+ this.panel = "TIME";
515
+ },
516
+
517
+ showPanelDate() {
518
+ this.panel = "DATE";
519
+ },
520
+
521
+ showPanelYear() {
522
+ this.panel = "YEAR";
523
+ },
524
+
525
+ showPanelMonth() {
526
+ this.panel = "MONTH";
527
+ },
528
+
529
+ setFocusToActivePanelFromParent() {
530
+ this.setWorkWithKeyboard();
531
+ this.setFocusToActivePanel();
532
+ this.setListenerForPressTabButton();
533
+ },
534
+
535
+ setFocusToActivePanel() {
536
+ this.isFocusPanelChild = true;
537
+ this.setFocusToActiveElementInChild();
538
+ },
539
+
540
+ removeFocusFromActivePanel() {
541
+ if (this.isFocusPanelChild) {
542
+ this.isFocusPanelChild = false;
543
+ this.emitEventBusDestroyAllListenerForPressButtonsForPanels();
544
+ }
545
+ },
546
+
547
+ setFocusToActiveElementInChild() {
548
+ if (this.panel === "DATE") {
549
+ this.$refs.panelDate.setFocusToActiveDay();
550
+ } else if (this.panel === "TIME") {
551
+ this.$refs.panelTime.setFocusToActiveTime();
552
+ } else if (this.panel === "YEAR") {
553
+ this.$refs.panelYear.setFocusToActiveYear();
554
+ } else if (this.panel === "MONTH") {
555
+ this.$refs.panelMonth.setFocusToActiveMonth();
556
+ }
557
+ },
558
+
559
+ setListenerForPressTabButton() {
560
+ document.addEventListener("keydown", this.pressTabButton);
561
+ },
562
+
563
+ destroyListenerForPressTabButton() {
564
+ document.removeEventListener("keydown", this.pressTabButton);
565
+ },
566
+
567
+ pressTabButton($event) {
568
+ const KEY_CODE = $event.keyCode;
569
+ if (KEY_CODE === keysCode.tab) {
570
+ this.trapFocus($event);
571
+ this.stopCurrentEvent($event);
572
+ }
573
+ },
574
+
575
+ trapFocus(EVENT) {
576
+ const FOCUSABLE_ELEMENTS = this.$el.querySelectorAll(".pux_datepicker__calendar__tab");
577
+ if (FOCUSABLE_ELEMENTS.length <= 1) {
578
+ return;
579
+ }
580
+ let isFocused = false;
581
+ let isFocusedPanel = false;
582
+ forEach(FOCUSABLE_ELEMENTS, (element, elementIndex) => {
583
+ if (document.activeElement === element) {
584
+ if (EVENT.shiftKey) {
585
+ if (elementIndex === 0) {
586
+ FOCUSABLE_ELEMENTS[FOCUSABLE_ELEMENTS.length - 1].focus();
587
+ isFocusedPanel = true;
588
+ } else {
589
+ FOCUSABLE_ELEMENTS[elementIndex - 1].focus();
590
+ }
591
+ } else {
592
+ if (elementIndex === FOCUSABLE_ELEMENTS.length - 1) {
593
+ FOCUSABLE_ELEMENTS[0].focus();
594
+ } else {
595
+ FOCUSABLE_ELEMENTS[elementIndex + 1].focus();
596
+ }
597
+ if (elementIndex === FOCUSABLE_ELEMENTS.length - 2) {
598
+ isFocusedPanel = true;
599
+ }
600
+ }
601
+ isFocused = true;
602
+ return false;
603
+ }
604
+ });
605
+ if (!isFocused) {
606
+ if (EVENT.shiftKey) {
607
+ FOCUSABLE_ELEMENTS[FOCUSABLE_ELEMENTS.length - 2].focus();
608
+ } else {
609
+ FOCUSABLE_ELEMENTS[0].focus();
610
+ }
611
+ }
612
+ if (isFocusedPanel) {
613
+ this.setFocusToActivePanel();
614
+ } else {
615
+ this.removeFocusFromActivePanel();
616
+ }
617
+ },
618
+
619
+ setWorkWithKeyboard() {
620
+ this.isWorkWithKeyboard = true;
621
+ },
622
+
623
+ setWorkWithoutKeyboard() {
624
+ this.isWorkWithKeyboard = false;
625
+ },
626
+
627
+ setListenerForPressEscapeButton() {
628
+ document.addEventListener("keydown", this.pressEscapeButton);
629
+ },
630
+
631
+ destroyListenerForPressEscapeButton() {
632
+ document.removeEventListener("keydown", this.pressEscapeButton);
633
+ },
634
+
635
+ closePopup() {
636
+ this.$emit("closePopup", true);
637
+ },
638
+
639
+ pressEscapeButton($event) {
640
+ const KEY_CODE = $event.keyCode;
641
+ if (KEY_CODE === keysCode.escape) {
642
+ this.closePopup();
643
+ }
644
+ },
645
+ },
646
+ };