@94ai/nf-timezone-picker 5.0.6 → 5.0.11

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.
@@ -36,7 +36,7 @@
36
36
 
37
37
  <script>
38
38
  import { getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, prevDate, nextDate, isDate, clearTime as _clearTime } from 'element-ui/src/utils/date-util'
39
- import Locale from 'element-ui/src/mixins/locale'
39
+ import Locale from 'element-ui/lib/mixins/locale'
40
40
  import { arrayFindIndex, arrayFind, coerceTruthyValueToArray } from 'element-ui/src/utils/util'
41
41
  import { getLocalTime } from '@94ai/common-utils/lib/util'
42
42
  const WEEKS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
@@ -1,253 +1,253 @@
1
- <template>
2
- <table class="el-month-table" @click="handleMonthTableClick" @mousemove="handleMouseMove">
3
- <tbody>
4
- <tr v-for="(row, key) in rows" :key="key">
5
- <td v-for="(cell, key) in row" :key="key" :class="getCellStyle(cell)">
6
- <div>
7
- <a class="cell">{{ t('el.datepicker.months.' + months[cell.text]) }}</a>
8
- </div>
9
- </td>
10
- </tr>
11
- </tbody>
12
- </table>
13
- </template>
14
-
15
- <script type="text/babel">
16
- import Locale from 'element-ui/src/mixins/locale'
17
- import { isDate, range, getDayCountOfMonth, nextDate } from 'element-ui/src/utils/date-util'
18
- import { hasClass } from 'element-ui/src/utils/dom'
19
- import { arrayFindIndex, coerceTruthyValueToArray, arrayFind } from 'element-ui/src/utils/util'
20
-
21
- const datesInMonth = (year, month) => {
22
- const numOfDays = getDayCountOfMonth(year, month)
23
- const firstDay = new Date(year, month, 1)
24
- return range(numOfDays).map(n => nextDate(firstDay, n))
25
- }
26
-
27
- const clearDate = (date) => {
28
- return new Date(date.getFullYear(), date.getMonth())
29
- }
30
-
31
- const getMonthTimestamp = function(time) {
32
- if (typeof time === 'number' || typeof time === 'string') {
33
- return clearDate(new Date(time)).getTime()
34
- } else if (time instanceof Date) {
35
- return clearDate(time).getTime()
36
- } else {
37
- return NaN
38
- }
39
- }
40
- export default {
41
-
42
- mixins: [Locale],
43
- props: {
44
- disabledDate: {},
45
- value: {},
46
- selectionMode: {
47
- default: 'month'
48
- },
49
- minDate: {},
50
-
51
- maxDate: {},
52
- defaultValue: {
53
- validator(val) {
54
- // null or valid Date Object
55
- return val === null || isDate(val) || (Array.isArray(val) && val.every(isDate))
56
- }
57
- },
58
- date: {},
59
- rangeState: {
60
- default() {
61
- return {
62
- endDate: null,
63
- selecting: false
64
- }
65
- }
66
- }
67
- },
68
-
69
- data() {
70
- return {
71
- months: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'],
72
- tableRows: [[], [], []],
73
- lastRow: null,
74
- lastColumn: null
75
- }
76
- },
77
-
78
- computed: {
79
- rows() {
80
- // TODO: refactory rows / getCellClasses
81
- const rows = this.tableRows
82
- const disabledDate = this.disabledDate
83
- const selectedDate = []
84
- const now = getMonthTimestamp(new Date())
85
-
86
- for (let i = 0; i < 3; i++) {
87
- const row = rows[i]
88
- for (let j = 0; j < 4; j++) {
89
- let cell = row[j]
90
- if (!cell) {
91
- cell = { row: i, column: j, type: 'normal', inRange: false, start: false, end: false }
92
- }
93
-
94
- cell.type = 'normal'
95
-
96
- const index = i * 4 + j
97
- const time = new Date(this.date.getFullYear(), index).getTime()
98
- cell.inRange = time >= getMonthTimestamp(this.minDate) && time <= getMonthTimestamp(this.maxDate)
99
- cell.start = this.minDate && time === getMonthTimestamp(this.minDate)
100
- cell.end = this.maxDate && time === getMonthTimestamp(this.maxDate)
101
- const isToday = time === now
102
-
103
- if (isToday) {
104
- cell.type = 'today'
105
- }
106
- cell.text = index
107
- const cellDate = new Date(time)
108
- cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate)
109
- cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime())
110
-
111
- this.$set(row, j, cell)
112
- }
113
- }
114
- return rows
115
- }
116
- },
117
-
118
- watch: {
119
- 'rangeState.endDate'(newVal) {
120
- this.markRange(this.minDate, newVal)
121
- },
122
-
123
- minDate(newVal, oldVal) {
124
- if (getMonthTimestamp(newVal) !== getMonthTimestamp(oldVal)) {
125
- this.markRange(this.minDate, this.maxDate)
126
- }
127
- },
128
-
129
- maxDate(newVal, oldVal) {
130
- if (getMonthTimestamp(newVal) !== getMonthTimestamp(oldVal)) {
131
- this.markRange(this.minDate, this.maxDate)
132
- }
133
- }
134
- },
135
-
136
- methods: {
137
- cellMatchesDate(cell, date) {
138
- const value = new Date(date)
139
- return this.date.getFullYear() === value.getFullYear() && Number(cell.text) === value.getMonth()
140
- },
141
- getCellStyle(cell) {
142
- const style = {}
143
- const year = this.date.getFullYear()
144
- const today = new Date()
145
- const month = cell.text
146
- const defaultValue = this.defaultValue ? Array.isArray(this.defaultValue) ? this.defaultValue : [this.defaultValue] : []
147
- style.disabled = typeof this.disabledDate === 'function'
148
- ? datesInMonth(year, month).every(this.disabledDate)
149
- : false
150
- style.current = arrayFindIndex(coerceTruthyValueToArray(this.value), date => date.getFullYear() === year && date.getMonth() === month) >= 0
151
- style.today = today.getFullYear() === year && today.getMonth() === month
152
- style.default = defaultValue.some(date => this.cellMatchesDate(cell, date))
153
-
154
- if (cell.inRange) {
155
- style['in-range'] = true
156
-
157
- if (cell.start) {
158
- style['start-date'] = true
159
- }
160
-
161
- if (cell.end) {
162
- style['end-date'] = true
163
- }
164
- }
165
- return style
166
- },
167
- getMonthOfCell(month) {
168
- const year = this.date.getFullYear()
169
- return new Date(year, month, 1)
170
- },
171
- markRange(minDate, maxDate) {
172
- minDate = getMonthTimestamp(minDate)
173
- maxDate = getMonthTimestamp(maxDate) || minDate;
174
- [minDate, maxDate] = [Math.min(minDate, maxDate), Math.max(minDate, maxDate)]
175
- const rows = this.rows
176
- for (let i = 0, k = rows.length; i < k; i++) {
177
- const row = rows[i]
178
- for (let j = 0, l = row.length; j < l; j++) {
179
- const cell = row[j]
180
- const index = i * 4 + j
181
- const time = new Date(this.date.getFullYear(), index).getTime()
182
-
183
- cell.inRange = minDate && time >= minDate && time <= maxDate
184
- cell.start = minDate && time === minDate
185
- cell.end = maxDate && time === maxDate
186
- }
187
- }
188
- },
189
- handleMouseMove(event) {
190
- if (!this.rangeState.selecting) return
191
-
192
- let target = event.target
193
- if (target.tagName === 'A') {
194
- target = target.parentNode.parentNode
195
- }
196
- if (target.tagName === 'DIV') {
197
- target = target.parentNode
198
- }
199
- if (target.tagName !== 'TD') return
200
-
201
- const row = target.parentNode.rowIndex
202
- const column = target.cellIndex
203
- // can not select disabled date
204
- if (this.rows[row][column].disabled) return
205
-
206
- // only update rangeState when mouse moves to a new cell
207
- // this avoids frequent Date object creation and improves performance
208
- if (row !== this.lastRow || column !== this.lastColumn) {
209
- this.lastRow = row
210
- this.lastColumn = column
211
- this.$emit('changerange', {
212
- minDate: this.minDate,
213
- maxDate: this.maxDate,
214
- rangeState: {
215
- selecting: true,
216
- endDate: this.getMonthOfCell(row * 4 + column)
217
- }
218
- })
219
- }
220
- },
221
- handleMonthTableClick(event) {
222
- let target = event.target
223
- if (target.tagName === 'A') {
224
- target = target.parentNode.parentNode
225
- }
226
- if (target.tagName === 'DIV') {
227
- target = target.parentNode
228
- }
229
- if (target.tagName !== 'TD') return
230
- if (hasClass(target, 'disabled')) return
231
- const column = target.cellIndex
232
- const row = target.parentNode.rowIndex
233
- const month = row * 4 + column
234
- const newDate = this.getMonthOfCell(month)
235
- if (this.selectionMode === 'range') {
236
- if (!this.rangeState.selecting) {
237
- this.$emit('pick', { minDate: newDate, maxDate: null })
238
- this.rangeState.selecting = true
239
- } else {
240
- if (newDate >= this.minDate) {
241
- this.$emit('pick', { minDate: this.minDate, maxDate: newDate })
242
- } else {
243
- this.$emit('pick', { minDate: newDate, maxDate: this.minDate })
244
- }
245
- this.rangeState.selecting = false
246
- }
247
- } else {
248
- this.$emit('pick', month)
249
- }
250
- }
251
- }
252
- }
253
- </script>
1
+ <template>
2
+ <table class="el-month-table" @click="handleMonthTableClick" @mousemove="handleMouseMove">
3
+ <tbody>
4
+ <tr v-for="(row, key) in rows" :key="key">
5
+ <td v-for="(cell, key) in row" :key="key" :class="getCellStyle(cell)">
6
+ <div>
7
+ <a class="cell">{{ t('el.datepicker.months.' + months[cell.text]) }}</a>
8
+ </div>
9
+ </td>
10
+ </tr>
11
+ </tbody>
12
+ </table>
13
+ </template>
14
+
15
+ <script type="text/babel">
16
+ import Locale from 'element-ui/lib/mixins/locale'
17
+ import { isDate, range, getDayCountOfMonth, nextDate } from 'element-ui/src/utils/date-util'
18
+ import { hasClass } from 'element-ui/src/utils/dom'
19
+ import { arrayFindIndex, coerceTruthyValueToArray, arrayFind } from 'element-ui/src/utils/util'
20
+
21
+ const datesInMonth = (year, month) => {
22
+ const numOfDays = getDayCountOfMonth(year, month)
23
+ const firstDay = new Date(year, month, 1)
24
+ return range(numOfDays).map(n => nextDate(firstDay, n))
25
+ }
26
+
27
+ const clearDate = (date) => {
28
+ return new Date(date.getFullYear(), date.getMonth())
29
+ }
30
+
31
+ const getMonthTimestamp = function(time) {
32
+ if (typeof time === 'number' || typeof time === 'string') {
33
+ return clearDate(new Date(time)).getTime()
34
+ } else if (time instanceof Date) {
35
+ return clearDate(time).getTime()
36
+ } else {
37
+ return NaN
38
+ }
39
+ }
40
+ export default {
41
+
42
+ mixins: [Locale],
43
+ props: {
44
+ disabledDate: {},
45
+ value: {},
46
+ selectionMode: {
47
+ default: 'month'
48
+ },
49
+ minDate: {},
50
+
51
+ maxDate: {},
52
+ defaultValue: {
53
+ validator(val) {
54
+ // null or valid Date Object
55
+ return val === null || isDate(val) || (Array.isArray(val) && val.every(isDate))
56
+ }
57
+ },
58
+ date: {},
59
+ rangeState: {
60
+ default() {
61
+ return {
62
+ endDate: null,
63
+ selecting: false
64
+ }
65
+ }
66
+ }
67
+ },
68
+
69
+ data() {
70
+ return {
71
+ months: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'],
72
+ tableRows: [[], [], []],
73
+ lastRow: null,
74
+ lastColumn: null
75
+ }
76
+ },
77
+
78
+ computed: {
79
+ rows() {
80
+ // TODO: refactory rows / getCellClasses
81
+ const rows = this.tableRows
82
+ const disabledDate = this.disabledDate
83
+ const selectedDate = []
84
+ const now = getMonthTimestamp(new Date())
85
+
86
+ for (let i = 0; i < 3; i++) {
87
+ const row = rows[i]
88
+ for (let j = 0; j < 4; j++) {
89
+ let cell = row[j]
90
+ if (!cell) {
91
+ cell = { row: i, column: j, type: 'normal', inRange: false, start: false, end: false }
92
+ }
93
+
94
+ cell.type = 'normal'
95
+
96
+ const index = i * 4 + j
97
+ const time = new Date(this.date.getFullYear(), index).getTime()
98
+ cell.inRange = time >= getMonthTimestamp(this.minDate) && time <= getMonthTimestamp(this.maxDate)
99
+ cell.start = this.minDate && time === getMonthTimestamp(this.minDate)
100
+ cell.end = this.maxDate && time === getMonthTimestamp(this.maxDate)
101
+ const isToday = time === now
102
+
103
+ if (isToday) {
104
+ cell.type = 'today'
105
+ }
106
+ cell.text = index
107
+ const cellDate = new Date(time)
108
+ cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate)
109
+ cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime())
110
+
111
+ this.$set(row, j, cell)
112
+ }
113
+ }
114
+ return rows
115
+ }
116
+ },
117
+
118
+ watch: {
119
+ 'rangeState.endDate'(newVal) {
120
+ this.markRange(this.minDate, newVal)
121
+ },
122
+
123
+ minDate(newVal, oldVal) {
124
+ if (getMonthTimestamp(newVal) !== getMonthTimestamp(oldVal)) {
125
+ this.markRange(this.minDate, this.maxDate)
126
+ }
127
+ },
128
+
129
+ maxDate(newVal, oldVal) {
130
+ if (getMonthTimestamp(newVal) !== getMonthTimestamp(oldVal)) {
131
+ this.markRange(this.minDate, this.maxDate)
132
+ }
133
+ }
134
+ },
135
+
136
+ methods: {
137
+ cellMatchesDate(cell, date) {
138
+ const value = new Date(date)
139
+ return this.date.getFullYear() === value.getFullYear() && Number(cell.text) === value.getMonth()
140
+ },
141
+ getCellStyle(cell) {
142
+ const style = {}
143
+ const year = this.date.getFullYear()
144
+ const today = new Date()
145
+ const month = cell.text
146
+ const defaultValue = this.defaultValue ? Array.isArray(this.defaultValue) ? this.defaultValue : [this.defaultValue] : []
147
+ style.disabled = typeof this.disabledDate === 'function'
148
+ ? datesInMonth(year, month).every(this.disabledDate)
149
+ : false
150
+ style.current = arrayFindIndex(coerceTruthyValueToArray(this.value), date => date.getFullYear() === year && date.getMonth() === month) >= 0
151
+ style.today = today.getFullYear() === year && today.getMonth() === month
152
+ style.default = defaultValue.some(date => this.cellMatchesDate(cell, date))
153
+
154
+ if (cell.inRange) {
155
+ style['in-range'] = true
156
+
157
+ if (cell.start) {
158
+ style['start-date'] = true
159
+ }
160
+
161
+ if (cell.end) {
162
+ style['end-date'] = true
163
+ }
164
+ }
165
+ return style
166
+ },
167
+ getMonthOfCell(month) {
168
+ const year = this.date.getFullYear()
169
+ return new Date(year, month, 1)
170
+ },
171
+ markRange(minDate, maxDate) {
172
+ minDate = getMonthTimestamp(minDate)
173
+ maxDate = getMonthTimestamp(maxDate) || minDate;
174
+ [minDate, maxDate] = [Math.min(minDate, maxDate), Math.max(minDate, maxDate)]
175
+ const rows = this.rows
176
+ for (let i = 0, k = rows.length; i < k; i++) {
177
+ const row = rows[i]
178
+ for (let j = 0, l = row.length; j < l; j++) {
179
+ const cell = row[j]
180
+ const index = i * 4 + j
181
+ const time = new Date(this.date.getFullYear(), index).getTime()
182
+
183
+ cell.inRange = minDate && time >= minDate && time <= maxDate
184
+ cell.start = minDate && time === minDate
185
+ cell.end = maxDate && time === maxDate
186
+ }
187
+ }
188
+ },
189
+ handleMouseMove(event) {
190
+ if (!this.rangeState.selecting) return
191
+
192
+ let target = event.target
193
+ if (target.tagName === 'A') {
194
+ target = target.parentNode.parentNode
195
+ }
196
+ if (target.tagName === 'DIV') {
197
+ target = target.parentNode
198
+ }
199
+ if (target.tagName !== 'TD') return
200
+
201
+ const row = target.parentNode.rowIndex
202
+ const column = target.cellIndex
203
+ // can not select disabled date
204
+ if (this.rows[row][column].disabled) return
205
+
206
+ // only update rangeState when mouse moves to a new cell
207
+ // this avoids frequent Date object creation and improves performance
208
+ if (row !== this.lastRow || column !== this.lastColumn) {
209
+ this.lastRow = row
210
+ this.lastColumn = column
211
+ this.$emit('changerange', {
212
+ minDate: this.minDate,
213
+ maxDate: this.maxDate,
214
+ rangeState: {
215
+ selecting: true,
216
+ endDate: this.getMonthOfCell(row * 4 + column)
217
+ }
218
+ })
219
+ }
220
+ },
221
+ handleMonthTableClick(event) {
222
+ let target = event.target
223
+ if (target.tagName === 'A') {
224
+ target = target.parentNode.parentNode
225
+ }
226
+ if (target.tagName === 'DIV') {
227
+ target = target.parentNode
228
+ }
229
+ if (target.tagName !== 'TD') return
230
+ if (hasClass(target, 'disabled')) return
231
+ const column = target.cellIndex
232
+ const row = target.parentNode.rowIndex
233
+ const month = row * 4 + column
234
+ const newDate = this.getMonthOfCell(month)
235
+ if (this.selectionMode === 'range') {
236
+ if (!this.rangeState.selecting) {
237
+ this.$emit('pick', { minDate: newDate, maxDate: null })
238
+ this.rangeState.selecting = true
239
+ } else {
240
+ if (newDate >= this.minDate) {
241
+ this.$emit('pick', { minDate: this.minDate, maxDate: newDate })
242
+ } else {
243
+ this.$emit('pick', { minDate: newDate, maxDate: this.minDate })
244
+ }
245
+ this.rangeState.selecting = false
246
+ }
247
+ } else {
248
+ this.$emit('pick', month)
249
+ }
250
+ }
251
+ }
252
+ }
253
+ </script>
@@ -222,7 +222,7 @@ import {
222
222
  extractTimeFormat
223
223
  } from 'element-ui/src/utils/date-util'
224
224
  import Clickoutside from 'element-ui/src/utils/clickoutside'
225
- import Locale from 'element-ui/src/mixins/locale'
225
+ import Locale from 'element-ui/lib/mixins/locale'
226
226
  import TimePicker from './time.vue'
227
227
  import DateTable from '../basic/date-table.vue'
228
228
  const calcDefaultValue = (defaultValue) => {
@@ -174,7 +174,7 @@ import {
174
174
  timeWithinRange
175
175
  } from 'element-ui/src/utils/date-util'
176
176
  import Clickoutside from 'element-ui/src/utils/clickoutside'
177
- import Locale from 'element-ui/src/mixins/locale'
177
+ import Locale from 'element-ui/lib/mixins/locale'
178
178
  import TimePicker from './time.vue'
179
179
  import YearTable from '../basic/year-table.vue'
180
180
  import MonthTable from '../basic/month-table.vue'
@@ -92,7 +92,7 @@ import {
92
92
  nextMonth
93
93
  } from 'element-ui/src/utils/date-util'
94
94
  import Clickoutside from 'element-ui/src/utils/clickoutside'
95
- import Locale from 'element-ui/src/mixins/locale'
95
+ import Locale from 'element-ui/lib/mixins/locale'
96
96
  import MonthTable from '../basic/month-table.vue'
97
97
 
98
98
  const calcDefaultValue = (defaultValue) => {
@@ -69,7 +69,7 @@ import {
69
69
  clearMilliseconds,
70
70
  timeWithinRange
71
71
  } from 'element-ui/src/utils/date-util'
72
- import Locale from 'element-ui/src/mixins/locale'
72
+ import Locale from 'element-ui/lib/mixins/locale'
73
73
  import TimeSpinner from '../basic/time-spinner.vue'
74
74
 
75
75
  const MIN_TIME = parseDate('00:00:00', 'HH:mm:ss')
@@ -35,7 +35,7 @@
35
35
 
36
36
  <script type="text/babel">
37
37
  import { limitTimeRange, isDate, clearMilliseconds, timeWithinRange } from 'element-ui/src/utils/date-util'
38
- import Locale from 'element-ui/src/mixins/locale'
38
+ import Locale from 'element-ui/lib/mixins/locale'
39
39
  import TimeSpinner from '../basic/time-spinner.vue'
40
40
 
41
41
  export default {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-timezone-picker",
3
- "version": "5.0.6",
3
+ "version": "5.0.11",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>",
@@ -14,7 +14,7 @@
14
14
  "url": "http://94ai.gitlab.com/ui/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-theme-chalk": "^5.0.6",
17
+ "@94ai/nf-theme-chalk": "^5.0.11",
18
18
  "vue-demi": "^0.14.5"
19
19
  },
20
20
  "peerDependenciesMeta": {
@@ -30,5 +30,5 @@
30
30
  "types": "lib/index.d.ts",
31
31
  "main": "lib/nf-timezone-picker.cjs.js",
32
32
  "module": "lib/nf-timezone-picker.esm-bundler.js",
33
- "gitHead": "a7667792044ecc753e5d7ed1240fa08785c7e2e9"
33
+ "gitHead": "a85628d299e162efb081b5b81084120a70c82a0f"
34
34
  }