@94ai/nf-timezone-picker 5.0.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 (41) hide show
  1. package/.eslintrc.cjs +49 -0
  2. package/README.md +17 -0
  3. package/components.d.ts +8 -0
  4. package/lib/basic/date-table.vue.d.ts +86 -0
  5. package/lib/basic/month-table.vue.d.ts +51 -0
  6. package/lib/basic/time-spinner.vue.d.ts +42 -0
  7. package/lib/basic/year-table.vue.d.ts +26 -0
  8. package/lib/index.d.ts +333 -0
  9. package/lib/nf-timezone-picker.cjs.js +5984 -0
  10. package/lib/nf-timezone-picker.esm-bundler.js +5984 -0
  11. package/lib/nf-timezone-picker.vue.d.ts +157 -0
  12. package/lib/panel/date-range.vue.d.ts +55 -0
  13. package/lib/panel/date.vue.d.ts +35 -0
  14. package/lib/panel/month-range.vue.d.ts +30 -0
  15. package/lib/panel/time.vue.d.ts +27 -0
  16. package/lib/picker.vue.d.ts +142 -0
  17. package/lib/style/css.d.ts +1 -0
  18. package/lib/style/css.js +1 -0
  19. package/lib/style/index.d.ts +1 -0
  20. package/lib/style/index.js +1 -0
  21. package/package/basic/date-table.vue +448 -0
  22. package/package/basic/month-table.vue +253 -0
  23. package/package/basic/time-spinner.vue +316 -0
  24. package/package/basic/year-table.vue +101 -0
  25. package/package/index.ts +7 -0
  26. package/package/nf-timezone-picker.vue +50 -0
  27. package/package/panel/date-range.vue +700 -0
  28. package/package/panel/date.vue +607 -0
  29. package/package/panel/month-range.vue +293 -0
  30. package/package/panel/time-range.vue +254 -0
  31. package/package/panel/time-select.vue +178 -0
  32. package/package/panel/time.vue +189 -0
  33. package/package/picker/date-picker.js +43 -0
  34. package/package/picker/time-picker.js +39 -0
  35. package/package/picker/time-select.js +21 -0
  36. package/package/picker.vue +943 -0
  37. package/package/popper.js +1276 -0
  38. package/package/style/css.ts +1 -0
  39. package/package/style/index.ts +1 -0
  40. package/package.json +34 -0
  41. package/postcss.config.js +8 -0
@@ -0,0 +1,607 @@
1
+ <template>
2
+ <transition name="el-zoom-in-top" @after-enter="handleEnter" @after-leave="handleLeave">
3
+ <div
4
+ v-show="visible"
5
+ class="el-picker-panel el-date-picker el-popper"
6
+ :class="[{
7
+ 'has-sidebar': $slots.sidebar || shortcuts,
8
+ 'has-time': showTime
9
+ }, popperClass]"
10
+ >
11
+ <div class="el-picker-panel__body-wrapper">
12
+ <slot name="sidebar" class="el-picker-panel__sidebar" />
13
+ <div v-if="shortcuts" class="el-picker-panel__sidebar">
14
+ <button
15
+ v-for="(shortcut, key) in shortcuts"
16
+ :key="key"
17
+ type="button"
18
+ class="el-picker-panel__shortcut"
19
+ @click="handleShortcutClick(shortcut)"
20
+ >{{ shortcut.text }}</button>
21
+ </div>
22
+ <div class="el-picker-panel__body">
23
+ <div v-if="showTime" class="el-date-picker__time-header">
24
+ <span class="el-date-picker__editor-wrap">
25
+ <el-input
26
+ :placeholder="t('el.datepicker.selectDate')"
27
+ :value="visibleDate"
28
+ size="small"
29
+ @input="val => userInputDate = val"
30
+ @change="handleVisibleDateChange"
31
+ />
32
+ </span>
33
+ <span v-clickoutside="handleTimePickClose" class="el-date-picker__editor-wrap">
34
+ <el-input
35
+ ref="input"
36
+ :placeholder="t('el.datepicker.selectTime')"
37
+ :value="visibleTime"
38
+ size="small"
39
+ @focus="timePickerVisible = true"
40
+ @input="val => userInputTime = val"
41
+ @change="handleVisibleTimeChange"
42
+ />
43
+ <time-picker
44
+ ref="timepicker"
45
+ :time-arrow-control="arrowControl"
46
+ :visible="timePickerVisible"
47
+ @pick="handleTimePick"
48
+ @mounted="proxyTimePickerDataProperties"
49
+ />
50
+ </span>
51
+ </div>
52
+ <div
53
+ v-show="currentView !== 'time'"
54
+ class="el-date-picker__header"
55
+ :class="{ 'el-date-picker__header--bordered': currentView === 'year' || currentView === 'month' }"
56
+ >
57
+ <button
58
+ type="button"
59
+ :aria-label="t(`el.datepicker.prevYear`)"
60
+ class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-d-arrow-left"
61
+ @click="prevYear"
62
+ />
63
+ <button
64
+ v-show="currentView === 'date'"
65
+ type="button"
66
+ :aria-label="t(`el.datepicker.prevMonth`)"
67
+ class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-arrow-left"
68
+ @click="prevMonth"
69
+ />
70
+ <span
71
+ role="button"
72
+ class="el-date-picker__header-label"
73
+ @click="showYearPicker"
74
+ >{{ yearLabel }}</span>
75
+ <span
76
+ v-show="currentView === 'date'"
77
+ role="button"
78
+ class="el-date-picker__header-label"
79
+ :class="{ active: currentView === 'month' }"
80
+ @click="showMonthPicker"
81
+ >{{ t(`el.datepicker.month${ month + 1 }`) }}</span>
82
+ <button
83
+ type="button"
84
+ :aria-label="t(`el.datepicker.nextYear`)"
85
+ class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-d-arrow-right"
86
+ @click="nextYear"
87
+ />
88
+ <button
89
+ v-show="currentView === 'date'"
90
+ type="button"
91
+ :aria-label="t(`el.datepicker.nextMonth`)"
92
+ class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-arrow-right"
93
+ @click="nextMonth"
94
+ />
95
+ </div>
96
+
97
+ <div class="el-picker-panel__content">
98
+ <date-table
99
+ v-show="currentView === 'date'"
100
+ :selection-mode="selectionMode"
101
+ :first-day-of-week="firstDayOfWeek"
102
+ :value="value"
103
+ :default-value="defaultValue ? new Date(defaultValue) : null"
104
+ :date="date"
105
+ :cell-class-name="cellClassName"
106
+ :disabled-date="disabledDate"
107
+ :timezone="timezone"
108
+ @pick="handleDatePick"
109
+ />
110
+ <year-table
111
+ v-show="currentView === 'year'"
112
+ :value="value"
113
+ :default-value="defaultValue ? new Date(defaultValue) : null"
114
+ :date="date"
115
+ :disabled-date="disabledDate"
116
+ @pick="handleYearPick"
117
+ />
118
+ <month-table
119
+ v-show="currentView === 'month'"
120
+ :value="value"
121
+ :default-value="defaultValue ? new Date(defaultValue) : null"
122
+ :date="date"
123
+ :disabled-date="disabledDate"
124
+ @pick="handleMonthPick"
125
+ />
126
+ </div>
127
+ </div>
128
+ </div>
129
+
130
+ <div
131
+ v-show="footerVisible && currentView === 'date'"
132
+ class="el-picker-panel__footer"
133
+ >
134
+ <el-button
135
+ v-show="selectionMode !== 'dates'"
136
+ size="mini"
137
+ type="text"
138
+ class="el-picker-panel__link-btn"
139
+ @click="changeToNow"
140
+ >
141
+ {{ t('el.datepicker.now') }}
142
+ </el-button>
143
+ <el-button
144
+ plain
145
+ size="mini"
146
+ class="el-picker-panel__link-btn"
147
+ @click="confirm"
148
+ >
149
+ {{ t('el.datepicker.confirm') }}
150
+ </el-button>
151
+ </div>
152
+ </div>
153
+ </transition>
154
+ </template>
155
+
156
+ <script type="text/babel">
157
+ import {
158
+ formatDate,
159
+ parseDate,
160
+ getWeekNumber,
161
+ isDate,
162
+ modifyDate,
163
+ modifyTime,
164
+ modifyWithTimeString,
165
+ clearMilliseconds,
166
+ clearTime,
167
+ prevYear,
168
+ nextYear,
169
+ prevMonth,
170
+ nextMonth,
171
+ changeYearMonthAndClampDate,
172
+ extractDateFormat,
173
+ extractTimeFormat,
174
+ timeWithinRange
175
+ } from 'element-ui/src/utils/date-util'
176
+ import Clickoutside from 'element-ui/src/utils/clickoutside'
177
+ import Locale from 'element-ui/src/mixins/locale'
178
+ import TimePicker from './time.vue'
179
+ import YearTable from '../basic/year-table.vue'
180
+ import MonthTable from '../basic/month-table.vue'
181
+ import DateTable from '../basic/date-table.vue'
182
+
183
+ export default {
184
+
185
+ directives: { Clickoutside },
186
+
187
+ components: {
188
+ TimePicker, YearTable, MonthTable, DateTable
189
+ },
190
+ mixins: [Locale],
191
+
192
+ data() {
193
+ return {
194
+ timezone: '',
195
+ popperClass: '',
196
+ date: new Date(),
197
+ value: '',
198
+ defaultValue: null, // use getDefaultValue() for time computation
199
+ defaultTime: null,
200
+ showTime: false,
201
+ selectionMode: 'day',
202
+ shortcuts: '',
203
+ visible: false,
204
+ currentView: 'date',
205
+ disabledDate: '',
206
+ cellClassName: '',
207
+ selectableRange: [],
208
+ firstDayOfWeek: 7,
209
+ showWeekNumber: false,
210
+ timePickerVisible: false,
211
+ format: '',
212
+ arrowControl: false,
213
+ userInputDate: null,
214
+ userInputTime: null
215
+ }
216
+ },
217
+
218
+ computed: {
219
+ year() {
220
+ return this.date.getFullYear()
221
+ },
222
+
223
+ month() {
224
+ return this.date.getMonth()
225
+ },
226
+
227
+ week() {
228
+ return getWeekNumber(this.date)
229
+ },
230
+
231
+ monthDate() {
232
+ return this.date.getDate()
233
+ },
234
+
235
+ footerVisible() {
236
+ return this.showTime || this.selectionMode === 'dates'
237
+ },
238
+
239
+ visibleTime() {
240
+ if (this.userInputTime !== null) {
241
+ return this.userInputTime
242
+ } else {
243
+ return formatDate(this.value || this.defaultValue, this.timeFormat)
244
+ }
245
+ },
246
+
247
+ visibleDate() {
248
+ if (this.userInputDate !== null) {
249
+ return this.userInputDate
250
+ } else {
251
+ return formatDate(this.value || this.defaultValue, this.dateFormat)
252
+ }
253
+ },
254
+
255
+ yearLabel() {
256
+ const yearTranslation = this.t('el.datepicker.year')
257
+ if (this.currentView === 'year') {
258
+ const startYear = Math.floor(this.year / 10) * 10
259
+ if (yearTranslation) {
260
+ return startYear + ' ' + yearTranslation + ' - ' + (startYear + 9) + ' ' + yearTranslation
261
+ }
262
+ return startYear + ' - ' + (startYear + 9)
263
+ }
264
+ return this.year + ' ' + yearTranslation
265
+ },
266
+
267
+ timeFormat() {
268
+ if (this.format) {
269
+ return extractTimeFormat(this.format)
270
+ } else {
271
+ return 'HH:mm:ss'
272
+ }
273
+ },
274
+
275
+ dateFormat() {
276
+ if (this.format) {
277
+ return extractDateFormat(this.format)
278
+ } else {
279
+ return 'yyyy-MM-dd'
280
+ }
281
+ }
282
+ },
283
+
284
+ watch: {
285
+ showTime(val) {
286
+ /* istanbul ignore if */
287
+ if (!val) return
288
+ this.$nextTick(_ => {
289
+ const inputElm = this.$refs.input.$el
290
+ if (inputElm) {
291
+ this.pickerWidth = inputElm.getBoundingClientRect().width + 10
292
+ }
293
+ })
294
+ },
295
+
296
+ value(val) {
297
+ if (this.selectionMode === 'dates' && this.value) return
298
+ if (isDate(val)) {
299
+ this.date = new Date(val)
300
+ } else {
301
+ this.date = this.getDefaultValue()
302
+ }
303
+ },
304
+
305
+ defaultValue(val) {
306
+ if (!isDate(this.value)) {
307
+ this.date = val ? new Date(val) : new Date()
308
+ }
309
+ },
310
+
311
+ timePickerVisible(val) {
312
+ if (val) this.$nextTick(() => this.$refs.timepicker.adjustSpinners())
313
+ },
314
+
315
+ selectionMode(newVal) {
316
+ if (newVal === 'month') {
317
+ /* istanbul ignore next */
318
+ if (this.currentView !== 'year' || this.currentView !== 'month') {
319
+ this.currentView = 'month'
320
+ }
321
+ } else if (newVal === 'dates') {
322
+ this.currentView = 'date'
323
+ }
324
+ }
325
+ },
326
+
327
+ methods: {
328
+ proxyTimePickerDataProperties() {
329
+ const format = timeFormat => { this.$refs.timepicker.format = timeFormat }
330
+ const value = value => { this.$refs.timepicker.value = value }
331
+ const date = date => { this.$refs.timepicker.date = date }
332
+ const selectableRange = selectableRange => { this.$refs.timepicker.selectableRange = selectableRange }
333
+
334
+ this.$watch('value', value)
335
+ this.$watch('date', date)
336
+ this.$watch('selectableRange', selectableRange)
337
+
338
+ format(this.timeFormat)
339
+ value(this.value)
340
+ date(this.date)
341
+ selectableRange(this.selectableRange)
342
+ },
343
+
344
+ handleClear() {
345
+ this.date = this.getDefaultValue()
346
+ this.$emit('pick', null)
347
+ },
348
+
349
+ emit(value, ...args) {
350
+ if (!value) {
351
+ this.$emit('pick', value, ...args)
352
+ } else if (Array.isArray(value)) {
353
+ const dates = value.map(date => this.showTime ? clearMilliseconds(date) : clearTime(date))
354
+ this.$emit('pick', dates, ...args)
355
+ } else {
356
+ this.$emit('pick', this.showTime ? clearMilliseconds(value) : clearTime(value), ...args)
357
+ }
358
+ this.userInputDate = null
359
+ this.userInputTime = null
360
+ },
361
+
362
+ // resetDate() {
363
+ // this.date = new Date(this.date);
364
+ // },
365
+
366
+ showMonthPicker() {
367
+ this.currentView = 'month'
368
+ },
369
+
370
+ showYearPicker() {
371
+ this.currentView = 'year'
372
+ },
373
+
374
+ // XXX: 没用到
375
+ // handleLabelClick() {
376
+ // if (this.currentView === 'date') {
377
+ // this.showMonthPicker();
378
+ // } else if (this.currentView === 'month') {
379
+ // this.showYearPicker();
380
+ // }
381
+ // },
382
+
383
+ prevMonth() {
384
+ this.date = prevMonth(this.date)
385
+ },
386
+
387
+ nextMonth() {
388
+ this.date = nextMonth(this.date)
389
+ },
390
+
391
+ prevYear() {
392
+ if (this.currentView === 'year') {
393
+ this.date = prevYear(this.date, 10)
394
+ } else {
395
+ this.date = prevYear(this.date)
396
+ }
397
+ },
398
+
399
+ nextYear() {
400
+ if (this.currentView === 'year') {
401
+ this.date = nextYear(this.date, 10)
402
+ } else {
403
+ this.date = nextYear(this.date)
404
+ }
405
+ },
406
+
407
+ handleShortcutClick(shortcut) {
408
+ if (shortcut.onClick) {
409
+ shortcut.onClick(this)
410
+ }
411
+ },
412
+
413
+ handleTimePick(value, visible, first) {
414
+ if (isDate(value)) {
415
+ const newDate = this.value
416
+ ? modifyTime(this.value, value.getHours(), value.getMinutes(), value.getSeconds())
417
+ : modifyWithTimeString(this.getDefaultValue(), this.defaultTime)
418
+ this.date = newDate
419
+ this.emit(this.date, true)
420
+ } else {
421
+ this.emit(value, true)
422
+ }
423
+ if (!first) {
424
+ this.timePickerVisible = visible
425
+ }
426
+ },
427
+
428
+ handleTimePickClose() {
429
+ this.timePickerVisible = false
430
+ },
431
+
432
+ handleMonthPick(month) {
433
+ if (this.selectionMode === 'month') {
434
+ this.date = modifyDate(this.date, this.year, month, 1)
435
+ this.emit(this.date)
436
+ } else {
437
+ this.date = changeYearMonthAndClampDate(this.date, this.year, month)
438
+ // TODO: should emit intermediate value ??
439
+ // this.emit(this.date);
440
+ this.currentView = 'date'
441
+ }
442
+ },
443
+
444
+ handleDatePick(value) {
445
+ if (this.selectionMode === 'day') {
446
+ let newDate = this.value
447
+ ? modifyDate(this.value, value.getFullYear(), value.getMonth(), value.getDate())
448
+ : modifyWithTimeString(value, this.defaultTime)
449
+ // change default time while out of selectableRange
450
+ if (!this.checkDateWithinRange(newDate)) {
451
+ newDate = modifyDate(this.selectableRange[0][0], value.getFullYear(), value.getMonth(), value.getDate())
452
+ }
453
+ this.date = newDate
454
+ this.emit(this.date, this.showTime)
455
+ } else if (this.selectionMode === 'week') {
456
+ this.emit(value.date)
457
+ } else if (this.selectionMode === 'dates') {
458
+ this.emit(value, true) // set false to keep panel open
459
+ }
460
+ },
461
+
462
+ handleYearPick(year) {
463
+ if (this.selectionMode === 'year') {
464
+ this.date = modifyDate(this.date, year, 0, 1)
465
+ this.emit(this.date)
466
+ } else {
467
+ this.date = changeYearMonthAndClampDate(this.date, year, this.month)
468
+ // TODO: should emit intermediate value ??
469
+ // this.emit(this.date, true);
470
+ this.currentView = 'month'
471
+ }
472
+ },
473
+
474
+ changeToNow() {
475
+ // NOTE: not a permanent solution
476
+ // consider disable "now" button in the future
477
+ if ((!this.disabledDate || !this.disabledDate(new Date())) && this.checkDateWithinRange(new Date())) {
478
+ this.date = new Date()
479
+ this.emit(this.date)
480
+ }
481
+ },
482
+
483
+ confirm() {
484
+ if (this.selectionMode === 'dates') {
485
+ this.emit(this.value)
486
+ } else {
487
+ // value were emitted in handle{Date,Time}Pick, nothing to update here
488
+ // deal with the scenario where: user opens the picker, then confirm without doing anything
489
+ const value = this.value
490
+ ? this.value
491
+ : modifyWithTimeString(this.getDefaultValue(), this.defaultTime)
492
+ this.date = new Date(value) // refresh date
493
+ this.emit(value)
494
+ }
495
+ },
496
+
497
+ resetView() {
498
+ if (this.selectionMode === 'month') {
499
+ this.currentView = 'month'
500
+ } else if (this.selectionMode === 'year') {
501
+ this.currentView = 'year'
502
+ } else {
503
+ this.currentView = 'date'
504
+ }
505
+ },
506
+
507
+ handleEnter() {
508
+ document.body.addEventListener('keydown', this.handleKeydown)
509
+ },
510
+
511
+ handleLeave() {
512
+ this.$emit('dodestroy')
513
+ document.body.removeEventListener('keydown', this.handleKeydown)
514
+ },
515
+
516
+ handleKeydown(event) {
517
+ const keyCode = event.keyCode
518
+ const list = [38, 40, 37, 39]
519
+ if (this.visible && !this.timePickerVisible) {
520
+ if (list.indexOf(keyCode) !== -1) {
521
+ this.handleKeyControl(keyCode)
522
+ event.stopPropagation()
523
+ event.preventDefault()
524
+ }
525
+ if (keyCode === 13 && this.userInputDate === null && this.userInputTime === null) { // Enter
526
+ this.emit(this.date, false)
527
+ }
528
+ }
529
+ },
530
+
531
+ handleKeyControl(keyCode) {
532
+ const mapping = {
533
+ 'year': {
534
+ 38: -4, 40: 4, 37: -1, 39: 1, offset: (date, step) => date.setFullYear(date.getFullYear() + step)
535
+ },
536
+ 'month': {
537
+ 38: -4, 40: 4, 37: -1, 39: 1, offset: (date, step) => date.setMonth(date.getMonth() + step)
538
+ },
539
+ 'week': {
540
+ 38: -1, 40: 1, 37: -1, 39: 1, offset: (date, step) => date.setDate(date.getDate() + step * 7)
541
+ },
542
+ 'day': {
543
+ 38: -7, 40: 7, 37: -1, 39: 1, offset: (date, step) => date.setDate(date.getDate() + step)
544
+ }
545
+ }
546
+ const mode = this.selectionMode
547
+ const year = 3.1536e10
548
+ const now = this.date.getTime()
549
+ const newDate = new Date(this.date.getTime())
550
+ while (Math.abs(now - newDate.getTime()) <= year) {
551
+ const map = mapping[mode]
552
+ map.offset(newDate, map[keyCode])
553
+ if (typeof this.disabledDate === 'function' && this.disabledDate(newDate)) {
554
+ continue
555
+ }
556
+ this.date = newDate
557
+ this.$emit('pick', newDate, true)
558
+ break
559
+ }
560
+ },
561
+
562
+ handleVisibleTimeChange(value) {
563
+ const time = parseDate(value, this.timeFormat)
564
+ if (time && this.checkDateWithinRange(time)) {
565
+ this.date = modifyDate(time, this.year, this.month, this.monthDate)
566
+ this.userInputTime = null
567
+ this.$refs.timepicker.value = this.date
568
+ this.timePickerVisible = false
569
+ this.emit(this.date, true)
570
+ }
571
+ },
572
+
573
+ handleVisibleDateChange(value) {
574
+ const date = parseDate(value, this.dateFormat)
575
+ if (date) {
576
+ if (typeof this.disabledDate === 'function' && this.disabledDate(date)) {
577
+ return
578
+ }
579
+ this.date = modifyTime(date, this.date.getHours(), this.date.getMinutes(), this.date.getSeconds())
580
+ this.userInputDate = null
581
+ this.resetView()
582
+ this.emit(this.date, true)
583
+ }
584
+ },
585
+
586
+ isValidValue(value) {
587
+ return value && !isNaN(value) && (
588
+ typeof this.disabledDate === 'function'
589
+ ? !this.disabledDate(value)
590
+ : true
591
+ ) && this.checkDateWithinRange(value)
592
+ },
593
+
594
+ getDefaultValue() {
595
+ // if default-value is set, return it
596
+ // otherwise, return now (the moment this method gets called)
597
+ return this.defaultValue ? new Date(this.defaultValue) : new Date()
598
+ },
599
+
600
+ checkDateWithinRange(date) {
601
+ return this.selectableRange.length > 0
602
+ ? timeWithinRange(date, this.selectableRange, this.format || 'HH:mm:ss')
603
+ : true
604
+ }
605
+ }
606
+ }
607
+ </script>