buefy 0.9.9 → 0.9.13
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.
- package/CHANGELOG.md +1639 -1609
- package/dist/buefy.css +20 -2
- package/dist/buefy.esm.js +2227 -1869
- package/dist/buefy.esm.min.js +2 -2
- package/dist/buefy.js +2266 -1907
- package/dist/buefy.min.css +1 -1
- package/dist/buefy.min.js +2 -2
- package/dist/cjs/autocomplete.js +6 -6
- package/dist/cjs/breadcrumb.js +127 -0
- package/dist/cjs/button.js +6 -107
- package/dist/cjs/carousel.js +9 -7
- package/dist/cjs/checkbox.js +5 -5
- package/dist/cjs/{chunk-d33a8a78.js → chunk-114191ae.js} +3 -3
- package/dist/cjs/{chunk-dafdb70c.js → chunk-2062216d.js} +39 -3
- package/dist/cjs/{chunk-64efc596.js → chunk-2911aa4b.js} +20 -16
- package/dist/cjs/{chunk-96ab31c1.js → chunk-2ae50815.js} +7 -7
- package/dist/cjs/{chunk-c3032504.js → chunk-2c7de785.js} +3 -3
- package/dist/cjs/{chunk-50ff3a78.js → chunk-30670fac.js} +96 -15
- package/dist/cjs/{chunk-e57b3891.js → chunk-34949503.js} +2 -2
- package/dist/cjs/{chunk-0abd2223.js → chunk-3b43d77a.js} +2 -2
- package/dist/cjs/{chunk-dcdbe2e8.js → chunk-3cc5d9a6.js} +1 -1
- package/dist/cjs/{chunk-0b57168e.js → chunk-61023b09.js} +3 -3
- package/dist/cjs/chunk-6cb902f8.js +314 -0
- package/dist/cjs/{chunk-adb01a93.js → chunk-7da0c017.js} +26 -24
- package/dist/cjs/{chunk-60255743.js → chunk-9103eeda.js} +4 -0
- package/dist/cjs/{chunk-14c82365.js → chunk-92621ff7.js} +37 -0
- package/dist/cjs/{chunk-816cba7a.js → chunk-9e4cf4c5.js} +1 -1
- package/dist/cjs/{chunk-33b9d1cf.js → chunk-a11294f9.js} +27 -26
- package/dist/cjs/{chunk-430b5370.js → chunk-bfcad370.js} +25 -2
- package/dist/cjs/{chunk-cc470e7c.js → chunk-c6fbc7b4.js} +7 -7
- package/dist/cjs/{chunk-993f89de.js → chunk-c7b2aa4b.js} +5 -4
- package/dist/cjs/{chunk-6474e963.js → chunk-d0f8ea39.js} +9 -9
- package/dist/cjs/{chunk-3acb500b.js → chunk-d120e215.js} +2 -2
- package/dist/cjs/{chunk-f5baaa70.js → chunk-d54e40f6.js} +2 -1
- package/dist/cjs/{chunk-916a2858.js → chunk-f5106717.js} +4 -4
- package/dist/cjs/chunk-fe2f57ee.js +110 -0
- package/dist/cjs/{chunk-2571dc7c.js → chunk-fefd7b77.js} +0 -0
- package/dist/cjs/clockpicker.js +11 -11
- package/dist/cjs/config.js +2 -2
- package/dist/cjs/datepicker.js +12 -12
- package/dist/cjs/datetimepicker.js +22 -15
- package/dist/cjs/dialog.js +13 -11
- package/dist/cjs/dropdown.js +8 -8
- package/dist/cjs/field.js +5 -5
- package/dist/cjs/helpers.js +2 -3
- package/dist/cjs/icon.js +3 -3
- package/dist/cjs/image.js +6 -311
- package/dist/cjs/index.js +29 -23
- package/dist/cjs/input.js +5 -5
- package/dist/cjs/loading.js +6 -6
- package/dist/cjs/menu.js +3 -3
- package/dist/cjs/message.js +6 -6
- package/dist/cjs/modal.js +6 -6
- package/dist/cjs/navbar.js +16 -4
- package/dist/cjs/notification.js +23 -11
- package/dist/cjs/numberinput.js +9 -7
- package/dist/cjs/pagination.js +8 -8
- package/dist/cjs/progress.js +10 -6
- package/dist/cjs/radio.js +3 -3
- package/dist/cjs/rate.js +3 -3
- package/dist/cjs/select.js +7 -7
- package/dist/cjs/sidebar.js +2 -2
- package/dist/cjs/slider.js +4 -4
- package/dist/cjs/snackbar.js +5 -5
- package/dist/cjs/steps.js +8 -8
- package/dist/cjs/switch.js +1 -1
- package/dist/cjs/table.js +13 -13
- package/dist/cjs/tabs.js +8 -8
- package/dist/cjs/tag.js +3 -3
- package/dist/cjs/taginput.js +34 -22
- package/dist/cjs/timepicker.js +13 -13
- package/dist/cjs/toast.js +5 -5
- package/dist/cjs/tooltip.js +5 -5
- package/dist/cjs/upload.js +5 -5
- package/dist/components/autocomplete/index.js +98 -13
- package/dist/components/autocomplete/index.min.js +2 -2
- package/dist/components/breadcrumb/index.js +293 -0
- package/dist/components/breadcrumb/index.min.js +2 -0
- package/dist/components/button/index.js +5 -1
- package/dist/components/button/index.min.js +2 -2
- package/dist/components/carousel/index.js +348 -15
- package/dist/components/carousel/index.min.js +2 -2
- package/dist/components/checkbox/index.js +1 -1
- package/dist/components/checkbox/index.min.js +1 -1
- package/dist/components/clockpicker/index.js +54 -47
- package/dist/components/clockpicker/index.min.js +2 -2
- package/dist/components/collapse/index.js +1 -1
- package/dist/components/collapse/index.min.js +1 -1
- package/dist/components/datepicker/index.js +41 -32
- package/dist/components/datepicker/index.min.js +2 -2
- package/dist/components/datetimepicker/index.js +75 -58
- package/dist/components/datetimepicker/index.min.js +2 -2
- package/dist/components/dialog/index.js +126 -18
- package/dist/components/dialog/index.min.js +2 -2
- package/dist/components/dropdown/index.js +5 -1
- package/dist/components/dropdown/index.min.js +1 -1
- package/dist/components/field/index.js +29 -23
- package/dist/components/field/index.min.js +2 -2
- package/dist/components/icon/index.js +5 -1
- package/dist/components/icon/index.min.js +2 -2
- package/dist/components/image/index.js +463 -444
- package/dist/components/image/index.min.js +2 -2
- package/dist/components/input/index.js +5 -1
- package/dist/components/input/index.min.js +2 -2
- package/dist/components/loading/index.js +2 -2
- package/dist/components/loading/index.min.js +2 -2
- package/dist/components/menu/index.js +5 -1
- package/dist/components/menu/index.min.js +2 -2
- package/dist/components/message/index.js +43 -3
- package/dist/components/message/index.min.js +2 -2
- package/dist/components/modal/index.js +7 -2
- package/dist/components/modal/index.min.js +2 -2
- package/dist/components/navbar/index.js +16 -4
- package/dist/components/navbar/index.min.js +2 -2
- package/dist/components/notification/index.js +59 -6
- package/dist/components/notification/index.min.js +2 -2
- package/dist/components/numberinput/index.js +9 -3
- package/dist/components/numberinput/index.min.js +2 -2
- package/dist/components/pagination/index.js +5 -1
- package/dist/components/pagination/index.min.js +2 -2
- package/dist/components/progress/index.js +10 -2
- package/dist/components/progress/index.min.js +2 -2
- package/dist/components/radio/index.js +1 -1
- package/dist/components/radio/index.min.js +1 -1
- package/dist/components/rate/index.js +5 -1
- package/dist/components/rate/index.min.js +2 -2
- package/dist/components/select/index.js +5 -1
- package/dist/components/select/index.min.js +2 -2
- package/dist/components/sidebar/index.js +5 -1
- package/dist/components/sidebar/index.min.js +1 -1
- package/dist/components/skeleton/index.js +1 -1
- package/dist/components/skeleton/index.min.js +1 -1
- package/dist/components/slider/index.js +5 -1
- package/dist/components/slider/index.min.js +2 -2
- package/dist/components/snackbar/index.js +7 -2
- package/dist/components/snackbar/index.min.js +2 -2
- package/dist/components/steps/index.js +5 -1
- package/dist/components/steps/index.min.js +2 -2
- package/dist/components/switch/index.js +5 -1
- package/dist/components/switch/index.min.js +1 -1
- package/dist/components/table/index.js +6 -2
- package/dist/components/table/index.min.js +2 -2
- package/dist/components/tabs/index.js +5 -1
- package/dist/components/tabs/index.min.js +2 -2
- package/dist/components/tag/index.js +26 -3
- package/dist/components/tag/index.min.js +2 -2
- package/dist/components/taginput/index.js +185 -29
- package/dist/components/taginput/index.min.js +2 -2
- package/dist/components/timepicker/index.js +54 -47
- package/dist/components/timepicker/index.min.js +2 -2
- package/dist/components/toast/index.js +7 -2
- package/dist/components/toast/index.min.js +2 -2
- package/dist/components/tooltip/index.js +5 -1
- package/dist/components/tooltip/index.min.js +1 -1
- package/dist/components/upload/index.js +5 -1
- package/dist/components/upload/index.min.js +2 -2
- package/dist/esm/autocomplete.js +7 -7
- package/dist/esm/breadcrumb.js +122 -0
- package/dist/esm/button.js +6 -107
- package/dist/esm/carousel.js +7 -5
- package/dist/esm/{chunk-56040896.js → chunk-18e8b067.js} +3 -3
- package/dist/esm/{chunk-fa404a2c.js → chunk-21fc0948.js} +7 -7
- package/dist/esm/{chunk-f9299099.js → chunk-22e9f916.js} +19 -15
- package/dist/esm/{chunk-1fafdf15.js → chunk-2452e3d3.js} +37 -1
- package/dist/esm/{chunk-1297c2c9.js → chunk-29ca0df8.js} +1 -1
- package/dist/esm/{chunk-3c2169d7.js → chunk-2f2f0a74.js} +25 -2
- package/dist/esm/{chunk-cf72ce36.js → chunk-3773c62d.js} +2 -2
- package/dist/esm/{chunk-2c957994.js → chunk-4b67a181.js} +3 -3
- package/dist/esm/{chunk-45740cdc.js → chunk-6019fd7a.js} +96 -15
- package/dist/esm/chunk-71a547bc.js +312 -0
- package/dist/esm/{chunk-516e4877.js → chunk-75a5af93.js} +1 -1
- package/dist/esm/{chunk-4e380ee2.js → chunk-799e084d.js} +2 -1
- package/dist/esm/{chunk-37678809.js → chunk-83eb0d37.js} +3 -3
- package/dist/esm/{chunk-34c74085.js → chunk-8d0f95b8.js} +4 -4
- package/dist/esm/{chunk-652f2dad.js → chunk-8ed29c41.js} +4 -0
- package/dist/esm/{chunk-742a9694.js → chunk-9f7f7441.js} +3 -2
- package/dist/esm/{chunk-f160efb9.js → chunk-ae8ab23a.js} +4 -4
- package/dist/esm/{chunk-c3b09672.js → chunk-b07e3182.js} +26 -24
- package/dist/esm/{chunk-e36a4f2c.js → chunk-b0c0c6b0.js} +0 -0
- package/dist/esm/{chunk-ee935ae6.js → chunk-c9c58d0c.js} +1 -1
- package/dist/esm/{chunk-1d62828e.js → chunk-d7f92d97.js} +39 -3
- package/dist/esm/{chunk-7fd02ffe.js → chunk-d92f0cd9.js} +2 -2
- package/dist/esm/chunk-e7c9b2cb.js +108 -0
- package/dist/esm/{chunk-0e22ae0a.js → chunk-ece062a7.js} +27 -26
- package/dist/esm/clockpicker.js +9 -9
- package/dist/esm/config.js +2 -2
- package/dist/esm/datepicker.js +11 -11
- package/dist/esm/datetimepicker.js +21 -14
- package/dist/esm/dialog.js +10 -8
- package/dist/esm/dropdown.js +5 -5
- package/dist/esm/field.js +4 -4
- package/dist/esm/helpers.js +2 -3
- package/dist/esm/icon.js +4 -4
- package/dist/esm/image.js +6 -311
- package/dist/esm/index.js +106 -100
- package/dist/esm/input.js +6 -6
- package/dist/esm/loading.js +4 -4
- package/dist/esm/menu.js +3 -3
- package/dist/esm/message.js +5 -5
- package/dist/esm/modal.js +4 -4
- package/dist/esm/navbar.js +16 -4
- package/dist/esm/notification.js +22 -10
- package/dist/esm/numberinput.js +9 -7
- package/dist/esm/pagination.js +5 -5
- package/dist/esm/progress.js +8 -4
- package/dist/esm/rate.js +3 -3
- package/dist/esm/select.js +6 -6
- package/dist/esm/sidebar.js +2 -2
- package/dist/esm/slider.js +3 -3
- package/dist/esm/snackbar.js +4 -4
- package/dist/esm/steps.js +6 -6
- package/dist/esm/switch.js +1 -1
- package/dist/esm/table.js +9 -9
- package/dist/esm/tabs.js +6 -6
- package/dist/esm/tag.js +2 -2
- package/dist/esm/taginput.js +33 -21
- package/dist/esm/timepicker.js +12 -12
- package/dist/esm/toast.js +4 -4
- package/dist/esm/tooltip.js +4 -4
- package/dist/esm/upload.js +3 -3
- package/dist/vetur/attributes.json +95 -19
- package/dist/vetur/tags.json +37 -4
- package/package.json +2 -2
- package/src/components/autocomplete/Autocomplete.spec.js +70 -0
- package/src/components/autocomplete/Autocomplete.vue +93 -18
- package/src/components/breadcrumb/Breadcrumb.spec.js +63 -0
- package/src/components/breadcrumb/Breadcrumb.vue +43 -0
- package/src/components/breadcrumb/BreadcrumbItem.spec.js +25 -0
- package/src/components/breadcrumb/BreadcrumbItem.vue +33 -0
- package/src/components/breadcrumb/__snapshots__/Breadcrumb.spec.js.snap +7 -0
- package/src/components/breadcrumb/__snapshots__/BreadcrumbItem.spec.js.snap +7 -0
- package/src/components/breadcrumb/index.js +20 -0
- package/src/components/carousel/CarouselList.vue +3 -1
- package/src/components/carousel/__snapshots__/CarouselList.spec.js.snap +128 -8
- package/src/components/clockpicker/Clockpicker.vue +259 -259
- package/src/components/datepicker/Datepicker.vue +10 -6
- package/src/components/datetimepicker/Datetimepicker.vue +8 -1
- package/src/components/dialog/Dialog.vue +10 -10
- package/src/components/field/Field.vue +271 -270
- package/src/components/image/Image.spec.js +197 -183
- package/src/components/image/Image.vue +4 -2
- package/src/components/index.js +2 -0
- package/src/components/loading/Loading.vue +1 -1
- package/src/components/loading/__snapshots__/Loading.spec.js.snap +1 -1
- package/src/components/message/Message.vue +7 -1
- package/src/components/message/__snapshots__/Message.spec.js.snap +1 -0
- package/src/components/modal/Modal.vue +2 -0
- package/src/components/navbar/Navbar.vue +5 -1
- package/src/components/navbar/NavbarBurger.vue +1 -0
- package/src/components/navbar/NavbarDropdown.vue +8 -2
- package/src/components/navbar/__snapshots__/NavBar.spec.js.snap +11 -11
- package/src/components/navbar/__snapshots__/NavBarBurger.spec.js.snap +3 -0
- package/src/components/navbar/__snapshots__/NavbarDropdown.spec.js.snap +1 -1
- package/src/components/notification/Notification.vue +6 -0
- package/src/components/notification/NotificationNotice.vue +16 -3
- package/src/components/notification/__snapshots__/Notification.spec.js.snap +1 -0
- package/src/components/numberinput/Numberinput.spec.js +10 -0
- package/src/components/numberinput/Numberinput.vue +4 -2
- package/src/components/progress/Progress.vue +6 -2
- package/src/components/snackbar/Snackbar.vue +2 -0
- package/src/components/tag/Tag.vue +25 -2
- package/src/components/tag/__snapshots__/Tag.spec.js.snap +1 -1
- package/src/components/taginput/Taginput.spec.js +57 -1
- package/src/components/taginput/Taginput.vue +373 -364
- package/src/components/toast/Toast.vue +1 -1
- package/src/index.js +2 -0
- package/src/scss/buefy.scss +1 -0
- package/src/scss/components/_loading.scss +2 -1
- package/src/scss/components/_message.scss +3 -0
- package/src/scss/components/_notification.scss +8 -0
- package/src/scss/components/_progress.scss +8 -0
- package/src/utils/MessageMixin.js +32 -1
- package/src/utils/NoticeMixin.js +1 -0
- package/src/utils/TimepickerMixin.js +718 -716
- package/src/utils/config.js +4 -0
- package/src/utils/helpers.js +1 -2
- package/types/components.d.ts +5 -0
- package/src/components/navbar/__snapshots__/NavbarBurger.spec.js.snap +0 -3
|
@@ -1,716 +1,718 @@
|
|
|
1
|
-
import FormElementMixin from './FormElementMixin'
|
|
2
|
-
import { isMobile, matchWithGroups } from './helpers'
|
|
3
|
-
import config from './config'
|
|
4
|
-
|
|
5
|
-
const AM = 'AM'
|
|
6
|
-
const PM = 'PM'
|
|
7
|
-
const HOUR_FORMAT_24 = '24'
|
|
8
|
-
const HOUR_FORMAT_12 = '12'
|
|
9
|
-
|
|
10
|
-
const defaultTimeFormatter = (date, vm) => {
|
|
11
|
-
return vm.dtf.format(date)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const defaultTimeParser = (timeString, vm) => {
|
|
15
|
-
if (timeString) {
|
|
16
|
-
let d = null
|
|
17
|
-
if (vm.computedValue && !isNaN(vm.computedValue)) {
|
|
18
|
-
d = new Date(vm.computedValue)
|
|
19
|
-
} else {
|
|
20
|
-
d = vm.timeCreator()
|
|
21
|
-
d.setMilliseconds(0)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (vm.dtf.formatToParts && typeof vm.dtf.formatToParts === 'function') {
|
|
25
|
-
const formatRegex = vm.dtf
|
|
26
|
-
.formatToParts(d).map((part) => {
|
|
27
|
-
if (part.type === 'literal') {
|
|
28
|
-
return part.value.replace(/ /g, '\\s?')
|
|
29
|
-
} else if (part.type === 'dayPeriod') {
|
|
30
|
-
return `((?!=<${part.type}>)(${vm.amString}|${vm.pmString}|${AM}|${PM}|${AM.toLowerCase()}|${PM.toLowerCase()})?)`
|
|
31
|
-
}
|
|
32
|
-
return `((?!=<${part.type}>)\\d+)`
|
|
33
|
-
}).join('')
|
|
34
|
-
const timeGroups = matchWithGroups(formatRegex, timeString)
|
|
35
|
-
|
|
36
|
-
// We do a simple validation for the group.
|
|
37
|
-
// If it is not valid, it will fallback to Date.parse below
|
|
38
|
-
timeGroups.hour = timeGroups.hour ? parseInt(timeGroups.hour, 10) : null
|
|
39
|
-
timeGroups.minute = timeGroups.minute ? parseInt(timeGroups.minute, 10) : null
|
|
40
|
-
timeGroups.second = timeGroups.second ? parseInt(timeGroups.second, 10) : null
|
|
41
|
-
if (
|
|
42
|
-
timeGroups.hour &&
|
|
43
|
-
timeGroups.hour >= 0 &&
|
|
44
|
-
timeGroups.hour < 24 &&
|
|
45
|
-
timeGroups.minute &&
|
|
46
|
-
timeGroups.minute >= 0 &&
|
|
47
|
-
timeGroups.minute < 59
|
|
48
|
-
) {
|
|
49
|
-
if (timeGroups.dayPeriod &&
|
|
50
|
-
(
|
|
51
|
-
timeGroups.dayPeriod.toLowerCase() === vm.pmString.toLowerCase() ||
|
|
52
|
-
timeGroups.dayPeriod.toLowerCase() === PM.toLowerCase()
|
|
53
|
-
) &&
|
|
54
|
-
timeGroups.hour < 12) {
|
|
55
|
-
timeGroups.hour += 12
|
|
56
|
-
}
|
|
57
|
-
d.setHours(timeGroups.hour)
|
|
58
|
-
d.setMinutes(timeGroups.minute)
|
|
59
|
-
d.setSeconds(timeGroups.second || 0)
|
|
60
|
-
return d
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Fallback if formatToParts is not supported or if we were not able to parse a valid date
|
|
65
|
-
let am = false
|
|
66
|
-
if (vm.hourFormat === HOUR_FORMAT_12) {
|
|
67
|
-
const dateString12 = timeString.split(' ')
|
|
68
|
-
timeString = dateString12[0]
|
|
69
|
-
am = (dateString12[1] === vm.amString || dateString12[1] === AM)
|
|
70
|
-
}
|
|
71
|
-
const time = timeString.split(':')
|
|
72
|
-
let hours = parseInt(time[0], 10)
|
|
73
|
-
const minutes = parseInt(time[1], 10)
|
|
74
|
-
const seconds = vm.enableSeconds ? parseInt(time[2], 10) : 0
|
|
75
|
-
if (isNaN(hours) || hours < 0 || hours > 23 ||
|
|
76
|
-
(vm.hourFormat === HOUR_FORMAT_12 && (hours < 1 || hours > 12)) ||
|
|
77
|
-
isNaN(minutes) || minutes < 0 || minutes > 59) {
|
|
78
|
-
return null
|
|
79
|
-
}
|
|
80
|
-
d.setSeconds(seconds)
|
|
81
|
-
d.setMinutes(minutes)
|
|
82
|
-
if (vm.hourFormat === HOUR_FORMAT_12) {
|
|
83
|
-
if (am && hours === 12) {
|
|
84
|
-
hours = 0
|
|
85
|
-
} else if (!am && hours !== 12) {
|
|
86
|
-
hours += 12
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
d.setHours(hours)
|
|
90
|
-
return new Date(d.getTime())
|
|
91
|
-
}
|
|
92
|
-
return null
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export default {
|
|
96
|
-
mixins: [FormElementMixin],
|
|
97
|
-
inheritAttrs: false,
|
|
98
|
-
props: {
|
|
99
|
-
value: Date,
|
|
100
|
-
inline: Boolean,
|
|
101
|
-
minTime: Date,
|
|
102
|
-
maxTime: Date,
|
|
103
|
-
placeholder: String,
|
|
104
|
-
editable: Boolean,
|
|
105
|
-
disabled: Boolean,
|
|
106
|
-
hourFormat: {
|
|
107
|
-
type: String,
|
|
108
|
-
validator: (value) => {
|
|
109
|
-
return value === HOUR_FORMAT_24 || value === HOUR_FORMAT_12
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
incrementHours: {
|
|
113
|
-
type: Number,
|
|
114
|
-
default: 1
|
|
115
|
-
},
|
|
116
|
-
incrementMinutes: {
|
|
117
|
-
type: Number,
|
|
118
|
-
default: 1
|
|
119
|
-
},
|
|
120
|
-
incrementSeconds: {
|
|
121
|
-
type: Number,
|
|
122
|
-
default: 1
|
|
123
|
-
},
|
|
124
|
-
timeFormatter: {
|
|
125
|
-
type: Function,
|
|
126
|
-
default: (date, vm) => {
|
|
127
|
-
if (typeof config.defaultTimeFormatter === 'function') {
|
|
128
|
-
return config.defaultTimeFormatter(date)
|
|
129
|
-
} else {
|
|
130
|
-
return defaultTimeFormatter(date, vm)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
timeParser: {
|
|
135
|
-
type: Function,
|
|
136
|
-
default: (date, vm) => {
|
|
137
|
-
if (typeof config.defaultTimeParser === 'function') {
|
|
138
|
-
return config.defaultTimeParser(date)
|
|
139
|
-
} else {
|
|
140
|
-
return defaultTimeParser(date, vm)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
mobileNative: {
|
|
145
|
-
type: Boolean,
|
|
146
|
-
default: () => config.defaultTimepickerMobileNative
|
|
147
|
-
},
|
|
148
|
-
timeCreator: {
|
|
149
|
-
type: Function,
|
|
150
|
-
default: () => {
|
|
151
|
-
if (typeof config.defaultTimeCreator === 'function') {
|
|
152
|
-
return config.defaultTimeCreator()
|
|
153
|
-
} else {
|
|
154
|
-
return new Date()
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
position: String,
|
|
159
|
-
unselectableTimes: Array,
|
|
160
|
-
openOnFocus: Boolean,
|
|
161
|
-
enableSeconds: Boolean,
|
|
162
|
-
defaultMinutes: Number,
|
|
163
|
-
defaultSeconds: Number,
|
|
164
|
-
focusable: {
|
|
165
|
-
type: Boolean,
|
|
166
|
-
default: true
|
|
167
|
-
},
|
|
168
|
-
tzOffset: {
|
|
169
|
-
type: Number,
|
|
170
|
-
default: 0
|
|
171
|
-
},
|
|
172
|
-
appendToBody: Boolean,
|
|
173
|
-
resetOnMeridianChange: {
|
|
174
|
-
type: Boolean,
|
|
175
|
-
default: false
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
data() {
|
|
179
|
-
return {
|
|
180
|
-
dateSelected: this.value,
|
|
181
|
-
hoursSelected: null,
|
|
182
|
-
minutesSelected: null,
|
|
183
|
-
secondsSelected: null,
|
|
184
|
-
meridienSelected: null,
|
|
185
|
-
_elementRef: 'input',
|
|
186
|
-
AM,
|
|
187
|
-
PM,
|
|
188
|
-
HOUR_FORMAT_24,
|
|
189
|
-
HOUR_FORMAT_12
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
computed: {
|
|
193
|
-
computedValue: {
|
|
194
|
-
get() {
|
|
195
|
-
return this.dateSelected
|
|
196
|
-
},
|
|
197
|
-
set(value) {
|
|
198
|
-
this.dateSelected = value
|
|
199
|
-
this.$emit('input', this.dateSelected)
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
localeOptions() {
|
|
203
|
-
return new Intl.DateTimeFormat(this.locale, {
|
|
204
|
-
hour: 'numeric',
|
|
205
|
-
minute: 'numeric',
|
|
206
|
-
second: this.enableSeconds ? 'numeric' : undefined
|
|
207
|
-
}).resolvedOptions()
|
|
208
|
-
},
|
|
209
|
-
dtf() {
|
|
210
|
-
return new Intl.DateTimeFormat(this.locale, {
|
|
211
|
-
hour: this.localeOptions.hour || 'numeric',
|
|
212
|
-
minute: this.localeOptions.minute || 'numeric',
|
|
213
|
-
second: this.enableSeconds ? this.localeOptions.second || 'numeric' : undefined,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
d.
|
|
223
|
-
d.
|
|
224
|
-
d.
|
|
225
|
-
d.
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
d.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
d.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
let
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
this.
|
|
376
|
-
this.
|
|
377
|
-
this.
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
this.
|
|
388
|
-
this.
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
this.
|
|
403
|
-
this.
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
this.
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
this.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
time.
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
time.
|
|
440
|
-
time.
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
this.
|
|
450
|
-
this.
|
|
451
|
-
|
|
452
|
-
this.
|
|
453
|
-
|
|
454
|
-
this.
|
|
455
|
-
this.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
disabled =
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
disabled =
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
time = new Date()
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
time.
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
this.computedValue =
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
return
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
}
|
|
1
|
+
import FormElementMixin from './FormElementMixin'
|
|
2
|
+
import { isMobile, matchWithGroups } from './helpers'
|
|
3
|
+
import config from './config'
|
|
4
|
+
|
|
5
|
+
const AM = 'AM'
|
|
6
|
+
const PM = 'PM'
|
|
7
|
+
const HOUR_FORMAT_24 = '24'
|
|
8
|
+
const HOUR_FORMAT_12 = '12'
|
|
9
|
+
|
|
10
|
+
const defaultTimeFormatter = (date, vm) => {
|
|
11
|
+
return vm.dtf.format(date)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const defaultTimeParser = (timeString, vm) => {
|
|
15
|
+
if (timeString) {
|
|
16
|
+
let d = null
|
|
17
|
+
if (vm.computedValue && !isNaN(vm.computedValue)) {
|
|
18
|
+
d = new Date(vm.computedValue)
|
|
19
|
+
} else {
|
|
20
|
+
d = vm.timeCreator()
|
|
21
|
+
d.setMilliseconds(0)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (vm.dtf.formatToParts && typeof vm.dtf.formatToParts === 'function') {
|
|
25
|
+
const formatRegex = vm.dtf
|
|
26
|
+
.formatToParts(d).map((part) => {
|
|
27
|
+
if (part.type === 'literal') {
|
|
28
|
+
return part.value.replace(/ /g, '\\s?')
|
|
29
|
+
} else if (part.type === 'dayPeriod') {
|
|
30
|
+
return `((?!=<${part.type}>)(${vm.amString}|${vm.pmString}|${AM}|${PM}|${AM.toLowerCase()}|${PM.toLowerCase()})?)`
|
|
31
|
+
}
|
|
32
|
+
return `((?!=<${part.type}>)\\d+)`
|
|
33
|
+
}).join('')
|
|
34
|
+
const timeGroups = matchWithGroups(formatRegex, timeString)
|
|
35
|
+
|
|
36
|
+
// We do a simple validation for the group.
|
|
37
|
+
// If it is not valid, it will fallback to Date.parse below
|
|
38
|
+
timeGroups.hour = timeGroups.hour ? parseInt(timeGroups.hour, 10) : null
|
|
39
|
+
timeGroups.minute = timeGroups.minute ? parseInt(timeGroups.minute, 10) : null
|
|
40
|
+
timeGroups.second = timeGroups.second ? parseInt(timeGroups.second, 10) : null
|
|
41
|
+
if (
|
|
42
|
+
timeGroups.hour &&
|
|
43
|
+
timeGroups.hour >= 0 &&
|
|
44
|
+
timeGroups.hour < 24 &&
|
|
45
|
+
timeGroups.minute &&
|
|
46
|
+
timeGroups.minute >= 0 &&
|
|
47
|
+
timeGroups.minute < 59
|
|
48
|
+
) {
|
|
49
|
+
if (timeGroups.dayPeriod &&
|
|
50
|
+
(
|
|
51
|
+
timeGroups.dayPeriod.toLowerCase() === vm.pmString.toLowerCase() ||
|
|
52
|
+
timeGroups.dayPeriod.toLowerCase() === PM.toLowerCase()
|
|
53
|
+
) &&
|
|
54
|
+
timeGroups.hour < 12) {
|
|
55
|
+
timeGroups.hour += 12
|
|
56
|
+
}
|
|
57
|
+
d.setHours(timeGroups.hour)
|
|
58
|
+
d.setMinutes(timeGroups.minute)
|
|
59
|
+
d.setSeconds(timeGroups.second || 0)
|
|
60
|
+
return d
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Fallback if formatToParts is not supported or if we were not able to parse a valid date
|
|
65
|
+
let am = false
|
|
66
|
+
if (vm.hourFormat === HOUR_FORMAT_12) {
|
|
67
|
+
const dateString12 = timeString.split(' ')
|
|
68
|
+
timeString = dateString12[0]
|
|
69
|
+
am = (dateString12[1] === vm.amString || dateString12[1] === AM)
|
|
70
|
+
}
|
|
71
|
+
const time = timeString.split(':')
|
|
72
|
+
let hours = parseInt(time[0], 10)
|
|
73
|
+
const minutes = parseInt(time[1], 10)
|
|
74
|
+
const seconds = vm.enableSeconds ? parseInt(time[2], 10) : 0
|
|
75
|
+
if (isNaN(hours) || hours < 0 || hours > 23 ||
|
|
76
|
+
(vm.hourFormat === HOUR_FORMAT_12 && (hours < 1 || hours > 12)) ||
|
|
77
|
+
isNaN(minutes) || minutes < 0 || minutes > 59) {
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
d.setSeconds(seconds)
|
|
81
|
+
d.setMinutes(minutes)
|
|
82
|
+
if (vm.hourFormat === HOUR_FORMAT_12) {
|
|
83
|
+
if (am && hours === 12) {
|
|
84
|
+
hours = 0
|
|
85
|
+
} else if (!am && hours !== 12) {
|
|
86
|
+
hours += 12
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
d.setHours(hours)
|
|
90
|
+
return new Date(d.getTime())
|
|
91
|
+
}
|
|
92
|
+
return null
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export default {
|
|
96
|
+
mixins: [FormElementMixin],
|
|
97
|
+
inheritAttrs: false,
|
|
98
|
+
props: {
|
|
99
|
+
value: Date,
|
|
100
|
+
inline: Boolean,
|
|
101
|
+
minTime: Date,
|
|
102
|
+
maxTime: Date,
|
|
103
|
+
placeholder: String,
|
|
104
|
+
editable: Boolean,
|
|
105
|
+
disabled: Boolean,
|
|
106
|
+
hourFormat: {
|
|
107
|
+
type: String,
|
|
108
|
+
validator: (value) => {
|
|
109
|
+
return value === HOUR_FORMAT_24 || value === HOUR_FORMAT_12
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
incrementHours: {
|
|
113
|
+
type: Number,
|
|
114
|
+
default: 1
|
|
115
|
+
},
|
|
116
|
+
incrementMinutes: {
|
|
117
|
+
type: Number,
|
|
118
|
+
default: 1
|
|
119
|
+
},
|
|
120
|
+
incrementSeconds: {
|
|
121
|
+
type: Number,
|
|
122
|
+
default: 1
|
|
123
|
+
},
|
|
124
|
+
timeFormatter: {
|
|
125
|
+
type: Function,
|
|
126
|
+
default: (date, vm) => {
|
|
127
|
+
if (typeof config.defaultTimeFormatter === 'function') {
|
|
128
|
+
return config.defaultTimeFormatter(date)
|
|
129
|
+
} else {
|
|
130
|
+
return defaultTimeFormatter(date, vm)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
timeParser: {
|
|
135
|
+
type: Function,
|
|
136
|
+
default: (date, vm) => {
|
|
137
|
+
if (typeof config.defaultTimeParser === 'function') {
|
|
138
|
+
return config.defaultTimeParser(date)
|
|
139
|
+
} else {
|
|
140
|
+
return defaultTimeParser(date, vm)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
mobileNative: {
|
|
145
|
+
type: Boolean,
|
|
146
|
+
default: () => config.defaultTimepickerMobileNative
|
|
147
|
+
},
|
|
148
|
+
timeCreator: {
|
|
149
|
+
type: Function,
|
|
150
|
+
default: () => {
|
|
151
|
+
if (typeof config.defaultTimeCreator === 'function') {
|
|
152
|
+
return config.defaultTimeCreator()
|
|
153
|
+
} else {
|
|
154
|
+
return new Date()
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
position: String,
|
|
159
|
+
unselectableTimes: Array,
|
|
160
|
+
openOnFocus: Boolean,
|
|
161
|
+
enableSeconds: Boolean,
|
|
162
|
+
defaultMinutes: Number,
|
|
163
|
+
defaultSeconds: Number,
|
|
164
|
+
focusable: {
|
|
165
|
+
type: Boolean,
|
|
166
|
+
default: true
|
|
167
|
+
},
|
|
168
|
+
tzOffset: {
|
|
169
|
+
type: Number,
|
|
170
|
+
default: 0
|
|
171
|
+
},
|
|
172
|
+
appendToBody: Boolean,
|
|
173
|
+
resetOnMeridianChange: {
|
|
174
|
+
type: Boolean,
|
|
175
|
+
default: false
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
data() {
|
|
179
|
+
return {
|
|
180
|
+
dateSelected: this.value,
|
|
181
|
+
hoursSelected: null,
|
|
182
|
+
minutesSelected: null,
|
|
183
|
+
secondsSelected: null,
|
|
184
|
+
meridienSelected: null,
|
|
185
|
+
_elementRef: 'input',
|
|
186
|
+
AM,
|
|
187
|
+
PM,
|
|
188
|
+
HOUR_FORMAT_24,
|
|
189
|
+
HOUR_FORMAT_12
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
computed: {
|
|
193
|
+
computedValue: {
|
|
194
|
+
get() {
|
|
195
|
+
return this.dateSelected
|
|
196
|
+
},
|
|
197
|
+
set(value) {
|
|
198
|
+
this.dateSelected = value
|
|
199
|
+
this.$emit('input', this.dateSelected)
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
localeOptions() {
|
|
203
|
+
return new Intl.DateTimeFormat(this.locale, {
|
|
204
|
+
hour: 'numeric',
|
|
205
|
+
minute: 'numeric',
|
|
206
|
+
second: this.enableSeconds ? 'numeric' : undefined
|
|
207
|
+
}).resolvedOptions()
|
|
208
|
+
},
|
|
209
|
+
dtf() {
|
|
210
|
+
return new Intl.DateTimeFormat(this.locale, {
|
|
211
|
+
hour: this.localeOptions.hour || 'numeric',
|
|
212
|
+
minute: this.localeOptions.minute || 'numeric',
|
|
213
|
+
second: this.enableSeconds ? this.localeOptions.second || 'numeric' : undefined,
|
|
214
|
+
// Fixes 12 hour display github.com/buefy/buefy/issues/3418
|
|
215
|
+
hourCycle: !this.isHourFormat24 ? 'h12' : 'h23'
|
|
216
|
+
})
|
|
217
|
+
},
|
|
218
|
+
newHourFormat() {
|
|
219
|
+
return this.hourFormat || (this.localeOptions.hour12 ? HOUR_FORMAT_12 : HOUR_FORMAT_24)
|
|
220
|
+
},
|
|
221
|
+
sampleTime() {
|
|
222
|
+
let d = this.timeCreator()
|
|
223
|
+
d.setHours(10)
|
|
224
|
+
d.setSeconds(0)
|
|
225
|
+
d.setMinutes(0)
|
|
226
|
+
d.setMilliseconds(0)
|
|
227
|
+
return d
|
|
228
|
+
},
|
|
229
|
+
hourLiteral() {
|
|
230
|
+
if (this.dtf.formatToParts && typeof this.dtf.formatToParts === 'function') {
|
|
231
|
+
let d = this.sampleTime
|
|
232
|
+
const parts = this.dtf.formatToParts(d)
|
|
233
|
+
const literal = parts.find((part, idx) => (idx > 0 && parts[idx - 1].type === 'hour'))
|
|
234
|
+
if (literal) {
|
|
235
|
+
return literal.value
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return ':'
|
|
239
|
+
},
|
|
240
|
+
minuteLiteral() {
|
|
241
|
+
if (this.dtf.formatToParts && typeof this.dtf.formatToParts === 'function') {
|
|
242
|
+
let d = this.sampleTime
|
|
243
|
+
const parts = this.dtf.formatToParts(d)
|
|
244
|
+
const literal = parts.find((part, idx) => (idx > 0 && parts[idx - 1].type === 'minute'))
|
|
245
|
+
if (literal) {
|
|
246
|
+
return literal.value
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return ':'
|
|
250
|
+
},
|
|
251
|
+
secondLiteral() {
|
|
252
|
+
if (this.dtf.formatToParts && typeof this.dtf.formatToParts === 'function') {
|
|
253
|
+
let d = this.sampleTime
|
|
254
|
+
const parts = this.dtf.formatToParts(d)
|
|
255
|
+
const literal = parts.find((part, idx) => (idx > 0 && parts[idx - 1].type === 'second'))
|
|
256
|
+
if (literal) {
|
|
257
|
+
return literal.value
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
amString() {
|
|
262
|
+
if (this.dtf.formatToParts && typeof this.dtf.formatToParts === 'function') {
|
|
263
|
+
let d = this.sampleTime
|
|
264
|
+
d.setHours(10)
|
|
265
|
+
const dayPeriod = this.dtf.formatToParts(d).find((part) => part.type === 'dayPeriod')
|
|
266
|
+
if (dayPeriod) {
|
|
267
|
+
return dayPeriod.value
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return AM
|
|
271
|
+
},
|
|
272
|
+
pmString() {
|
|
273
|
+
if (this.dtf.formatToParts && typeof this.dtf.formatToParts === 'function') {
|
|
274
|
+
let d = this.sampleTime
|
|
275
|
+
d.setHours(20)
|
|
276
|
+
const dayPeriod = this.dtf.formatToParts(d).find((part) => part.type === 'dayPeriod')
|
|
277
|
+
if (dayPeriod) {
|
|
278
|
+
return dayPeriod.value
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return PM
|
|
282
|
+
},
|
|
283
|
+
hours() {
|
|
284
|
+
if (!this.incrementHours || this.incrementHours < 1) throw new Error('Hour increment cannot be null or less than 1.')
|
|
285
|
+
const hours = []
|
|
286
|
+
const numberOfHours = this.isHourFormat24 ? 24 : 12
|
|
287
|
+
for (let i = 0; i < numberOfHours; i += this.incrementHours) {
|
|
288
|
+
let value = i
|
|
289
|
+
let label = value
|
|
290
|
+
if (!this.isHourFormat24) {
|
|
291
|
+
value = (i + 1)
|
|
292
|
+
label = value
|
|
293
|
+
if (this.meridienSelected === this.amString) {
|
|
294
|
+
if (value === 12) {
|
|
295
|
+
value = 0
|
|
296
|
+
}
|
|
297
|
+
} else if (this.meridienSelected === this.pmString) {
|
|
298
|
+
if (value !== 12) {
|
|
299
|
+
value += 12
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
hours.push({
|
|
304
|
+
label: this.formatNumber(label),
|
|
305
|
+
value: value
|
|
306
|
+
})
|
|
307
|
+
}
|
|
308
|
+
return hours
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
minutes() {
|
|
312
|
+
if (!this.incrementMinutes || this.incrementMinutes < 1) throw new Error('Minute increment cannot be null or less than 1.')
|
|
313
|
+
const minutes = []
|
|
314
|
+
for (let i = 0; i < 60; i += this.incrementMinutes) {
|
|
315
|
+
minutes.push({
|
|
316
|
+
label: this.formatNumber(i, true),
|
|
317
|
+
value: i
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
return minutes
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
seconds() {
|
|
324
|
+
if (!this.incrementSeconds || this.incrementSeconds < 1) throw new Error('Second increment cannot be null or less than 1.')
|
|
325
|
+
const seconds = []
|
|
326
|
+
for (let i = 0; i < 60; i += this.incrementSeconds) {
|
|
327
|
+
seconds.push({
|
|
328
|
+
label: this.formatNumber(i, true),
|
|
329
|
+
value: i
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
return seconds
|
|
333
|
+
},
|
|
334
|
+
|
|
335
|
+
meridiens() {
|
|
336
|
+
return [this.amString, this.pmString]
|
|
337
|
+
},
|
|
338
|
+
|
|
339
|
+
isMobile() {
|
|
340
|
+
return this.mobileNative && isMobile.any()
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
isHourFormat24() {
|
|
344
|
+
return this.newHourFormat === HOUR_FORMAT_24
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
watch: {
|
|
348
|
+
hourFormat() {
|
|
349
|
+
if (this.hoursSelected !== null) {
|
|
350
|
+
this.meridienSelected = this.hoursSelected >= 12 ? this.pmString : this.amString
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
locale() {
|
|
354
|
+
// see updateInternalState default
|
|
355
|
+
if (!this.value) {
|
|
356
|
+
this.meridienSelected = this.amString
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
/**
|
|
360
|
+
* When v-model is changed:
|
|
361
|
+
* 1. Update internal value.
|
|
362
|
+
* 2. If it's invalid, validate again.
|
|
363
|
+
*/
|
|
364
|
+
value: {
|
|
365
|
+
handler(value) {
|
|
366
|
+
this.updateInternalState(value)
|
|
367
|
+
!this.isValid && this.$refs.input.checkHtml5Validity()
|
|
368
|
+
},
|
|
369
|
+
immediate: true
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
methods: {
|
|
373
|
+
onMeridienChange(value) {
|
|
374
|
+
if (this.hoursSelected !== null && this.resetOnMeridianChange) {
|
|
375
|
+
this.hoursSelected = null
|
|
376
|
+
this.minutesSelected = null
|
|
377
|
+
this.secondsSelected = null
|
|
378
|
+
this.computedValue = null
|
|
379
|
+
} else if (this.hoursSelected !== null) {
|
|
380
|
+
if (value === this.pmString) {
|
|
381
|
+
this.hoursSelected += 12
|
|
382
|
+
} else if (value === this.amString) {
|
|
383
|
+
this.hoursSelected -= 12
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
this.updateDateSelected(
|
|
387
|
+
this.hoursSelected,
|
|
388
|
+
this.minutesSelected,
|
|
389
|
+
this.enableSeconds ? this.secondsSelected : 0,
|
|
390
|
+
value)
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
onHoursChange(value) {
|
|
394
|
+
if (!this.minutesSelected && typeof this.defaultMinutes !== 'undefined') {
|
|
395
|
+
this.minutesSelected = this.defaultMinutes
|
|
396
|
+
}
|
|
397
|
+
if (!this.secondsSelected && typeof this.defaultSeconds !== 'undefined') {
|
|
398
|
+
this.secondsSelected = this.defaultSeconds
|
|
399
|
+
}
|
|
400
|
+
this.updateDateSelected(
|
|
401
|
+
parseInt(value, 10),
|
|
402
|
+
this.minutesSelected,
|
|
403
|
+
this.enableSeconds ? this.secondsSelected : 0,
|
|
404
|
+
this.meridienSelected
|
|
405
|
+
)
|
|
406
|
+
},
|
|
407
|
+
|
|
408
|
+
onMinutesChange(value) {
|
|
409
|
+
if (!this.secondsSelected && this.defaultSeconds) {
|
|
410
|
+
this.secondsSelected = this.defaultSeconds
|
|
411
|
+
}
|
|
412
|
+
this.updateDateSelected(
|
|
413
|
+
this.hoursSelected,
|
|
414
|
+
parseInt(value, 10),
|
|
415
|
+
this.enableSeconds ? this.secondsSelected : 0,
|
|
416
|
+
this.meridienSelected
|
|
417
|
+
)
|
|
418
|
+
},
|
|
419
|
+
|
|
420
|
+
onSecondsChange(value) {
|
|
421
|
+
this.updateDateSelected(
|
|
422
|
+
this.hoursSelected,
|
|
423
|
+
this.minutesSelected,
|
|
424
|
+
parseInt(value, 10),
|
|
425
|
+
this.meridienSelected
|
|
426
|
+
)
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
updateDateSelected(hours, minutes, seconds, meridiens) {
|
|
430
|
+
if (hours != null && minutes != null &&
|
|
431
|
+
((!this.isHourFormat24 && meridiens !== null) || this.isHourFormat24)) {
|
|
432
|
+
let time = null
|
|
433
|
+
if (this.computedValue && !isNaN(this.computedValue)) {
|
|
434
|
+
time = new Date(this.computedValue)
|
|
435
|
+
} else {
|
|
436
|
+
time = this.timeCreator()
|
|
437
|
+
time.setMilliseconds(0)
|
|
438
|
+
}
|
|
439
|
+
time.setHours(hours)
|
|
440
|
+
time.setMinutes(minutes)
|
|
441
|
+
time.setSeconds(seconds)
|
|
442
|
+
|
|
443
|
+
if (!isNaN(time.getTime())) this.computedValue = new Date(time.getTime())
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
|
|
447
|
+
updateInternalState(value) {
|
|
448
|
+
if (value) {
|
|
449
|
+
this.hoursSelected = value.getHours()
|
|
450
|
+
this.minutesSelected = value.getMinutes()
|
|
451
|
+
this.secondsSelected = value.getSeconds()
|
|
452
|
+
this.meridienSelected = value.getHours() >= 12 ? this.pmString : this.amString
|
|
453
|
+
} else {
|
|
454
|
+
this.hoursSelected = null
|
|
455
|
+
this.minutesSelected = null
|
|
456
|
+
this.secondsSelected = null
|
|
457
|
+
this.meridienSelected = this.amString
|
|
458
|
+
}
|
|
459
|
+
this.dateSelected = value
|
|
460
|
+
},
|
|
461
|
+
|
|
462
|
+
isHourDisabled(hour) {
|
|
463
|
+
let disabled = false
|
|
464
|
+
if (this.minTime) {
|
|
465
|
+
const minHours = this.minTime.getHours()
|
|
466
|
+
const noMinutesAvailable = this.minutes.every((minute) => {
|
|
467
|
+
return this.isMinuteDisabledForHour(hour, minute.value)
|
|
468
|
+
})
|
|
469
|
+
disabled = hour < minHours || noMinutesAvailable
|
|
470
|
+
}
|
|
471
|
+
if (this.maxTime) {
|
|
472
|
+
if (!disabled) {
|
|
473
|
+
const maxHours = this.maxTime.getHours()
|
|
474
|
+
disabled = hour > maxHours
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (this.unselectableTimes) {
|
|
478
|
+
if (!disabled) {
|
|
479
|
+
const unselectable = this.unselectableTimes.filter((time) => {
|
|
480
|
+
if (this.enableSeconds && this.secondsSelected !== null) {
|
|
481
|
+
return time.getHours() === hour &&
|
|
482
|
+
time.getMinutes() === this.minutesSelected &&
|
|
483
|
+
time.getSeconds() === this.secondsSelected
|
|
484
|
+
} else if (this.minutesSelected !== null) {
|
|
485
|
+
return time.getHours() === hour &&
|
|
486
|
+
time.getMinutes() === this.minutesSelected
|
|
487
|
+
}
|
|
488
|
+
return false
|
|
489
|
+
})
|
|
490
|
+
if (unselectable.length > 0) {
|
|
491
|
+
disabled = true
|
|
492
|
+
} else {
|
|
493
|
+
disabled = this.minutes.every((minute) => {
|
|
494
|
+
return this.unselectableTimes.filter((time) => {
|
|
495
|
+
return time.getHours() === hour &&
|
|
496
|
+
time.getMinutes() === minute.value
|
|
497
|
+
}).length > 0
|
|
498
|
+
})
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return disabled
|
|
503
|
+
},
|
|
504
|
+
|
|
505
|
+
isMinuteDisabledForHour(hour, minute) {
|
|
506
|
+
let disabled = false
|
|
507
|
+
if (this.minTime) {
|
|
508
|
+
const minHours = this.minTime.getHours()
|
|
509
|
+
const minMinutes = this.minTime.getMinutes()
|
|
510
|
+
disabled = hour === minHours && minute < minMinutes
|
|
511
|
+
}
|
|
512
|
+
if (this.maxTime) {
|
|
513
|
+
if (!disabled) {
|
|
514
|
+
const maxHours = this.maxTime.getHours()
|
|
515
|
+
const maxMinutes = this.maxTime.getMinutes()
|
|
516
|
+
disabled = hour === maxHours && minute > maxMinutes
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return disabled
|
|
521
|
+
},
|
|
522
|
+
|
|
523
|
+
isMinuteDisabled(minute) {
|
|
524
|
+
let disabled = false
|
|
525
|
+
if (this.hoursSelected !== null) {
|
|
526
|
+
if (this.isHourDisabled(this.hoursSelected)) {
|
|
527
|
+
disabled = true
|
|
528
|
+
} else {
|
|
529
|
+
disabled = this.isMinuteDisabledForHour(this.hoursSelected, minute)
|
|
530
|
+
}
|
|
531
|
+
if (this.unselectableTimes) {
|
|
532
|
+
if (!disabled) {
|
|
533
|
+
const unselectable = this.unselectableTimes.filter((time) => {
|
|
534
|
+
if (this.enableSeconds && this.secondsSelected !== null) {
|
|
535
|
+
return time.getHours() === this.hoursSelected &&
|
|
536
|
+
time.getMinutes() === minute &&
|
|
537
|
+
time.getSeconds() === this.secondsSelected
|
|
538
|
+
} else {
|
|
539
|
+
return time.getHours() === this.hoursSelected &&
|
|
540
|
+
time.getMinutes() === minute
|
|
541
|
+
}
|
|
542
|
+
})
|
|
543
|
+
disabled = unselectable.length > 0
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return disabled
|
|
548
|
+
},
|
|
549
|
+
|
|
550
|
+
isSecondDisabled(second) {
|
|
551
|
+
let disabled = false
|
|
552
|
+
if (this.minutesSelected !== null) {
|
|
553
|
+
if (this.isMinuteDisabled(this.minutesSelected)) {
|
|
554
|
+
disabled = true
|
|
555
|
+
} else {
|
|
556
|
+
if (this.minTime) {
|
|
557
|
+
const minHours = this.minTime.getHours()
|
|
558
|
+
const minMinutes = this.minTime.getMinutes()
|
|
559
|
+
const minSeconds = this.minTime.getSeconds()
|
|
560
|
+
disabled = this.hoursSelected === minHours &&
|
|
561
|
+
this.minutesSelected === minMinutes &&
|
|
562
|
+
second < minSeconds
|
|
563
|
+
}
|
|
564
|
+
if (this.maxTime) {
|
|
565
|
+
if (!disabled) {
|
|
566
|
+
const maxHours = this.maxTime.getHours()
|
|
567
|
+
const maxMinutes = this.maxTime.getMinutes()
|
|
568
|
+
const maxSeconds = this.maxTime.getSeconds()
|
|
569
|
+
disabled = this.hoursSelected === maxHours &&
|
|
570
|
+
this.minutesSelected === maxMinutes &&
|
|
571
|
+
second > maxSeconds
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (this.unselectableTimes) {
|
|
576
|
+
if (!disabled) {
|
|
577
|
+
const unselectable = this.unselectableTimes.filter((time) => {
|
|
578
|
+
return time.getHours() === this.hoursSelected &&
|
|
579
|
+
time.getMinutes() === this.minutesSelected &&
|
|
580
|
+
time.getSeconds() === second
|
|
581
|
+
})
|
|
582
|
+
disabled = unselectable.length > 0
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return disabled
|
|
587
|
+
},
|
|
588
|
+
|
|
589
|
+
/*
|
|
590
|
+
* Parse string into date
|
|
591
|
+
*/
|
|
592
|
+
onChange(value) {
|
|
593
|
+
const date = this.timeParser(value, this)
|
|
594
|
+
this.updateInternalState(date)
|
|
595
|
+
if (date && !isNaN(date)) {
|
|
596
|
+
this.computedValue = date
|
|
597
|
+
} else {
|
|
598
|
+
// Force refresh input value when not valid date
|
|
599
|
+
this.computedValue = null
|
|
600
|
+
this.$refs.input.newValue = this.computedValue
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
|
|
604
|
+
/*
|
|
605
|
+
* Toggle timepicker
|
|
606
|
+
*/
|
|
607
|
+
toggle(active) {
|
|
608
|
+
if (this.$refs.dropdown) {
|
|
609
|
+
this.$refs.dropdown.isActive = typeof active === 'boolean'
|
|
610
|
+
? active
|
|
611
|
+
: !this.$refs.dropdown.isActive
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
|
|
615
|
+
/*
|
|
616
|
+
* Close timepicker
|
|
617
|
+
*/
|
|
618
|
+
close() {
|
|
619
|
+
this.toggle(false)
|
|
620
|
+
},
|
|
621
|
+
|
|
622
|
+
/*
|
|
623
|
+
* Call default onFocus method and show timepicker
|
|
624
|
+
*/
|
|
625
|
+
handleOnFocus() {
|
|
626
|
+
this.onFocus()
|
|
627
|
+
if (this.openOnFocus) {
|
|
628
|
+
this.toggle(true)
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
|
|
632
|
+
/*
|
|
633
|
+
* Format date into string 'HH-MM-SS'
|
|
634
|
+
*/
|
|
635
|
+
formatHHMMSS(value) {
|
|
636
|
+
const date = new Date(value)
|
|
637
|
+
if (value && !isNaN(date)) {
|
|
638
|
+
const hours = date.getHours()
|
|
639
|
+
const minutes = date.getMinutes()
|
|
640
|
+
const seconds = date.getSeconds()
|
|
641
|
+
return this.formatNumber(hours, true) + ':' +
|
|
642
|
+
this.formatNumber(minutes, true) + ':' +
|
|
643
|
+
this.formatNumber(seconds, true)
|
|
644
|
+
}
|
|
645
|
+
return ''
|
|
646
|
+
},
|
|
647
|
+
|
|
648
|
+
/*
|
|
649
|
+
* Parse time from string
|
|
650
|
+
*/
|
|
651
|
+
onChangeNativePicker(event) {
|
|
652
|
+
const date = event.target.value
|
|
653
|
+
if (date) {
|
|
654
|
+
let time = null
|
|
655
|
+
if (this.computedValue && !isNaN(this.computedValue)) {
|
|
656
|
+
time = new Date(this.computedValue)
|
|
657
|
+
} else {
|
|
658
|
+
time = new Date()
|
|
659
|
+
time.setMilliseconds(0)
|
|
660
|
+
}
|
|
661
|
+
const t = date.split(':')
|
|
662
|
+
time.setHours(parseInt(t[0], 10))
|
|
663
|
+
time.setMinutes(parseInt(t[1], 10))
|
|
664
|
+
time.setSeconds(t[2] ? parseInt(t[2], 10) : 0)
|
|
665
|
+
this.computedValue = new Date(time.getTime())
|
|
666
|
+
} else {
|
|
667
|
+
this.computedValue = null
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
|
|
671
|
+
formatNumber(value, prependZero) {
|
|
672
|
+
return this.isHourFormat24 || prependZero
|
|
673
|
+
? this.pad(value)
|
|
674
|
+
: value
|
|
675
|
+
},
|
|
676
|
+
|
|
677
|
+
pad(value) {
|
|
678
|
+
return (value < 10 ? '0' : '') + value
|
|
679
|
+
},
|
|
680
|
+
|
|
681
|
+
/*
|
|
682
|
+
* Format date into string
|
|
683
|
+
*/
|
|
684
|
+
formatValue(date) {
|
|
685
|
+
if (date && !isNaN(date)) {
|
|
686
|
+
return this.timeFormatter(date, this)
|
|
687
|
+
} else {
|
|
688
|
+
return null
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
/**
|
|
692
|
+
* Keypress event that is bound to the document.
|
|
693
|
+
*/
|
|
694
|
+
keyPress({ key }) {
|
|
695
|
+
if (this.$refs.dropdown && this.$refs.dropdown.isActive && (key === 'Escape' || key === 'Esc')) {
|
|
696
|
+
this.toggle(false)
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
/**
|
|
700
|
+
* Emit 'blur' event on dropdown is not active (closed)
|
|
701
|
+
*/
|
|
702
|
+
onActiveChange(value) {
|
|
703
|
+
if (!value) {
|
|
704
|
+
this.onBlur()
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
created() {
|
|
709
|
+
if (typeof window !== 'undefined') {
|
|
710
|
+
document.addEventListener('keyup', this.keyPress)
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
beforeDestroy() {
|
|
714
|
+
if (typeof window !== 'undefined') {
|
|
715
|
+
document.removeEventListener('keyup', this.keyPress)
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|