aloha-vue 2.85.0 → 2.87.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 (245) hide show
  1. package/CHANGELOG.md +1215 -1200
  2. package/README.md +117 -117
  3. package/dist/aloha-vue.css +13827 -13601
  4. package/dist/aloha-vue.css.map +1 -1
  5. package/dist/aloha-vue.es.js +60235 -57401
  6. package/dist/aloha-vue.umd.js +319 -319
  7. package/package.json +1 -1
  8. package/scss/components/AButton.scss +6 -6
  9. package/scss/components/ADivider.scss +9 -9
  10. package/scss/components/AElement.scss +6 -6
  11. package/scss/components/AGroupButtonDropdown.scss +4 -4
  12. package/scss/components/AIcon.scss +17 -17
  13. package/scss/components/ALoading.scss +18 -18
  14. package/scss/components/AMenu.scss +634 -634
  15. package/scss/components/AProgressCirle.scss +43 -43
  16. package/scss/components/AShowMore.scss +9 -9
  17. package/scss/components/ATableForm.scss +7 -7
  18. package/scss/components/ATabs.scss +186 -186
  19. package/scss/components/ui/AColorPicker.scss +243 -0
  20. package/scss/components/ui/AJson.scss +11 -11
  21. package/scss/components/ui/ui.scss +1 -0
  22. package/scss/text/text_line_height.scss +17 -17
  23. package/scss/text/text_size.scss +88 -88
  24. package/scss/utils/acordion.scss +173 -173
  25. package/scss/utils/alert.scss +81 -81
  26. package/scss/utils/aloha_prefix.scss +1 -1
  27. package/scss/utils/backdrop.scss +24 -24
  28. package/scss/utils/border.scss +65 -65
  29. package/scss/utils/breakpoint.scss +48 -48
  30. package/scss/utils/button_close.scss +22 -22
  31. package/scss/utils/button_group.scss +69 -69
  32. package/scss/utils/color_utils.scss +234 -234
  33. package/scss/utils/display.scss +67 -67
  34. package/scss/utils/flex.scss +141 -141
  35. package/scss/utils/float.scss +10 -10
  36. package/scss/utils/global.scss +44 -44
  37. package/scss/utils/global_variables.scss +26 -26
  38. package/scss/utils/grid.scss +95 -95
  39. package/scss/utils/list_columns.scss +31 -31
  40. package/scss/utils/list_group.scss +127 -127
  41. package/scss/utils/notification.scss +36 -36
  42. package/scss/utils/overflow.scss +40 -40
  43. package/scss/utils/pagination.scss +94 -94
  44. package/scss/utils/position.scss +90 -90
  45. package/scss/utils/progress.scss +70 -70
  46. package/scss/utils/screenreader.scss +16 -16
  47. package/scss/utils/spinner.scss +35 -35
  48. package/scss/utils/utils.scss +19 -19
  49. package/scss/utils/vars_global.scss +12 -12
  50. package/src/AAlert/i18n/AAlertI18n.js +4 -0
  51. package/src/AAlert/i18n/nl.json +3 -0
  52. package/src/AAlert/i18n/pl.json +3 -0
  53. package/src/ACarousel/i18n/ACarouselI18n.js +4 -0
  54. package/src/ACarousel/i18n/nl.json +9 -0
  55. package/src/ACarousel/i18n/pl.json +9 -0
  56. package/src/ACloak/i18n/ACloakI18n.js +4 -0
  57. package/src/ACloak/i18n/nl.json +3 -0
  58. package/src/ACloak/i18n/pl.json +3 -0
  59. package/src/ADisclosure/i18n/ADisclosureI18n.js +4 -0
  60. package/src/ADisclosure/i18n/nl.json +4 -0
  61. package/src/ADisclosure/i18n/pl.json +4 -0
  62. package/src/AFilters/i18n/AFiltersI18n.js +4 -0
  63. package/src/AFilters/i18n/nl.json +30 -0
  64. package/src/AFilters/i18n/pl.json +30 -0
  65. package/src/AGroupButtonDropdown/AGroupButtonDropdown.js +119 -119
  66. package/src/ALinkCopy/i18n/ALinkCopyI18n.js +4 -0
  67. package/src/ALinkCopy/i18n/nl.json +4 -0
  68. package/src/ALinkCopy/i18n/pl.json +4 -0
  69. package/src/ALoading/i18n/ALoadingI18n.js +4 -0
  70. package/src/ALoading/i18n/nl.json +3 -0
  71. package/src/ALoading/i18n/pl.json +3 -0
  72. package/src/AMenu/i18n/AMenu2I18n.js +4 -0
  73. package/src/AMenu/i18n/nl.json +14 -0
  74. package/src/AMenu/i18n/pl.json +14 -0
  75. package/src/AModal/compositionAPI/ZIndexAPI.js +48 -48
  76. package/src/AModal/i18n/AModalI18n.js +4 -0
  77. package/src/AModal/i18n/nl.json +7 -0
  78. package/src/AModal/i18n/pl.json +7 -0
  79. package/src/APagination/i18n/APaginationI18n.js +4 -0
  80. package/src/APagination/i18n/nl.json +12 -0
  81. package/src/APagination/i18n/pl.json +12 -0
  82. package/src/AProgress/AProgress.js +141 -141
  83. package/src/AProgressCircle/AProgressCircle.js +160 -160
  84. package/src/AShowMore/i18n/AShowMoreI18n.js +4 -0
  85. package/src/AShowMore/i18n/nl.json +6 -0
  86. package/src/AShowMore/i18n/pl.json +6 -0
  87. package/src/ASpinner/i18n/ASpinnerI18n.js +4 -0
  88. package/src/ASpinner/i18n/nl.json +3 -0
  89. package/src/ASpinner/i18n/pl.json +3 -0
  90. package/src/ATable/ATableHeaderTh/ATableHeaderTh.js +188 -188
  91. package/src/ATable/i18n/ATableI18n.js +4 -0
  92. package/src/ATable/i18n/nl.json +54 -0
  93. package/src/ATable/i18n/pl.json +54 -0
  94. package/src/ATableForm/i18n/ATableFormI18n.js +4 -0
  95. package/src/ATableForm/i18n/nl.json +18 -0
  96. package/src/ATableForm/i18n/pl.json +18 -0
  97. package/src/ATranslation/compositionAPI/UtilsAPI.js +6 -1
  98. package/src/ATranslation/compositionAPI/__tests__/UtilsAPI.getTranslatedText.test.js +38 -0
  99. package/src/AVerticalScroll/i18n/AVerticalScrollI18n.js +4 -0
  100. package/src/AVerticalScroll/i18n/nl.json +4 -0
  101. package/src/AVerticalScroll/i18n/pl.json +4 -0
  102. package/src/AWizard/i18n/AWizardI18n.js +4 -0
  103. package/src/AWizard/i18n/nl.json +16 -0
  104. package/src/AWizard/i18n/pl.json +16 -0
  105. package/src/PVP/new.txt +39 -39
  106. package/src/PuxDatepicker/PuxDatepicker.js +670 -670
  107. package/src/PuxDatepicker/PuxDatepicker.pug +131 -131
  108. package/src/PuxDatepicker/PuxDatepicker.vue +2 -2
  109. package/src/PuxDatepicker/PuxDatepickerCalendarPanel/PuxDatepickerCalendarPanel.pug +136 -136
  110. package/src/PuxDatepicker/PuxDatepickerCalendarPanel/PuxDatepickerCalendarPanel.vue +2 -2
  111. package/src/PuxDatepicker/PuxDatepickerIcon/PuxDatepickerIcon.js +30 -30
  112. package/src/PuxDatepicker/PuxDatepickerIcon/PuxDatepickerIcon.pug +6 -6
  113. package/src/PuxDatepicker/PuxDatepickerIcon/PuxDatepickerIcon.vue +2 -2
  114. package/src/PuxDatepicker/locale/languages.js +174 -174
  115. package/src/PuxDatepicker/mixins/PanelMixin.js +76 -76
  116. package/src/PuxDatepicker/panel/PanelDate/PanelDate.pug +41 -41
  117. package/src/PuxDatepicker/panel/PanelDate/PanelDate.vue +2 -2
  118. package/src/PuxDatepicker/panel/PanelMonth/PanelMonth.pug +16 -16
  119. package/src/PuxDatepicker/panel/PanelMonth/PanelMonth.vue +2 -2
  120. package/src/PuxDatepicker/panel/PanelTime/PanelTime.pug +20 -20
  121. package/src/PuxDatepicker/panel/PanelTime/PanelTime.vue +2 -2
  122. package/src/PuxDatepicker/panel/PanelYear/PanelYear.pug +16 -16
  123. package/src/PuxDatepicker/panel/PanelYear/PanelYear.vue +2 -2
  124. package/src/PuxDatepicker/panel/PanelYearItem/PanelYearItem.js +55 -55
  125. package/src/PuxDatepicker/panel/PanelYearItem/PanelYearItem.pug +9 -9
  126. package/src/PuxDatepicker/panel/PanelYearItem/PanelYearItem.vue +2 -2
  127. package/src/PuxDatepicker/utils/keysCode.js +9 -9
  128. package/src/PuxDatepicker/utils/scroll-into-view.js +23 -23
  129. package/src/PuxDatepicker/utils/transform.js +23 -23
  130. package/src/filters/i18n/Filters18n.js +4 -0
  131. package/src/filters/i18n/nl.json +11 -0
  132. package/src/filters/i18n/pl.json +11 -0
  133. package/src/i18n/allLanguages.js +96 -0
  134. package/src/i18n/nl.json +4 -0
  135. package/src/i18n/pl.json +4 -0
  136. package/src/index.js +4 -0
  137. package/src/ui/ACheckbox/ACheckbox.js +5 -0
  138. package/src/ui/ACheckbox/i18n/ACheckboxI18n.js +4 -0
  139. package/src/ui/ACheckbox/i18n/nl.json +5 -0
  140. package/src/ui/ACheckbox/i18n/pl.json +5 -0
  141. package/src/ui/AColorPicker/AColorPicker.js +743 -0
  142. package/src/ui/AColorPicker/AColorPickerSaturation/AColorPickerSaturation.js +102 -0
  143. package/src/ui/AColorPicker/AColorPickerSaturation/compositionAPI/SaturationAPI.js +77 -0
  144. package/src/ui/AColorPicker/AColorPickerSlider/AColorPickerSlider.js +125 -0
  145. package/src/ui/AColorPicker/AColorPickerSlider/compositionAPI/SliderAPI.js +73 -0
  146. package/src/ui/AColorPicker/__tests__/AColorPicker.test.js +204 -0
  147. package/src/ui/AColorPicker/__tests__/colorUtils.test.js +104 -0
  148. package/src/ui/AColorPicker/compositionAPI/ColorStateAPI.js +133 -0
  149. package/src/ui/AColorPicker/compositionAPI/ConfirmAPI.js +36 -0
  150. package/src/ui/AColorPicker/compositionAPI/FormatAPI.js +59 -0
  151. package/src/ui/AColorPicker/compositionAPI/InputAPI.js +63 -0
  152. package/src/ui/AColorPicker/compositionAPI/KeyboardStepAPI.js +42 -0
  153. package/src/ui/AColorPicker/compositionAPI/PointerDragAPI.js +70 -0
  154. package/src/ui/AColorPicker/compositionAPI/PopoverAPI.js +196 -0
  155. package/src/ui/AColorPicker/compositionAPI/PredefineAPI.js +42 -0
  156. package/src/ui/AColorPicker/compositionAPI/ToggleClassAPI.js +24 -0
  157. package/src/ui/AColorPicker/i18n/AColorPickerI18n.js +25 -0
  158. package/src/ui/AColorPicker/i18n/ar.json +14 -0
  159. package/src/ui/AColorPicker/i18n/de.json +14 -0
  160. package/src/ui/AColorPicker/i18n/en.json +14 -0
  161. package/src/ui/AColorPicker/i18n/es.json +14 -0
  162. package/src/ui/AColorPicker/i18n/fr.json +14 -0
  163. package/src/ui/AColorPicker/i18n/hr.json +14 -0
  164. package/src/ui/AColorPicker/i18n/it.json +14 -0
  165. package/src/ui/AColorPicker/i18n/nl.json +14 -0
  166. package/src/ui/AColorPicker/i18n/pl.json +14 -0
  167. package/src/ui/AColorPicker/i18n/ru.json +14 -0
  168. package/src/ui/AColorPicker/i18n/uk.json +14 -0
  169. package/src/ui/AColorPicker/utils/colorUtils.js +296 -0
  170. package/src/ui/ADatepicker/ADatepickerCalendarPanel/ADatepickerCalendarPanel.js +68 -68
  171. package/src/ui/ADatepicker/i18n/ADatepickerI18n.js +4 -0
  172. package/src/ui/ADatepicker/i18n/nl.json +58 -0
  173. package/src/ui/ADatepicker/i18n/pl.json +58 -0
  174. package/src/ui/ADatepicker/panel/APanelTime/APanelTime.js +147 -147
  175. package/src/ui/ADatepicker/panel/APanelYear/APanelYear.js +123 -123
  176. package/src/ui/ADatepickerAlt/ADatepickerCalendarPanel/ADatepickerCalendarPanel.js +804 -804
  177. package/src/ui/ADatepickerAlt/panel/APanelDate/APanelDate.js +353 -353
  178. package/src/ui/ADatepickerAlt/panel/APanelMonth/APanelMonth.js +187 -187
  179. package/src/ui/ADatepickerAlt/panel/APanelTime/APanelTime.js +303 -303
  180. package/src/ui/ADatepickerAlt/panel/APanelYear/APanelYear.js +162 -162
  181. package/src/ui/ADatepickerRange/i18n/ADatepickerRangeI18n.js +4 -0
  182. package/src/ui/ADatepickerRange/i18n/nl.json +4 -0
  183. package/src/ui/ADatepickerRange/i18n/pl.json +4 -0
  184. package/src/ui/AErrors/i18n/AErrorsI18n.js +4 -0
  185. package/src/ui/AErrors/i18n/nl.json +3 -0
  186. package/src/ui/AErrors/i18n/pl.json +3 -0
  187. package/src/ui/AFieldset/__tests__/AFieldset.ClassColumn.test.js +1 -0
  188. package/src/ui/AFieldset/i18n/AFieldsetI18n.js +4 -0
  189. package/src/ui/AFieldset/i18n/nl.json +4 -0
  190. package/src/ui/AFieldset/i18n/pl.json +4 -0
  191. package/src/ui/AFormElementBtnClear/i18n/AFormElementBtnClearI18n.js +4 -0
  192. package/src/ui/AFormElementBtnClear/i18n/nl.json +3 -0
  193. package/src/ui/AFormElementBtnClear/i18n/pl.json +3 -0
  194. package/src/ui/AInput/i18n/AInputI18n.js +4 -0
  195. package/src/ui/AInput/i18n/nl.json +4 -0
  196. package/src/ui/AInput/i18n/pl.json +4 -0
  197. package/src/ui/AInputCurrency/i18n/AInputCurrencyI18n.js +4 -0
  198. package/src/ui/AInputCurrency/i18n/nl.json +4 -0
  199. package/src/ui/AInputCurrency/i18n/pl.json +4 -0
  200. package/src/ui/AInputNumber/i18n/AInputNumberI18n.js +4 -0
  201. package/src/ui/AInputNumber/i18n/nl.json +4 -0
  202. package/src/ui/AInputNumber/i18n/pl.json +4 -0
  203. package/src/ui/AInputNumberRange/i18n/AInputNumberRangeI18n.js +4 -0
  204. package/src/ui/AInputNumberRange/i18n/nl.json +4 -0
  205. package/src/ui/AInputNumberRange/i18n/pl.json +4 -0
  206. package/src/ui/AJson/i18n/AJsonI18n.js +4 -0
  207. package/src/ui/AJson/i18n/nl.json +8 -0
  208. package/src/ui/AJson/i18n/pl.json +8 -0
  209. package/src/ui/AMultiselectOrdered/i18n/AMultiselectOrderedI18n.js +4 -0
  210. package/src/ui/AMultiselectOrdered/i18n/nl.json +12 -0
  211. package/src/ui/AMultiselectOrdered/i18n/pl.json +12 -0
  212. package/src/ui/ARadio/i18n/ARadioI18n.js +4 -0
  213. package/src/ui/ARadio/i18n/nl.json +5 -0
  214. package/src/ui/ARadio/i18n/pl.json +5 -0
  215. package/src/ui/ARequired/i18n/ARequiredI18n.js +4 -0
  216. package/src/ui/ARequired/i18n/nl.json +3 -0
  217. package/src/ui/ARequired/i18n/pl.json +3 -0
  218. package/src/ui/ARouterLinkConfig/i18n/ARouterLinkConfigI18n.js +4 -0
  219. package/src/ui/ARouterLinkConfig/i18n/nl.json +14 -0
  220. package/src/ui/ARouterLinkConfig/i18n/pl.json +14 -0
  221. package/src/ui/ASelect/i18n/ASelectI18n.js +4 -0
  222. package/src/ui/ASelect/i18n/ar.json +5 -5
  223. package/src/ui/ASelect/i18n/de.json +4 -4
  224. package/src/ui/ASelect/i18n/en.json +5 -5
  225. package/src/ui/ASelect/i18n/es.json +5 -5
  226. package/src/ui/ASelect/i18n/fr.json +5 -5
  227. package/src/ui/ASelect/i18n/hr.json +5 -5
  228. package/src/ui/ASelect/i18n/it.json +5 -5
  229. package/src/ui/ASelect/i18n/nl.json +11 -0
  230. package/src/ui/ASelect/i18n/pl.json +11 -0
  231. package/src/ui/ASelect/i18n/ru.json +5 -5
  232. package/src/ui/ASelectStyle/i18n/ASelectStyleI18n.js +4 -0
  233. package/src/ui/ASelectStyle/i18n/nl.json +292 -0
  234. package/src/ui/ASelectStyle/i18n/pl.json +292 -0
  235. package/src/ui/ASlider/i18n/ASliderI18n.js +4 -0
  236. package/src/ui/ASlider/i18n/nl.json +5 -0
  237. package/src/ui/ASlider/i18n/pl.json +5 -0
  238. package/src/ui/ASwitch/i18n/ASwitchI18n.js +4 -0
  239. package/src/ui/ASwitch/i18n/nl.json +5 -0
  240. package/src/ui/ASwitch/i18n/pl.json +5 -0
  241. package/src/ui/AUiComponents.js +2 -0
  242. package/src/ui/AValidatedJson/i18n/AValidatedJsonI18n.js +4 -0
  243. package/src/ui/AValidatedJson/i18n/nl.json +25 -0
  244. package/src/ui/AValidatedJson/i18n/pl.json +25 -0
  245. package/src/ui/compositionApi/__tests__/UiStyleHideAPI.test.js +9 -4
@@ -1,670 +1,670 @@
1
- import PuxDatepickerCalendarPanel from "./PuxDatepickerCalendarPanel/PuxDatepickerCalendarPanel.vue";
2
- import PuxDatepickerIcon from "./PuxDatepickerIcon/PuxDatepickerIcon.vue";
3
- import {
4
- AButton,
5
- } from "aloha-vue";
6
-
7
- import Languages from "./locale/languages";
8
- import keysCode from "./utils/keysCode";
9
- import moment from "moment";
10
- import {
11
- formatDate,
12
- isDateObject,
13
- isPlainObject,
14
- isValidDate,
15
- isValidRangeDate,
16
- parseDate,
17
- throttle,
18
- } from "./utils";
19
- import {
20
- gettext,
21
- } from "../../functions/utils";
22
- import {
23
- transformDate,
24
- } from "./utils/transform";
25
-
26
-
27
- // @vue/component
28
- export default {
29
- name: "DatePicker",
30
- components: {
31
- AButton,
32
- PuxDatepickerCalendarPanel,
33
- PuxDatepickerIcon,
34
- },
35
- props: {
36
- id: {
37
- type: String,
38
- required: true,
39
- },
40
- value: {
41
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
42
- default: undefined,
43
- },
44
- valueType: {
45
- default: "date",
46
- validator: function(value) {
47
- return ["timestamp", "format", "date"].indexOf(value) !== -1 || isPlainObject(value);
48
- },
49
- },
50
- placeholder: {
51
- type: String,
52
- default: null,
53
- },
54
- lang: {
55
- type: String,
56
- default: "de",
57
- required: false,
58
- },
59
- languages: {
60
- type: Object,
61
- default: undefined,
62
- required: false,
63
- },
64
- format: {
65
- type: [String, Object],
66
- default: "YYYY-MM-DD",
67
- },
68
- dateFormat: {
69
- type: String, // format the time header and date tooltip
70
- default: undefined,
71
- },
72
- type: {
73
- type: String,
74
- default: "date", // ["date", "datetime"] zendy added "month", "year", mxie added "time"
75
- },
76
- range: {
77
- type: Boolean,
78
- default: false,
79
- },
80
- rangeSeparator: {
81
- type: String,
82
- default: "~",
83
- },
84
- width: {
85
- type: [String, Number],
86
- default: null,
87
- },
88
- confirmText: {
89
- type: String,
90
- default: "OK",
91
- },
92
- confirm: {
93
- type: Boolean,
94
- default: false,
95
- },
96
- editable: {
97
- type: Boolean,
98
- default: true,
99
- },
100
- disabled: {
101
- type: Boolean,
102
- default: false,
103
- },
104
- clearable: {
105
- type: Boolean,
106
- default: true,
107
- },
108
- shortcuts: {
109
- type: [Boolean, Array],
110
- default: true,
111
- },
112
- inputName: {
113
- type: String,
114
- default: "date",
115
- },
116
- inputClass: {
117
- type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
118
- default: "pux_datepicker__input",
119
- },
120
- inputAttr: {
121
- type: Object,
122
- default: undefined,
123
- },
124
- appendToBody: {
125
- type: Boolean,
126
- default: false,
127
- },
128
- popupStyle: {
129
- type: Object,
130
- default: undefined,
131
- },
132
- iconDay: {
133
- type: [Number, String],
134
- default: undefined,
135
- },
136
- },
137
- emits: [
138
- "blur",
139
- "change",
140
- "clear",
141
- "confirm",
142
- "focus",
143
- "input",
144
- "inputError",
145
- "changeCalendarMonth",
146
- "changeCalendarYear",
147
- ],
148
- data() {
149
- return {
150
- currentValue: this.range ? [null, null] : null,
151
- userInput: null,
152
- popupVisible: false,
153
- position: {},
154
- };
155
- },
156
- computed: {
157
- transform() {
158
- const type = this.valueType;
159
- if (isPlainObject(type)) {
160
- return { ...transformDate.date, ...type };
161
- }
162
- if (type === "format") {
163
- return {
164
- value2date: this.parse.bind(this),
165
- date2value: this.stringify.bind(this),
166
- };
167
- }
168
- return transformDate[type] || transformDate.date;
169
- },
170
-
171
- languagesLocal() {
172
- if (isPlainObject(this.languages)) {
173
- return {
174
- ...Languages,
175
- ...this.languages,
176
- };
177
- }
178
- return Languages;
179
- },
180
-
181
- currentLanguage() {
182
- return this.languagesLocal[this.lang];
183
- },
184
-
185
- innerPlaceholder() {
186
- if (typeof this.placeholder === "string") {
187
- return gettext(this.placeholder);
188
- }
189
- if (this.range) {
190
- return this.currentLanguage.placeholder.dateRange;
191
- }
192
- if (this.type === "time") {
193
- return this.currentLanguage.placeholder.time;
194
- }
195
- return this.currentLanguage.placeholder.date;
196
- },
197
-
198
- text() {
199
- if (this.userInput !== null) {
200
- return this.userInput;
201
- }
202
- const {
203
- value2date,
204
- } = this.transform;
205
- if (!this.range) {
206
- return this.isValidValue(this.value)
207
- ? this.stringify(value2date(this.value))
208
- : "";
209
- }
210
- return this.isValidRangeValue(this.value)
211
- ? `${ this.stringify(value2date(this.value[0])) } ${ this.rangeSeparator } ${ this.stringify(value2date(this.value[1])) }`
212
- : "";
213
- },
214
-
215
- computedWidth() {
216
- if (typeof this.width === "number" || (typeof this.width === "string" && /^\d+$/.test(this.width))) {
217
- return this.width + "px";
218
- }
219
- return this.width;
220
- },
221
-
222
- showClearIcon() {
223
- return !this.disabled && this.clearable && (this.range ? this.isValidRangeValue(this.value) : this.isValidValue(this.value));
224
- },
225
-
226
- innerType() {
227
- return String(this.type).toLowerCase();
228
- },
229
-
230
- innerShortcuts() {
231
- if (Array.isArray(this.shortcuts)) {
232
- return this.shortcuts;
233
- }
234
- if (this.shortcuts === false) {
235
- return [];
236
- }
237
- const pickers = this.currentLanguage.pickers;
238
- const arr = [
239
- {
240
- text: pickers[0],
241
- onClick(self) {
242
- self.currentValue = [new Date(), new Date(Date.now() + 3600 * 1000 * 24 * 7)];
243
- self.updateDate(true);
244
- },
245
- },
246
- {
247
- text: pickers[1],
248
- onClick(self) {
249
- self.currentValue = [new Date(), new Date(Date.now() + 3600 * 1000 * 24 * 30)];
250
- self.updateDate(true);
251
- },
252
- },
253
- {
254
- text: pickers[2],
255
- onClick(self) {
256
- self.currentValue = [new Date(Date.now() - 3600 * 1000 * 24 * 7), new Date()];
257
- self.updateDate(true);
258
- },
259
- },
260
- {
261
- text: pickers[3],
262
- onClick(self) {
263
- self.currentValue = [new Date(Date.now() - 3600 * 1000 * 24 * 30), new Date()];
264
- self.updateDate(true);
265
- },
266
- },
267
- ];
268
- return arr;
269
- },
270
-
271
- innerDateFormat() {
272
- if (this.dateFormat) {
273
- return this.dateFormat;
274
- }
275
- if (typeof this.format !== "string") {
276
- return "YYYY-MM-DD";
277
- }
278
- if (this.innerType === "date") {
279
- return this.format;
280
- }
281
- return this.format.replace(/[Hh]+.*[msSaAZ]|\[.*?\]/g, "").trim() || "YYYY-MM-DD";
282
- },
283
-
284
- innerPopupStyle() {
285
- return { ...this.position, ...this.popupStyle };
286
- },
287
-
288
- idForPanel() {
289
- return `${ this.id }_panel`;
290
- },
291
-
292
- idsForPanelRange() {
293
- return [
294
- `${ this.idForPanel }_0`,
295
- `${ this.idForPanel }_1`,
296
- ];
297
- },
298
-
299
- ariaHiddenForCalendar() {
300
- return `${ !this.popupVisible }`;
301
- },
302
-
303
- ariaExpandedForCalendar() {
304
- return `${ this.popupVisible }`;
305
- },
306
-
307
- idForCalendar() {
308
- return `${ this.id }_calendar`;
309
- },
310
-
311
- modalBody() {
312
- return document.querySelector("div.modal_body"); // Workaround till updated by ADatePicker
313
- },
314
- },
315
- watch: {
316
- value: {
317
- immediate: true,
318
- handler: "handleValueChange",
319
- },
320
-
321
- popupVisible(val) {
322
- if (val) {
323
- this.initCalendar();
324
- } else {
325
- this.userInput = null;
326
- this.blur();
327
- }
328
- },
329
- },
330
- mounted() {
331
- if (this.appendToBody) {
332
- this.popupElm = this.$refs.calendar;
333
- document.body.appendChild(this.popupElm);
334
- }
335
- // clickoutside close popup
336
- let mousedownTarget;
337
- this._bindDocmentMousedown = evt => {
338
- mousedownTarget = evt.target;
339
- };
340
- this._bindDocumentMouseup = evt => {
341
- const mouseupTarget = evt.target;
342
- const el = this.$el;
343
- const { popupElm } = this;
344
- if (
345
- !mousedownTarget ||
346
- !mouseupTarget ||
347
- el.contains(mousedownTarget) ||
348
- el.contains(mouseupTarget) ||
349
- (popupElm && (popupElm.contains(mousedownTarget) || popupElm.contains(mouseupTarget)))
350
- ) {
351
- return;
352
- }
353
- mousedownTarget = null;
354
- this.closePopup();
355
- };
356
- this._startEvt = "mousedown";
357
- this._endEvt = "mouseup";
358
- if ("ontouchend" in document) {
359
- this._startEvt = "touchstart";
360
- this._endEvt = "touchend";
361
- }
362
- document.addEventListener(this._startEvt, this._bindDocmentMousedown);
363
- document.addEventListener(this._endEvt, this._bindDocumentMouseup);
364
-
365
- this._displayPopup = throttle(() => {
366
- if (this.popupVisible) {
367
- this.displayPopup();
368
- }
369
- }, 200);
370
- window.addEventListener("resize", this._displayPopup);
371
- window.addEventListener("scroll", this._displayPopup);
372
-
373
- // Workaround till updated by ADatePicker
374
- if (this.modalBody) {
375
- this.modalBody.addEventListener("scroll", this._displayPopup);
376
- }
377
- },
378
- beforeUnmount() {
379
- if (this.popupElm && this.popupElm.parentNode === document.body) {
380
- document.body.removeChild(this.popupElm);
381
- }
382
- document.removeEventListener(this._startEvt, this._bindDocmentMousedown);
383
- document.removeEventListener(this._endEvt, this._bindDocumentMouseup);
384
- window.removeEventListener("resize", this._displayPopup);
385
- window.removeEventListener("scroll", this._displayPopup);
386
-
387
- // Workaround till updated by ADatePicker
388
- if (this.modalBody) {
389
- this.modalBody.removeEventListener("scroll", this._displayPopup);
390
- }
391
- },
392
- methods: {
393
- initCalendar() {
394
- this.handleValueChange(this.value);
395
- this.displayPopup();
396
- },
397
-
398
- stringify(date) {
399
- return (isPlainObject(this.format) && typeof this.format.stringify === "function")
400
- ? this.format.stringify(date)
401
- : formatDate(date, this.format);
402
- },
403
-
404
- parse(value) {
405
- return (isPlainObject(this.format) && typeof this.format.parse === "function")
406
- ? this.format.parse(value)
407
- : parseDate(value, this.format);
408
- },
409
-
410
- isValidValue(value) {
411
- const { value2date } = this.transform;
412
- return isValidDate(value2date(value));
413
- },
414
-
415
- isValidRangeValue(value) {
416
- const { value2date } = this.transform;
417
- return Array.isArray(value) && value.length === 2 && this.isValidValue(value[0]) &&
418
- this.isValidValue(value[1]) && (value2date(value[1]).getTime() >= value2date(value[0]).getTime());
419
- },
420
-
421
- dateEqual(a, b) {
422
- return isDateObject(a) && isDateObject(b) && a.getTime() === b.getTime();
423
- },
424
-
425
- rangeEqual(a, b) {
426
- return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => this.dateEqual(item, b[index]));
427
- },
428
-
429
- selectRange(range) {
430
- if (typeof range.onClick === "function") {
431
- const close = range.onClick(this);
432
- if (close !== false) {
433
- this.closePopup();
434
- }
435
- } else {
436
- this.currentValue = [new Date(range.start), new Date(range.end)];
437
- this.updateDate(true);
438
- this.closePopup();
439
- }
440
- },
441
-
442
- clearDate() {
443
- const date = this.range ? [null, null] : null;
444
- this.currentValue = date;
445
- this.updateDate(true);
446
- this.$emit("clear");
447
- },
448
-
449
- confirmDate() {
450
- const valid = this.range ? isValidRangeDate(this.currentValue) : isValidDate(this.currentValue);
451
- if (valid) {
452
- this.updateDate(true);
453
- }
454
- this.emitDate("confirm");
455
- this.closePopup();
456
- },
457
-
458
- updateDate(confirm = false) {
459
- if ((this.confirm && !confirm) || this.disabled) {
460
- return false;
461
- }
462
- const equal = this.range ? this.rangeEqual(this.value, this.currentValue) : this.dateEqual(this.value, this.currentValue);
463
- if (equal) {
464
- return false;
465
- }
466
- this.emitDate("input");
467
- this.emitDate("change");
468
- return true;
469
- },
470
-
471
- emitDate(eventName) {
472
- const { date2value } = this.transform;
473
- const value = this.range
474
- ? this.currentValue.map(date2value)
475
- : date2value(this.currentValue);
476
- this.$emit(eventName, value);
477
- },
478
-
479
- handleValueChange(value) {
480
- const { value2date } = this.transform;
481
- if (this.range) {
482
- this.currentValue = this.isValidRangeValue(value) ? value.map(value2date) : [null, null];
483
- } else {
484
- this.currentValue = this.isValidValue(value) ? value2date(value) : null;
485
- }
486
- },
487
-
488
- selectDate(date) {
489
- this.currentValue = date;
490
- this.updateDate() && this.closePopup();
491
- this.setCloseFocus();
492
- },
493
-
494
- selectStartDate(date) {
495
- this.currentValue[0] = date;
496
- if (this.currentValue[1]) {
497
- this.updateDate();
498
- }
499
- },
500
-
501
- selectEndDate(date) {
502
- this.currentValue[1] = date;
503
- if (this.currentValue[0]) {
504
- this.updateDate();
505
- }
506
- },
507
-
508
- selectTime(time, close) {
509
- this.currentValue = time;
510
- this.updateDate() && close && this.closePopup();
511
- if (close) {
512
- this.setCloseFocus();
513
- }
514
- },
515
-
516
- selectStartTime(time) {
517
- this.selectStartDate(time);
518
- },
519
-
520
- selectEndTime(time) {
521
- this.selectEndDate(time);
522
- },
523
-
524
- showPopup() {
525
- if (this.disabled) {
526
- return;
527
- }
528
- this.popupVisible = true;
529
- },
530
-
531
- closePopup(isSetFocusByClose) {
532
- this.popupVisible = false;
533
- if (isSetFocusByClose) {
534
- this.setCloseFocus();
535
- }
536
- },
537
-
538
- getPopupSize(element) {
539
- const originalDisplay = element.style.display;
540
- const originalVisibility = element.style.visibility;
541
- element.style.display = "block";
542
- element.style.visibility = "hidden";
543
- const styles = window.getComputedStyle(element);
544
- const width = element.offsetWidth + parseInt(styles.marginLeft) + parseInt(styles.marginRight);
545
- const height = element.offsetHeight + parseInt(styles.marginTop) + parseInt(styles.marginBottom);
546
- const result = { width, height };
547
- element.style.display = originalDisplay;
548
- element.style.visibility = originalVisibility;
549
- return result;
550
- },
551
-
552
- displayPopup() {
553
- if (!this.$el?.getBoundingClientRect) {
554
- return;
555
- }
556
-
557
- const dw = document.documentElement.clientWidth;
558
- const dh = document.documentElement.clientHeight;
559
- const InputRect = this.$el.getBoundingClientRect();
560
- const PopupRect = this._popupRect || (this._popupRect = this.getPopupSize(this.$refs.calendar));
561
- const position = {};
562
- let offsetRelativeToInputX = 0;
563
- let offsetRelativeToInputY = 0;
564
- if (this.appendToBody) {
565
- offsetRelativeToInputX = window.scrollX + InputRect.left;
566
- offsetRelativeToInputY = window.scrollY + InputRect.top;
567
- }
568
- if (
569
- dw - InputRect.left < PopupRect.width &&
570
- InputRect.right < PopupRect.width
571
- ) {
572
- position.left = offsetRelativeToInputX - InputRect.left + 1 + "px";
573
- } else if (InputRect.left + InputRect.width / 2 <= dw / 2) {
574
- position.left = offsetRelativeToInputX + "px";
575
- } else {
576
- position.left = offsetRelativeToInputX + InputRect.width - PopupRect.width + "px";
577
- }
578
- if (
579
- InputRect.top <= PopupRect.height &&
580
- dh - InputRect.bottom <= PopupRect.height
581
- ) {
582
- position.top = offsetRelativeToInputY + dh - InputRect.top - PopupRect.height + "px";
583
- } else if (InputRect.top + InputRect.height / 2 <= dh / 2) {
584
- position.top = offsetRelativeToInputY + InputRect.height + "px";
585
- } else {
586
- position.top = offsetRelativeToInputY - PopupRect.height + "px";
587
- }
588
- if (position.top !== this.position.top || position.left !== this.position.left) {
589
- this.position = position;
590
- }
591
- },
592
-
593
- blur() {
594
- this.$refs.input.blur();
595
- },
596
-
597
- handleBlur(event) {
598
- this.$emit("blur", event);
599
- },
600
-
601
- handleFocus(event) {
602
- if (!this.popupVisible) {
603
- this.showPopup();
604
- }
605
- this.$emit("focus", event);
606
- },
607
-
608
- handleKeydown($event) {
609
- const KEY_CODE = $event.keyCode;
610
- if (KEY_CODE === keysCode.tab || KEY_CODE === keysCode.enter) {
611
- // ie emit the watch before the change event
612
- this.handleChange();
613
- this.userInput = null;
614
- this.closePopup();
615
- } else if (KEY_CODE === keysCode.arrowUp || KEY_CODE === keysCode.arrowDown) {
616
- this.setFocusToPanel();
617
- $event.stopPropagation();
618
- $event.preventDefault();
619
- }
620
- },
621
-
622
- handleInput(event) {
623
- this.userInput = event.target.value;
624
- },
625
-
626
- handleChange() {
627
- if (this.editable && this.userInput !== null) {
628
- let value = this.text;
629
- const checkDate = this.$refs.calendarPanel.isDisabledTime;
630
- if (!value) {
631
- this.clearDate();
632
- return;
633
- }
634
- if (this.range) {
635
- const range = value.split(` ${ this.rangeSeparator } `);
636
- if (range.length === 2) {
637
- const start = this.parse(range[0]);
638
- const end = this.parse(range[1]);
639
- if (start && end && !checkDate(start, null, end) && !checkDate(end, start, null)) {
640
- this.currentValue = [start, end];
641
- this.updateDate(true);
642
- this.closePopup();
643
- return;
644
- }
645
- }
646
- } else {
647
- if (this.type === "time") {
648
- value = `${ moment().format("DD.MM.YYYY") } ${ value }`;
649
- }
650
- const date = this.parse(value);
651
- if (date && !checkDate(date, null, null)) {
652
- this.currentValue = date;
653
- this.updateDate(true);
654
- this.closePopup();
655
- return;
656
- }
657
- }
658
- this.$emit("inputError", value);
659
- }
660
- },
661
-
662
- setFocusToPanel() {
663
- this.$refs.calendarPanel.setFocusToActivePanelFromParent();
664
- },
665
-
666
- setCloseFocus() {
667
- this.$refs.focusByClose.focus();
668
- },
669
- },
670
- };
1
+ import PuxDatepickerCalendarPanel from "./PuxDatepickerCalendarPanel/PuxDatepickerCalendarPanel.vue";
2
+ import PuxDatepickerIcon from "./PuxDatepickerIcon/PuxDatepickerIcon.vue";
3
+ import {
4
+ AButton,
5
+ } from "aloha-vue";
6
+
7
+ import Languages from "./locale/languages";
8
+ import keysCode from "./utils/keysCode";
9
+ import moment from "moment";
10
+ import {
11
+ formatDate,
12
+ isDateObject,
13
+ isPlainObject,
14
+ isValidDate,
15
+ isValidRangeDate,
16
+ parseDate,
17
+ throttle,
18
+ } from "./utils";
19
+ import {
20
+ gettext,
21
+ } from "../../functions/utils";
22
+ import {
23
+ transformDate,
24
+ } from "./utils/transform";
25
+
26
+
27
+ // @vue/component
28
+ export default {
29
+ name: "DatePicker",
30
+ components: {
31
+ AButton,
32
+ PuxDatepickerCalendarPanel,
33
+ PuxDatepickerIcon,
34
+ },
35
+ props: {
36
+ id: {
37
+ type: String,
38
+ required: true,
39
+ },
40
+ value: {
41
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
42
+ default: undefined,
43
+ },
44
+ valueType: {
45
+ default: "date",
46
+ validator: function(value) {
47
+ return ["timestamp", "format", "date"].indexOf(value) !== -1 || isPlainObject(value);
48
+ },
49
+ },
50
+ placeholder: {
51
+ type: String,
52
+ default: null,
53
+ },
54
+ lang: {
55
+ type: String,
56
+ default: "de",
57
+ required: false,
58
+ },
59
+ languages: {
60
+ type: Object,
61
+ default: undefined,
62
+ required: false,
63
+ },
64
+ format: {
65
+ type: [String, Object],
66
+ default: "YYYY-MM-DD",
67
+ },
68
+ dateFormat: {
69
+ type: String, // format the time header and date tooltip
70
+ default: undefined,
71
+ },
72
+ type: {
73
+ type: String,
74
+ default: "date", // ["date", "datetime"] zendy added "month", "year", mxie added "time"
75
+ },
76
+ range: {
77
+ type: Boolean,
78
+ default: false,
79
+ },
80
+ rangeSeparator: {
81
+ type: String,
82
+ default: "~",
83
+ },
84
+ width: {
85
+ type: [String, Number],
86
+ default: null,
87
+ },
88
+ confirmText: {
89
+ type: String,
90
+ default: "OK",
91
+ },
92
+ confirm: {
93
+ type: Boolean,
94
+ default: false,
95
+ },
96
+ editable: {
97
+ type: Boolean,
98
+ default: true,
99
+ },
100
+ disabled: {
101
+ type: Boolean,
102
+ default: false,
103
+ },
104
+ clearable: {
105
+ type: Boolean,
106
+ default: true,
107
+ },
108
+ shortcuts: {
109
+ type: [Boolean, Array],
110
+ default: true,
111
+ },
112
+ inputName: {
113
+ type: String,
114
+ default: "date",
115
+ },
116
+ inputClass: {
117
+ type: [String, Number, Boolean, Array, Object, Date, Function, Symbol],
118
+ default: "pux_datepicker__input",
119
+ },
120
+ inputAttr: {
121
+ type: Object,
122
+ default: undefined,
123
+ },
124
+ appendToBody: {
125
+ type: Boolean,
126
+ default: false,
127
+ },
128
+ popupStyle: {
129
+ type: Object,
130
+ default: undefined,
131
+ },
132
+ iconDay: {
133
+ type: [Number, String],
134
+ default: undefined,
135
+ },
136
+ },
137
+ emits: [
138
+ "blur",
139
+ "change",
140
+ "clear",
141
+ "confirm",
142
+ "focus",
143
+ "input",
144
+ "inputError",
145
+ "changeCalendarMonth",
146
+ "changeCalendarYear",
147
+ ],
148
+ data() {
149
+ return {
150
+ currentValue: this.range ? [null, null] : null,
151
+ userInput: null,
152
+ popupVisible: false,
153
+ position: {},
154
+ };
155
+ },
156
+ computed: {
157
+ transform() {
158
+ const type = this.valueType;
159
+ if (isPlainObject(type)) {
160
+ return { ...transformDate.date, ...type };
161
+ }
162
+ if (type === "format") {
163
+ return {
164
+ value2date: this.parse.bind(this),
165
+ date2value: this.stringify.bind(this),
166
+ };
167
+ }
168
+ return transformDate[type] || transformDate.date;
169
+ },
170
+
171
+ languagesLocal() {
172
+ if (isPlainObject(this.languages)) {
173
+ return {
174
+ ...Languages,
175
+ ...this.languages,
176
+ };
177
+ }
178
+ return Languages;
179
+ },
180
+
181
+ currentLanguage() {
182
+ return this.languagesLocal[this.lang];
183
+ },
184
+
185
+ innerPlaceholder() {
186
+ if (typeof this.placeholder === "string") {
187
+ return gettext(this.placeholder);
188
+ }
189
+ if (this.range) {
190
+ return this.currentLanguage.placeholder.dateRange;
191
+ }
192
+ if (this.type === "time") {
193
+ return this.currentLanguage.placeholder.time;
194
+ }
195
+ return this.currentLanguage.placeholder.date;
196
+ },
197
+
198
+ text() {
199
+ if (this.userInput !== null) {
200
+ return this.userInput;
201
+ }
202
+ const {
203
+ value2date,
204
+ } = this.transform;
205
+ if (!this.range) {
206
+ return this.isValidValue(this.value)
207
+ ? this.stringify(value2date(this.value))
208
+ : "";
209
+ }
210
+ return this.isValidRangeValue(this.value)
211
+ ? `${ this.stringify(value2date(this.value[0])) } ${ this.rangeSeparator } ${ this.stringify(value2date(this.value[1])) }`
212
+ : "";
213
+ },
214
+
215
+ computedWidth() {
216
+ if (typeof this.width === "number" || (typeof this.width === "string" && /^\d+$/.test(this.width))) {
217
+ return this.width + "px";
218
+ }
219
+ return this.width;
220
+ },
221
+
222
+ showClearIcon() {
223
+ return !this.disabled && this.clearable && (this.range ? this.isValidRangeValue(this.value) : this.isValidValue(this.value));
224
+ },
225
+
226
+ innerType() {
227
+ return String(this.type).toLowerCase();
228
+ },
229
+
230
+ innerShortcuts() {
231
+ if (Array.isArray(this.shortcuts)) {
232
+ return this.shortcuts;
233
+ }
234
+ if (this.shortcuts === false) {
235
+ return [];
236
+ }
237
+ const pickers = this.currentLanguage.pickers;
238
+ const arr = [
239
+ {
240
+ text: pickers[0],
241
+ onClick(self) {
242
+ self.currentValue = [new Date(), new Date(Date.now() + 3600 * 1000 * 24 * 7)];
243
+ self.updateDate(true);
244
+ },
245
+ },
246
+ {
247
+ text: pickers[1],
248
+ onClick(self) {
249
+ self.currentValue = [new Date(), new Date(Date.now() + 3600 * 1000 * 24 * 30)];
250
+ self.updateDate(true);
251
+ },
252
+ },
253
+ {
254
+ text: pickers[2],
255
+ onClick(self) {
256
+ self.currentValue = [new Date(Date.now() - 3600 * 1000 * 24 * 7), new Date()];
257
+ self.updateDate(true);
258
+ },
259
+ },
260
+ {
261
+ text: pickers[3],
262
+ onClick(self) {
263
+ self.currentValue = [new Date(Date.now() - 3600 * 1000 * 24 * 30), new Date()];
264
+ self.updateDate(true);
265
+ },
266
+ },
267
+ ];
268
+ return arr;
269
+ },
270
+
271
+ innerDateFormat() {
272
+ if (this.dateFormat) {
273
+ return this.dateFormat;
274
+ }
275
+ if (typeof this.format !== "string") {
276
+ return "YYYY-MM-DD";
277
+ }
278
+ if (this.innerType === "date") {
279
+ return this.format;
280
+ }
281
+ return this.format.replace(/[Hh]+.*[msSaAZ]|\[.*?\]/g, "").trim() || "YYYY-MM-DD";
282
+ },
283
+
284
+ innerPopupStyle() {
285
+ return { ...this.position, ...this.popupStyle };
286
+ },
287
+
288
+ idForPanel() {
289
+ return `${ this.id }_panel`;
290
+ },
291
+
292
+ idsForPanelRange() {
293
+ return [
294
+ `${ this.idForPanel }_0`,
295
+ `${ this.idForPanel }_1`,
296
+ ];
297
+ },
298
+
299
+ ariaHiddenForCalendar() {
300
+ return `${ !this.popupVisible }`;
301
+ },
302
+
303
+ ariaExpandedForCalendar() {
304
+ return `${ this.popupVisible }`;
305
+ },
306
+
307
+ idForCalendar() {
308
+ return `${ this.id }_calendar`;
309
+ },
310
+
311
+ modalBody() {
312
+ return document.querySelector("div.modal_body"); // Workaround till updated by ADatePicker
313
+ },
314
+ },
315
+ watch: {
316
+ value: {
317
+ immediate: true,
318
+ handler: "handleValueChange",
319
+ },
320
+
321
+ popupVisible(val) {
322
+ if (val) {
323
+ this.initCalendar();
324
+ } else {
325
+ this.userInput = null;
326
+ this.blur();
327
+ }
328
+ },
329
+ },
330
+ mounted() {
331
+ if (this.appendToBody) {
332
+ this.popupElm = this.$refs.calendar;
333
+ document.body.appendChild(this.popupElm);
334
+ }
335
+ // clickoutside close popup
336
+ let mousedownTarget;
337
+ this._bindDocmentMousedown = evt => {
338
+ mousedownTarget = evt.target;
339
+ };
340
+ this._bindDocumentMouseup = evt => {
341
+ const mouseupTarget = evt.target;
342
+ const el = this.$el;
343
+ const { popupElm } = this;
344
+ if (
345
+ !mousedownTarget ||
346
+ !mouseupTarget ||
347
+ el.contains(mousedownTarget) ||
348
+ el.contains(mouseupTarget) ||
349
+ (popupElm && (popupElm.contains(mousedownTarget) || popupElm.contains(mouseupTarget)))
350
+ ) {
351
+ return;
352
+ }
353
+ mousedownTarget = null;
354
+ this.closePopup();
355
+ };
356
+ this._startEvt = "mousedown";
357
+ this._endEvt = "mouseup";
358
+ if ("ontouchend" in document) {
359
+ this._startEvt = "touchstart";
360
+ this._endEvt = "touchend";
361
+ }
362
+ document.addEventListener(this._startEvt, this._bindDocmentMousedown);
363
+ document.addEventListener(this._endEvt, this._bindDocumentMouseup);
364
+
365
+ this._displayPopup = throttle(() => {
366
+ if (this.popupVisible) {
367
+ this.displayPopup();
368
+ }
369
+ }, 200);
370
+ window.addEventListener("resize", this._displayPopup);
371
+ window.addEventListener("scroll", this._displayPopup);
372
+
373
+ // Workaround till updated by ADatePicker
374
+ if (this.modalBody) {
375
+ this.modalBody.addEventListener("scroll", this._displayPopup);
376
+ }
377
+ },
378
+ beforeUnmount() {
379
+ if (this.popupElm && this.popupElm.parentNode === document.body) {
380
+ document.body.removeChild(this.popupElm);
381
+ }
382
+ document.removeEventListener(this._startEvt, this._bindDocmentMousedown);
383
+ document.removeEventListener(this._endEvt, this._bindDocumentMouseup);
384
+ window.removeEventListener("resize", this._displayPopup);
385
+ window.removeEventListener("scroll", this._displayPopup);
386
+
387
+ // Workaround till updated by ADatePicker
388
+ if (this.modalBody) {
389
+ this.modalBody.removeEventListener("scroll", this._displayPopup);
390
+ }
391
+ },
392
+ methods: {
393
+ initCalendar() {
394
+ this.handleValueChange(this.value);
395
+ this.displayPopup();
396
+ },
397
+
398
+ stringify(date) {
399
+ return (isPlainObject(this.format) && typeof this.format.stringify === "function")
400
+ ? this.format.stringify(date)
401
+ : formatDate(date, this.format);
402
+ },
403
+
404
+ parse(value) {
405
+ return (isPlainObject(this.format) && typeof this.format.parse === "function")
406
+ ? this.format.parse(value)
407
+ : parseDate(value, this.format);
408
+ },
409
+
410
+ isValidValue(value) {
411
+ const { value2date } = this.transform;
412
+ return isValidDate(value2date(value));
413
+ },
414
+
415
+ isValidRangeValue(value) {
416
+ const { value2date } = this.transform;
417
+ return Array.isArray(value) && value.length === 2 && this.isValidValue(value[0]) &&
418
+ this.isValidValue(value[1]) && (value2date(value[1]).getTime() >= value2date(value[0]).getTime());
419
+ },
420
+
421
+ dateEqual(a, b) {
422
+ return isDateObject(a) && isDateObject(b) && a.getTime() === b.getTime();
423
+ },
424
+
425
+ rangeEqual(a, b) {
426
+ return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => this.dateEqual(item, b[index]));
427
+ },
428
+
429
+ selectRange(range) {
430
+ if (typeof range.onClick === "function") {
431
+ const close = range.onClick(this);
432
+ if (close !== false) {
433
+ this.closePopup();
434
+ }
435
+ } else {
436
+ this.currentValue = [new Date(range.start), new Date(range.end)];
437
+ this.updateDate(true);
438
+ this.closePopup();
439
+ }
440
+ },
441
+
442
+ clearDate() {
443
+ const date = this.range ? [null, null] : null;
444
+ this.currentValue = date;
445
+ this.updateDate(true);
446
+ this.$emit("clear");
447
+ },
448
+
449
+ confirmDate() {
450
+ const valid = this.range ? isValidRangeDate(this.currentValue) : isValidDate(this.currentValue);
451
+ if (valid) {
452
+ this.updateDate(true);
453
+ }
454
+ this.emitDate("confirm");
455
+ this.closePopup();
456
+ },
457
+
458
+ updateDate(confirm = false) {
459
+ if ((this.confirm && !confirm) || this.disabled) {
460
+ return false;
461
+ }
462
+ const equal = this.range ? this.rangeEqual(this.value, this.currentValue) : this.dateEqual(this.value, this.currentValue);
463
+ if (equal) {
464
+ return false;
465
+ }
466
+ this.emitDate("input");
467
+ this.emitDate("change");
468
+ return true;
469
+ },
470
+
471
+ emitDate(eventName) {
472
+ const { date2value } = this.transform;
473
+ const value = this.range
474
+ ? this.currentValue.map(date2value)
475
+ : date2value(this.currentValue);
476
+ this.$emit(eventName, value);
477
+ },
478
+
479
+ handleValueChange(value) {
480
+ const { value2date } = this.transform;
481
+ if (this.range) {
482
+ this.currentValue = this.isValidRangeValue(value) ? value.map(value2date) : [null, null];
483
+ } else {
484
+ this.currentValue = this.isValidValue(value) ? value2date(value) : null;
485
+ }
486
+ },
487
+
488
+ selectDate(date) {
489
+ this.currentValue = date;
490
+ this.updateDate() && this.closePopup();
491
+ this.setCloseFocus();
492
+ },
493
+
494
+ selectStartDate(date) {
495
+ this.currentValue[0] = date;
496
+ if (this.currentValue[1]) {
497
+ this.updateDate();
498
+ }
499
+ },
500
+
501
+ selectEndDate(date) {
502
+ this.currentValue[1] = date;
503
+ if (this.currentValue[0]) {
504
+ this.updateDate();
505
+ }
506
+ },
507
+
508
+ selectTime(time, close) {
509
+ this.currentValue = time;
510
+ this.updateDate() && close && this.closePopup();
511
+ if (close) {
512
+ this.setCloseFocus();
513
+ }
514
+ },
515
+
516
+ selectStartTime(time) {
517
+ this.selectStartDate(time);
518
+ },
519
+
520
+ selectEndTime(time) {
521
+ this.selectEndDate(time);
522
+ },
523
+
524
+ showPopup() {
525
+ if (this.disabled) {
526
+ return;
527
+ }
528
+ this.popupVisible = true;
529
+ },
530
+
531
+ closePopup(isSetFocusByClose) {
532
+ this.popupVisible = false;
533
+ if (isSetFocusByClose) {
534
+ this.setCloseFocus();
535
+ }
536
+ },
537
+
538
+ getPopupSize(element) {
539
+ const originalDisplay = element.style.display;
540
+ const originalVisibility = element.style.visibility;
541
+ element.style.display = "block";
542
+ element.style.visibility = "hidden";
543
+ const styles = window.getComputedStyle(element);
544
+ const width = element.offsetWidth + parseInt(styles.marginLeft) + parseInt(styles.marginRight);
545
+ const height = element.offsetHeight + parseInt(styles.marginTop) + parseInt(styles.marginBottom);
546
+ const result = { width, height };
547
+ element.style.display = originalDisplay;
548
+ element.style.visibility = originalVisibility;
549
+ return result;
550
+ },
551
+
552
+ displayPopup() {
553
+ if (!this.$el?.getBoundingClientRect) {
554
+ return;
555
+ }
556
+
557
+ const dw = document.documentElement.clientWidth;
558
+ const dh = document.documentElement.clientHeight;
559
+ const InputRect = this.$el.getBoundingClientRect();
560
+ const PopupRect = this._popupRect || (this._popupRect = this.getPopupSize(this.$refs.calendar));
561
+ const position = {};
562
+ let offsetRelativeToInputX = 0;
563
+ let offsetRelativeToInputY = 0;
564
+ if (this.appendToBody) {
565
+ offsetRelativeToInputX = window.scrollX + InputRect.left;
566
+ offsetRelativeToInputY = window.scrollY + InputRect.top;
567
+ }
568
+ if (
569
+ dw - InputRect.left < PopupRect.width &&
570
+ InputRect.right < PopupRect.width
571
+ ) {
572
+ position.left = offsetRelativeToInputX - InputRect.left + 1 + "px";
573
+ } else if (InputRect.left + InputRect.width / 2 <= dw / 2) {
574
+ position.left = offsetRelativeToInputX + "px";
575
+ } else {
576
+ position.left = offsetRelativeToInputX + InputRect.width - PopupRect.width + "px";
577
+ }
578
+ if (
579
+ InputRect.top <= PopupRect.height &&
580
+ dh - InputRect.bottom <= PopupRect.height
581
+ ) {
582
+ position.top = offsetRelativeToInputY + dh - InputRect.top - PopupRect.height + "px";
583
+ } else if (InputRect.top + InputRect.height / 2 <= dh / 2) {
584
+ position.top = offsetRelativeToInputY + InputRect.height + "px";
585
+ } else {
586
+ position.top = offsetRelativeToInputY - PopupRect.height + "px";
587
+ }
588
+ if (position.top !== this.position.top || position.left !== this.position.left) {
589
+ this.position = position;
590
+ }
591
+ },
592
+
593
+ blur() {
594
+ this.$refs.input.blur();
595
+ },
596
+
597
+ handleBlur(event) {
598
+ this.$emit("blur", event);
599
+ },
600
+
601
+ handleFocus(event) {
602
+ if (!this.popupVisible) {
603
+ this.showPopup();
604
+ }
605
+ this.$emit("focus", event);
606
+ },
607
+
608
+ handleKeydown($event) {
609
+ const KEY_CODE = $event.keyCode;
610
+ if (KEY_CODE === keysCode.tab || KEY_CODE === keysCode.enter) {
611
+ // ie emit the watch before the change event
612
+ this.handleChange();
613
+ this.userInput = null;
614
+ this.closePopup();
615
+ } else if (KEY_CODE === keysCode.arrowUp || KEY_CODE === keysCode.arrowDown) {
616
+ this.setFocusToPanel();
617
+ $event.stopPropagation();
618
+ $event.preventDefault();
619
+ }
620
+ },
621
+
622
+ handleInput(event) {
623
+ this.userInput = event.target.value;
624
+ },
625
+
626
+ handleChange() {
627
+ if (this.editable && this.userInput !== null) {
628
+ let value = this.text;
629
+ const checkDate = this.$refs.calendarPanel.isDisabledTime;
630
+ if (!value) {
631
+ this.clearDate();
632
+ return;
633
+ }
634
+ if (this.range) {
635
+ const range = value.split(` ${ this.rangeSeparator } `);
636
+ if (range.length === 2) {
637
+ const start = this.parse(range[0]);
638
+ const end = this.parse(range[1]);
639
+ if (start && end && !checkDate(start, null, end) && !checkDate(end, start, null)) {
640
+ this.currentValue = [start, end];
641
+ this.updateDate(true);
642
+ this.closePopup();
643
+ return;
644
+ }
645
+ }
646
+ } else {
647
+ if (this.type === "time") {
648
+ value = `${ moment().format("DD.MM.YYYY") } ${ value }`;
649
+ }
650
+ const date = this.parse(value);
651
+ if (date && !checkDate(date, null, null)) {
652
+ this.currentValue = date;
653
+ this.updateDate(true);
654
+ this.closePopup();
655
+ return;
656
+ }
657
+ }
658
+ this.$emit("inputError", value);
659
+ }
660
+ },
661
+
662
+ setFocusToPanel() {
663
+ this.$refs.calendarPanel.setFocusToActivePanelFromParent();
664
+ },
665
+
666
+ setCloseFocus() {
667
+ this.$refs.focusByClose.focus();
668
+ },
669
+ },
670
+ };