beyond-rails 0.0.172 → 0.0.177

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 469a1f5d652f10d810b7c6575e9aa591a33a89434e6e84a7ea12884fa2d0a039
4
- data.tar.gz: d16e57ce2b2891f61b7e76313ee595d1810ce15dfd802fcf1491fc9793242d52
3
+ metadata.gz: edb93ef99c3dedb899622911c44e1394c11892ec357817bd89f69437da2e2c28
4
+ data.tar.gz: 9ffa3851690aae9723208be83abba39743742e9413492563e739d360c26889fa
5
5
  SHA512:
6
- metadata.gz: 40f79d566a84a068bdf3de167170290b7984b9d2164be04e43dcb3704cbbbe68c5380d8049aedc57012805a37c2ef6bfe8e9cbdc76f1d6fbb9902f02dffb16d4
7
- data.tar.gz: 12a54452faa90d2944388dcd728539c714a319cd073cd3268005631b32918b20bd01d656aea63ade762e5eaad0d0bf5b42c5e7d61a5aa8137515fe2f3aa0fbaf
6
+ metadata.gz: a720ab5f813ac0738f91f2a3f89d8a0c5e55d9869bbb129271cfa27438a9455cf9087cdd6f4eba207398076f3dfedd8abf9f13245fe5de701965b4c19059997c
7
+ data.tar.gz: e376485f65d1d0adde8bc7a40f1d9501b87111f53d7e294ee36dbbcb91246409c12880fe2d62857f235d34d4fe367df2647381ab2eb26baa37ba47b5457ec3b4
@@ -66,7 +66,6 @@ export default class Autocomplete {
66
66
  menu.on('click', index => {
67
67
  const { itemClick } = this.options
68
68
  if (typeof itemClick === 'function') {
69
- clearTimeout(this._blurTimer)
70
69
  const value = itemClick(this.rows[index])
71
70
  this.dom.value = value
72
71
  this.menu.hide()
@@ -82,8 +81,13 @@ export default class Autocomplete {
82
81
  }
83
82
  })
84
83
 
85
- this.addEvent(dom, 'blur', () => {
86
- this._blurTimer = setTimeout(() => this.menu.hide(), 50)
84
+ this.addEvent(document, 'click', event => {
85
+ const { target } = event
86
+ const inInput = this.dom.contains(target)
87
+ const inMenu = this.menu.dom.contains(target)
88
+ if ((! inInput) && (! inMenu)) {
89
+ this.menu.hide()
90
+ }
87
91
  })
88
92
 
89
93
  this.addEvent(dom, 'keyup', debounce(() => {
@@ -1,6 +1,6 @@
1
1
  import getFloatedTargetPos from '../utils/getFloatedTargetPos'
2
- import toPixel from '../utils/toPixel'
3
2
  import supportDom from '../utils/supportDom'
3
+ import { toPixel } from '../utils'
4
4
 
5
5
  @supportDom
6
6
  export default class AutocompleteMenu {
@@ -1,5 +1,5 @@
1
1
  import supportDom from '../utils/supportDom'
2
- import toPixel from '../utils/toPixel'
2
+ import { toPixel } from '../utils'
3
3
 
4
4
  @supportDom
5
5
  export default class Btn {
@@ -1,6 +1,4 @@
1
1
  import getFloatedTargetPos from '../utils/getFloatedTargetPos'
2
- import range from '../utils/range'
3
- import toPixel from '../utils/toPixel'
4
2
  import isTouchDevice from '../utils/isTouchDevice'
5
3
  import dateLt from '../utils/dateLt'
6
4
  import dateEq from '../utils/dateEq'
@@ -15,10 +13,12 @@ import {
15
13
  getMonth,
16
14
  getYear,
17
15
  throttle,
16
+ range,
18
17
  set,
19
18
  startOfDay,
20
19
  startOfMonth,
21
20
  subMonths,
21
+ toPixel,
22
22
  format
23
23
  } from '../utils'
24
24
  import { DEFAULT_TIMEZONE, DEFAULT_LOCALE } from '../consts'
@@ -81,7 +81,7 @@ export default class DateMenu {
81
81
 
82
82
  const firstWeekday = getDay(startOfMonth(date))
83
83
  const beforeWeekday = ((firstWeekday - 1) === -1) ? 6 : (firstWeekday - 1)
84
- const emptyHeadRows = range(1, beforeWeekday).map(toEmptyCell)
84
+ const emptyHeadRows = range(1, beforeWeekday + 1).map(toEmptyCell)
85
85
 
86
86
  const initialStartDate = startOfDay(startDate)
87
87
  const initialEndDate = startOfDay(endDate)
@@ -106,7 +106,7 @@ export default class DateMenu {
106
106
  }
107
107
  const today = formatDate(new Date())
108
108
 
109
- const rows = range(1, daysInMonth).map(day => {
109
+ const rows = range(1, daysInMonth + 1).map(day => {
110
110
 
111
111
  const d = addDays(firstDateOfMonth, day - 1)
112
112
  const resCompareStart = compareAsc(startOfStartDate, d)
@@ -124,7 +124,7 @@ export default class DateMenu {
124
124
 
125
125
  const lastWeekday = getDay(endOfMonth(date))
126
126
  const emptyDays = ((7 - lastWeekday) % 7)
127
- const emptyTailRows = range(1, emptyDays).map(toEmptyCell)
127
+ const emptyTailRows = range(1, emptyDays + 1).map(toEmptyCell)
128
128
 
129
129
  return emptyHeadRows.concat(rows).concat(emptyTailRows)
130
130
  }
@@ -97,12 +97,20 @@ export default class Datepicker {
97
97
  this.nextDate = res
98
98
  }
99
99
 
100
+ clearBlurTimer() {
101
+ if (this._blurTimer) {
102
+ clearTimeout(this._blurTimer)
103
+ this._blurTimer = null
104
+ }
105
+ }
106
+
100
107
  handleDateInputBlur() {
101
108
  const { nextDate, date, dateInput } = this
102
109
 
103
110
  if (date === null) {
104
111
  dateInput.setDate(null)
105
112
  this.timeInput && this.timeInput.setDate(null)
113
+ this._blurTimer = setTimeout(() => this.emitChange(), 50)
106
114
  }
107
115
  else if (nextDate) {
108
116
  this.date = nextDate
@@ -191,6 +199,8 @@ export default class Datepicker {
191
199
  event.stopPropagation()
192
200
  event.preventDefault()
193
201
 
202
+ this.clearBlurTimer()
203
+
194
204
  const { year, month, date } = res
195
205
  this.date = set(this.date || new Date(), { year, month, date })
196
206
  this.dateInput.setDate(this.date)
@@ -1,7 +1,6 @@
1
1
  import getFloatedTargetPos from '../utils/getFloatedTargetPos'
2
- import toPixel from '../utils/toPixel'
3
2
  import supportDom from '../utils/supportDom'
4
- import { isFunction, throttle } from '../utils'
3
+ import { isFunction, toPixel, throttle } from '../utils'
5
4
 
6
5
  @supportDom
7
6
  export default class Dropdown {
@@ -1,8 +1,7 @@
1
1
  import getFloatedTargetPos from '../utils/getFloatedTargetPos'
2
- import toPixel from '../utils/toPixel'
3
2
  import supportDom from '../utils/supportDom'
4
3
  import getKey from '../utils/getKey'
5
- import { debounce, noop, throttle } from '../utils'
4
+ import { debounce, noop, toPixel, throttle } from '../utils'
6
5
 
7
6
  const renderMenu = row => {
8
7
  return `<div class="search-dropdown-menu-item" data-item>${JSON.stringify(row)}</div>`
@@ -1,7 +1,6 @@
1
1
  import getFloatedTargetPos from '../utils/getFloatedTargetPos'
2
- import toPixel from '../utils/toPixel'
3
2
  import supportDom from '../utils/supportDom'
4
- import { getHours, getMinutes, range } from '../utils'
3
+ import { getHours, getMinutes, range, toPixel } from '../utils'
5
4
 
6
5
  @supportDom
7
6
  export default class TimeMenu {
@@ -1,6 +1,6 @@
1
1
  import getFloatedTargetPos from '../utils/getFloatedTargetPos'
2
- import toPixel from '../utils/toPixel'
3
2
  import supportDom from '../utils/supportDom'
3
+ import { toPixel } from '../utils'
4
4
 
5
5
  const TOOLTIP_PLACEMENTS = ['top', 'bottom', 'left', 'right']
6
6
 
@@ -65,6 +65,13 @@ export default class Tooltip {
65
65
  const { dom, tooltip } = this
66
66
  if ('onmouseover' in dom) {
67
67
  this.addEvent(dom, 'mouseover', () => {
68
+
69
+ const msg = this.dom.dataset.msg || ''
70
+
71
+ if (msg.length === 0) {
72
+ return
73
+ }
74
+
68
75
  this.setTooltipMsg()
69
76
 
70
77
  tooltip.style.opacity = 0
@@ -0,0 +1,12 @@
1
+ import { test } from '~/test/utils'
2
+ import dateEq from '~/src/js/utils/dateEq'
3
+
4
+ test('dateEq', t => {
5
+
6
+ // Sun Jul 12 2020 18:31:43 GMT+0800 (Taipei Standard Time)
7
+ const date1 = new Date(1594549903944)
8
+
9
+ // Sun Jul 12 2020 18:31:43 GMT+0800 (Taipei Standard Time)
10
+ const date2 = new Date(1594549903944)
11
+ t.true(dateEq(date1, date2))
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test } from '~/test/utils'
2
+ import dateGt from '~/src/js/utils/dateGt'
3
+
4
+ test('dateGt', t => {
5
+
6
+ // Sun Jul 12 2020 18:31:43 GMT+0800 (Taipei Standard Time)
7
+ const date1 = new Date(1594549903944)
8
+
9
+ // Mon Jul 13 2020 18:31:43 GMT+0800 (Taipei Standard Time)
10
+ const date2 = new Date(1594636303944)
11
+ t.true(dateGt(date2, date1))
12
+ })
@@ -0,0 +1,12 @@
1
+ import { test } from '~/test/utils'
2
+ import dateLt from '~/src/js/utils/dateLt'
3
+
4
+ test('dateLt', t => {
5
+
6
+ // Sun Jul 12 2020 18:31:43 GMT+0800 (Taipei Standard Time)
7
+ const date1 = new Date(1594549903944)
8
+
9
+ // Mon Jul 13 2020 18:31:43 GMT+0800 (Taipei Standard Time)
10
+ const date2 = new Date(1594636303944)
11
+ t.true(dateLt(date1, date2))
12
+ })
@@ -0,0 +1,25 @@
1
+ import { test } from '~/test/utils'
2
+ import getKey from '~/src/js/utils/getKey'
3
+
4
+ test('getKey', t => {
5
+
6
+ const keyMap = {
7
+ 13: 'enter',
8
+ 17: 'ctrl',
9
+ 27: 'esc',
10
+ 38: 'up',
11
+ 40: 'down',
12
+ 70: 'f',
13
+ 91: 'left-meta',
14
+ 93: 'right-meta'
15
+ }
16
+
17
+ for (const [k, v] of Object.entries(keyMap)) {
18
+ const keyCode = parseInt(k, 10)
19
+ const event = { keyCode }
20
+ t.is(getKey(event), v)
21
+ }
22
+
23
+ // Return empty string when keyCode is not found.
24
+ t.is(getKey({ keyCode: 9999 }), '')
25
+ })
@@ -0,0 +1,8 @@
1
+ import { test } from '~/test/utils'
2
+ import msToS from '~/src/js/utils/msToS'
3
+
4
+ test('msToS', t => {
5
+ t.is(msToS(1000), 1)
6
+ t.is(msToS(1200), 1)
7
+ t.is(msToS(900), 0)
8
+ })
@@ -4,6 +4,7 @@ import getDomPos from '@superlanding/getdompos'
4
4
  import getScrollLeft from '@superlanding/getscrollleft'
5
5
  import getScrollTop from '@superlanding/getscrolltop'
6
6
  import timestampToDate from '@superlanding/timestamptodate'
7
+ import toPixel from '@superlanding/topixel'
7
8
 
8
9
  // date-fns
9
10
  import addDays from 'date-fns/addDays'
@@ -40,6 +41,7 @@ export {
40
41
  getScrollLeft,
41
42
  getScrollTop,
42
43
  timestampToDate,
44
+ toPixel,
43
45
 
44
46
  // date-fns
45
47
  addDays,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.172
4
+ version: 0.0.177
5
5
  platform: ruby
6
6
  authors:
7
7
  - kmsheng
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-30 00:00:00.000000000 Z
12
+ date: 2020-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sassc
@@ -141,6 +141,11 @@ files:
141
141
  - src/js/polyfills/nodeContains.js
142
142
  - src/js/polyfills/nodeHasAttribute.js
143
143
  - src/js/polyfills/nodeRemove.js
144
+ - src/js/tests/utils/dateEq.test.js
145
+ - src/js/tests/utils/dateGt.test.js
146
+ - src/js/tests/utils/dateLt.test.js
147
+ - src/js/tests/utils/getKey.test.js
148
+ - src/js/tests/utils/msToS.test.js
144
149
  - src/js/utils/bind.js
145
150
  - src/js/utils/dateEq.js
146
151
  - src/js/utils/dateGt.js
@@ -152,9 +157,7 @@ files:
152
157
  - src/js/utils/isTouchDevice.js
153
158
  - src/js/utils/msToS.js
154
159
  - src/js/utils/promisify.js
155
- - src/js/utils/range.js
156
160
  - src/js/utils/supportDom.js
157
- - src/js/utils/toPixel.js
158
161
  - src/js/utils/unbindAll.js
159
162
  - src/sass/_beyond-sprockets.scss
160
163
  - src/sass/_beyond.scss
@@ -1,7 +0,0 @@
1
- export default function range(start, end) {
2
- const arr = []
3
- for (let i = start; i <= end; i++) {
4
- arr.push(i)
5
- }
6
- return arr
7
- }
@@ -1,3 +0,0 @@
1
- export default function toPixel(num) {
2
- return parseInt(num, 10) + 'px'
3
- }