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,301 +1,300 @@
1
- import {
2
- AButton,
3
- } from "aloha-vue";
4
-
5
- import PanelMixin from "../../mixins/PanelMixin";
6
-
7
- import keysCode from "../../utils/keysCode";
8
- import moment from "moment";
9
- import {
10
- formatDate,
11
- } from "../../utils";
12
-
13
-
14
- // @vue/component
15
- export default {
16
- name: "PanelDate",
17
- components: {
18
- AButton,
19
- },
20
- mixins: [
21
- PanelMixin,
22
- ],
23
- props: {
24
- value: {
25
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
26
- required: false,
27
- default: undefined,
28
- },
29
- startAt: {
30
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
31
- required: false,
32
- default: undefined,
33
- },
34
- endAt: {
35
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
36
- required: false,
37
- default: undefined,
38
- },
39
- dateFormat: {
40
- type: String,
41
- default: "YYYY-MM-DD",
42
- },
43
- calendarMonth: {
44
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
45
- default: new Date().getMonth(),
46
- },
47
- calendarYear: {
48
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
49
- default: new Date().getFullYear(),
50
- },
51
- firstDayOfWeek: {
52
- default: 7,
53
- type: Number,
54
- validator: val => val >= 1 && val <= 7,
55
- },
56
- disabledDate: {
57
- type: Function,
58
- default: () => {
59
- return false;
60
- },
61
- },
62
- currentLanguage: {
63
- type: Object,
64
- required: true,
65
- },
66
- },
67
- emits: [
68
- "handleIconMonth",
69
- "select",
70
- ],
71
- data() {
72
- return {
73
- dayForFocusButton: undefined,
74
- };
75
- },
76
- computed: {
77
- ths() {
78
- return this.getDays(this.firstDayOfWeek);
79
- },
80
-
81
- dates() {
82
- return this.getDates(this.calendarYear, this.calendarMonth, this.firstDayOfWeek);
83
- },
84
-
85
- trsWithTds() {
86
- const TRS_WITH_TDS = [];
87
- for (let i = 0; i < 6; i++) {
88
- const TDS = [];
89
- this.dates.slice(7 * i, 7 * i + 7).forEach(date => {
90
- const IS_TODAY = this.isCurrentDayToday(date);
91
- const CELL_TIME = this.getCellTime(date);
92
- const IS_DISABLED = this.disabledDate(CELL_TIME);
93
- TDS.push({
94
- class: this.getCellClasses({
95
- cellTime: CELL_TIME,
96
- isToday: IS_TODAY,
97
- month: date.month,
98
- }),
99
- id: this.getId({
100
- month: date.month,
101
- day: date.day,
102
- }),
103
- year: date.year,
104
- month: date.month,
105
- fullDate: this.getCellTitle(date),
106
- date: date,
107
- label: date.day,
108
- isToday: IS_TODAY,
109
- isDisabled: IS_DISABLED,
110
- isCurrentMonth: date.month === this.calendarMonth,
111
- });
112
- });
113
- TRS_WITH_TDS.push(TDS);
114
- }
115
- return TRS_WITH_TDS;
116
- },
117
-
118
- dayFromValueOrToday() {
119
- return this.dayFromValue || new Date().getDate();
120
- },
121
-
122
- dayFromValue() {
123
- if (this.value) {
124
- return new Date(this.value).getDate();
125
- }
126
- return "";
127
- },
128
-
129
- idForFocus() {
130
- if (this.dayForFocusButton) {
131
- return `${ this.id }_${ this.dayForFocusButton }`;
132
- }
133
- return "";
134
- },
135
-
136
- daysInMonth() {
137
- return moment(`${ this.calendarYear }_${ this.calendarMonth + 1 }`, "YYYY-MM").daysInMonth();
138
- },
139
-
140
- todayTranslate() {
141
- return this.currentLanguage.today;
142
- },
143
- },
144
- methods: {
145
- selectDate({ year, month, day }) {
146
- const date = new Date(year, month, day);
147
- if (this.disabledDate(date)) {
148
- return;
149
- }
150
- this.$emit("select", date);
151
- },
152
-
153
- getDays(firstDayOfWeek) {
154
- const days = this.currentLanguage.days;
155
- const firstday = parseInt(firstDayOfWeek, 10);
156
- return days.concat(days).slice(firstday, firstday + 7);
157
- },
158
-
159
- getDates(year, month, firstDayOfWeek) {
160
- const arr = [];
161
- const time = new Date(year, month);
162
-
163
- time.setDate(0);
164
- const lastMonthLength = (time.getDay() + 7 - firstDayOfWeek) % 7 + 1;
165
- const lastMonthfirst = time.getDate() - (lastMonthLength - 1);
166
- for (let i = 0; i < lastMonthLength; i++) {
167
- arr.push({ year, month: month - 1, day: lastMonthfirst + i });
168
- }
169
-
170
- time.setMonth(time.getMonth() + 2, 0);
171
- const curMonthLength = time.getDate();
172
- for (let i = 0; i < curMonthLength; i++) {
173
- arr.push({ year, month, day: 1 + i });
174
- }
175
-
176
- time.setMonth(time.getMonth() + 1, 1);
177
- const nextMonthLength = 42 - (lastMonthLength + curMonthLength);
178
- for (let i = 0; i < nextMonthLength; i++) {
179
- arr.push({ year, month: month + 1, day: 1 + i });
180
- }
181
-
182
- return arr;
183
- },
184
-
185
- isCurrentDayToday({ year, month, day }) {
186
- const CELL_TIME = this.getCellTime({ year, month, day });
187
- const TODAY = new Date().setHours(0, 0, 0, 0);
188
- return CELL_TIME === TODAY;
189
- },
190
-
191
- getCellClasses({ cellTime, isToday, month }) {
192
- const CLASSES = [];
193
- const CURRENT_TIME = this.value && new Date(this.value).setHours(0, 0, 0, 0);
194
- const START_TIME = this.startAt && new Date(this.startAt).setHours(0, 0, 0, 0);
195
- const END_TIME = this.endAt && new Date(this.endAt).setHours(0, 0, 0, 0);
196
-
197
- if (month < this.calendarMonth) {
198
- CLASSES.push("last-month");
199
- } else if (month > this.calendarMonth) {
200
- CLASSES.push("next-month");
201
- } else {
202
- CLASSES.push("cur-month");
203
- }
204
-
205
- if (isToday) {
206
- CLASSES.push("today");
207
- }
208
-
209
- if (this.disabledDate(cellTime)) {
210
- CLASSES.push("disabled");
211
- }
212
-
213
- if (CURRENT_TIME) {
214
- if (cellTime === CURRENT_TIME) {
215
- CLASSES.push("actived");
216
- } else if (START_TIME && cellTime <= CURRENT_TIME) {
217
- CLASSES.push("inrange");
218
- } else if (END_TIME && cellTime >= CURRENT_TIME) {
219
- CLASSES.push("inrange");
220
- }
221
- }
222
- return CLASSES.join(" ");
223
- },
224
-
225
- getCellTime({ year, month, day }) {
226
- return new Date(year, month, day).getTime();
227
- },
228
-
229
- getCellTitle({ year, month, day }) {
230
- return formatDate(new Date(year, month, day), this.dateFormat);
231
- },
232
-
233
- getId({ month, day }) {
234
- let id = `${ this.id }_${ day }`;
235
- if (month < this.calendarMonth) {
236
- id += "_last_month";
237
- } else if (month > this.calendarMonth) {
238
- id += "_next_month";
239
- }
240
- return id;
241
- },
242
-
243
- setFocusToActiveDay() {
244
- setTimeout(() => {
245
- this.setDefaultDayForFocusButton();
246
- document.getElementById(this.idForFocus).focus();
247
- this.setListenerForPressButtons();
248
- });
249
- },
250
-
251
- setDefaultDayForFocusButton() {
252
- this.dayForFocusButton = this.dayFromValueOrToday;
253
- },
254
-
255
- pressButton($event) {
256
- const KEY_CODE = $event.keyCode;
257
- if (KEY_CODE === keysCode.arrowUp) {
258
- this.setFocusToPast(7);
259
- this.stopCurrentEvent($event);
260
- } else if (KEY_CODE === keysCode.arrowDown) {
261
- this.setFocusToFuture(7);
262
- this.stopCurrentEvent($event);
263
- } else if (KEY_CODE === keysCode.arrowLeft) {
264
- this.setFocusToPast(1);
265
- this.stopCurrentEvent($event);
266
- } else if (KEY_CODE === keysCode.arrowRight) {
267
- this.setFocusToFuture(1);
268
- this.stopCurrentEvent($event);
269
- }
270
- },
271
-
272
- setFocusToPast(minusDays) {
273
- const NEW_DAY_FOR_BUTTON = this.dayForFocusButton - minusDays;
274
- if (NEW_DAY_FOR_BUTTON > 0) {
275
- this.dayForFocusButton = NEW_DAY_FOR_BUTTON;
276
- } else {
277
- this.$emit("handleIconMonth", -1);
278
- setTimeout(() => {
279
- this.dayForFocusButton = this.daysInMonth - Math.abs(NEW_DAY_FOR_BUTTON);
280
- });
281
- }
282
- this.setFocusToElementWithTimeout(this.idForFocus);
283
- },
284
-
285
- setFocusToFuture(plusDays) {
286
- const NEW_DAY_FOR_BUTTON = this.dayForFocusButton + plusDays;
287
- if (NEW_DAY_FOR_BUTTON <= this.daysInMonth) {
288
- this.dayForFocusButton = NEW_DAY_FOR_BUTTON;
289
- } else {
290
- const ALT_DAY_IN_MONTH = this.daysInMonth;
291
- this.$emit("handleIconMonth", 1);
292
- this.dayForFocusButton = NEW_DAY_FOR_BUTTON - ALT_DAY_IN_MONTH;
293
- }
294
- this.setFocusToElementWithTimeout(this.idForFocus);
295
- },
296
-
297
- destroyListenerForPressButtonsCallback() {
298
- this.dayForFocusButton = undefined;
299
- },
300
- },
301
- };
1
+ import {
2
+ AButton,
3
+ } from "aloha-vue";
4
+
5
+ import PanelMixin from "../../mixins/PanelMixin";
6
+ import keysCode from "../../utils/keysCode";
7
+ import moment from "moment";
8
+ import {
9
+ formatDate,
10
+ } from "../../utils";
11
+
12
+
13
+ // @vue/component
14
+ export default {
15
+ name: "PanelDate",
16
+ components: {
17
+ AButton,
18
+ },
19
+ mixins: [
20
+ PanelMixin,
21
+ ],
22
+ props: {
23
+ value: {
24
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
25
+ required: false,
26
+ default: undefined,
27
+ },
28
+ startAt: {
29
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
30
+ required: false,
31
+ default: undefined,
32
+ },
33
+ endAt: {
34
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
35
+ required: false,
36
+ default: undefined,
37
+ },
38
+ dateFormat: {
39
+ type: String,
40
+ default: "YYYY-MM-DD",
41
+ },
42
+ calendarMonth: {
43
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
44
+ default: new Date().getMonth(),
45
+ },
46
+ calendarYear: {
47
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
48
+ default: new Date().getFullYear(),
49
+ },
50
+ firstDayOfWeek: {
51
+ default: 7,
52
+ type: Number,
53
+ validator: val => val >= 1 && val <= 7,
54
+ },
55
+ disabledDate: {
56
+ type: Function,
57
+ default: () => {
58
+ return false;
59
+ },
60
+ },
61
+ currentLanguage: {
62
+ type: Object,
63
+ required: true,
64
+ },
65
+ },
66
+ emits: [
67
+ "handleIconMonth",
68
+ "select",
69
+ ],
70
+ data() {
71
+ return {
72
+ dayForFocusButton: undefined,
73
+ };
74
+ },
75
+ computed: {
76
+ ths() {
77
+ return this.getDays(this.firstDayOfWeek);
78
+ },
79
+
80
+ dates() {
81
+ return this.getDates(this.calendarYear, this.calendarMonth, this.firstDayOfWeek);
82
+ },
83
+
84
+ trsWithTds() {
85
+ const TRS_WITH_TDS = [];
86
+ for (let i = 0; i < 6; i++) {
87
+ const TDS = [];
88
+ this.dates.slice(7 * i, 7 * i + 7).forEach(date => {
89
+ const IS_TODAY = this.isCurrentDayToday(date);
90
+ const CELL_TIME = this.getCellTime(date);
91
+ const IS_DISABLED = this.disabledDate(CELL_TIME);
92
+ TDS.push({
93
+ class: this.getCellClasses({
94
+ cellTime: CELL_TIME,
95
+ isToday: IS_TODAY,
96
+ month: date.month,
97
+ }),
98
+ id: this.getId({
99
+ month: date.month,
100
+ day: date.day,
101
+ }),
102
+ year: date.year,
103
+ month: date.month,
104
+ fullDate: this.getCellTitle(date),
105
+ date: date,
106
+ label: date.day,
107
+ isToday: IS_TODAY,
108
+ isDisabled: IS_DISABLED,
109
+ isCurrentMonth: date.month === this.calendarMonth,
110
+ });
111
+ });
112
+ TRS_WITH_TDS.push(TDS);
113
+ }
114
+ return TRS_WITH_TDS;
115
+ },
116
+
117
+ dayFromValueOrToday() {
118
+ return this.dayFromValue || new Date().getDate();
119
+ },
120
+
121
+ dayFromValue() {
122
+ if (this.value) {
123
+ return new Date(this.value).getDate();
124
+ }
125
+ return "";
126
+ },
127
+
128
+ idForFocus() {
129
+ if (this.dayForFocusButton) {
130
+ return `${ this.id }_${ this.dayForFocusButton }`;
131
+ }
132
+ return "";
133
+ },
134
+
135
+ daysInMonth() {
136
+ return moment(`${ this.calendarYear }_${ this.calendarMonth + 1 }`, "YYYY-MM").daysInMonth();
137
+ },
138
+
139
+ todayTranslate() {
140
+ return this.currentLanguage.today;
141
+ },
142
+ },
143
+ methods: {
144
+ selectDate({ year, month, day }) {
145
+ const date = new Date(year, month, day);
146
+ if (this.disabledDate(date)) {
147
+ return;
148
+ }
149
+ this.$emit("select", date);
150
+ },
151
+
152
+ getDays(firstDayOfWeek) {
153
+ const days = this.currentLanguage.days;
154
+ const firstday = parseInt(firstDayOfWeek, 10);
155
+ return days.concat(days).slice(firstday, firstday + 7);
156
+ },
157
+
158
+ getDates(year, month, firstDayOfWeek) {
159
+ const arr = [];
160
+ const time = new Date(year, month);
161
+
162
+ time.setDate(0);
163
+ const lastMonthLength = (time.getDay() + 7 - firstDayOfWeek) % 7 + 1;
164
+ const lastMonthfirst = time.getDate() - (lastMonthLength - 1);
165
+ for (let i = 0; i < lastMonthLength; i++) {
166
+ arr.push({ year, month: month - 1, day: lastMonthfirst + i });
167
+ }
168
+
169
+ time.setMonth(time.getMonth() + 2, 0);
170
+ const curMonthLength = time.getDate();
171
+ for (let i = 0; i < curMonthLength; i++) {
172
+ arr.push({ year, month, day: 1 + i });
173
+ }
174
+
175
+ time.setMonth(time.getMonth() + 1, 1);
176
+ const nextMonthLength = 42 - (lastMonthLength + curMonthLength);
177
+ for (let i = 0; i < nextMonthLength; i++) {
178
+ arr.push({ year, month: month + 1, day: 1 + i });
179
+ }
180
+
181
+ return arr;
182
+ },
183
+
184
+ isCurrentDayToday({ year, month, day }) {
185
+ const CELL_TIME = this.getCellTime({ year, month, day });
186
+ const TODAY = new Date().setHours(0, 0, 0, 0);
187
+ return CELL_TIME === TODAY;
188
+ },
189
+
190
+ getCellClasses({ cellTime, isToday, month }) {
191
+ const CLASSES = [];
192
+ const CURRENT_TIME = this.value && new Date(this.value).setHours(0, 0, 0, 0);
193
+ const START_TIME = this.startAt && new Date(this.startAt).setHours(0, 0, 0, 0);
194
+ const END_TIME = this.endAt && new Date(this.endAt).setHours(0, 0, 0, 0);
195
+
196
+ if (month < this.calendarMonth) {
197
+ CLASSES.push("last-month");
198
+ } else if (month > this.calendarMonth) {
199
+ CLASSES.push("next-month");
200
+ } else {
201
+ CLASSES.push("cur-month");
202
+ }
203
+
204
+ if (isToday) {
205
+ CLASSES.push("today");
206
+ }
207
+
208
+ if (this.disabledDate(cellTime)) {
209
+ CLASSES.push("disabled");
210
+ }
211
+
212
+ if (CURRENT_TIME) {
213
+ if (cellTime === CURRENT_TIME) {
214
+ CLASSES.push("actived");
215
+ } else if (START_TIME && cellTime <= CURRENT_TIME) {
216
+ CLASSES.push("inrange");
217
+ } else if (END_TIME && cellTime >= CURRENT_TIME) {
218
+ CLASSES.push("inrange");
219
+ }
220
+ }
221
+ return CLASSES.join(" ");
222
+ },
223
+
224
+ getCellTime({ year, month, day }) {
225
+ return new Date(year, month, day).getTime();
226
+ },
227
+
228
+ getCellTitle({ year, month, day }) {
229
+ return formatDate(new Date(year, month, day), this.dateFormat);
230
+ },
231
+
232
+ getId({ month, day }) {
233
+ let id = `${ this.id }_${ day }`;
234
+ if (month < this.calendarMonth) {
235
+ id += "_last_month";
236
+ } else if (month > this.calendarMonth) {
237
+ id += "_next_month";
238
+ }
239
+ return id;
240
+ },
241
+
242
+ setFocusToActiveDay() {
243
+ setTimeout(() => {
244
+ this.setDefaultDayForFocusButton();
245
+ document.getElementById(this.idForFocus).focus();
246
+ this.setListenerForPressButtons();
247
+ });
248
+ },
249
+
250
+ setDefaultDayForFocusButton() {
251
+ this.dayForFocusButton = this.dayFromValueOrToday;
252
+ },
253
+
254
+ pressButton($event) {
255
+ const KEY_CODE = $event.keyCode;
256
+ if (KEY_CODE === keysCode.arrowUp) {
257
+ this.setFocusToPast(7);
258
+ this.stopCurrentEvent($event);
259
+ } else if (KEY_CODE === keysCode.arrowDown) {
260
+ this.setFocusToFuture(7);
261
+ this.stopCurrentEvent($event);
262
+ } else if (KEY_CODE === keysCode.arrowLeft) {
263
+ this.setFocusToPast(1);
264
+ this.stopCurrentEvent($event);
265
+ } else if (KEY_CODE === keysCode.arrowRight) {
266
+ this.setFocusToFuture(1);
267
+ this.stopCurrentEvent($event);
268
+ }
269
+ },
270
+
271
+ setFocusToPast(minusDays) {
272
+ const NEW_DAY_FOR_BUTTON = this.dayForFocusButton - minusDays;
273
+ if (NEW_DAY_FOR_BUTTON > 0) {
274
+ this.dayForFocusButton = NEW_DAY_FOR_BUTTON;
275
+ } else {
276
+ this.$emit("handleIconMonth", -1);
277
+ setTimeout(() => {
278
+ this.dayForFocusButton = this.daysInMonth - Math.abs(NEW_DAY_FOR_BUTTON);
279
+ });
280
+ }
281
+ this.setFocusToElementWithTimeout(this.idForFocus);
282
+ },
283
+
284
+ setFocusToFuture(plusDays) {
285
+ const NEW_DAY_FOR_BUTTON = this.dayForFocusButton + plusDays;
286
+ if (NEW_DAY_FOR_BUTTON <= this.daysInMonth) {
287
+ this.dayForFocusButton = NEW_DAY_FOR_BUTTON;
288
+ } else {
289
+ const ALT_DAY_IN_MONTH = this.daysInMonth;
290
+ this.$emit("handleIconMonth", 1);
291
+ this.dayForFocusButton = NEW_DAY_FOR_BUTTON - ALT_DAY_IN_MONTH;
292
+ }
293
+ this.setFocusToElementWithTimeout(this.idForFocus);
294
+ },
295
+
296
+ destroyListenerForPressButtonsCallback() {
297
+ this.dayForFocusButton = undefined;
298
+ },
299
+ },
300
+ };