sone-ui-component-3.2.4 2.1.62 → 2.1.64

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.
@@ -0,0 +1,147 @@
1
+ import normalizeWheel from 'normalize-wheel'
2
+ import { getValueByPath } from 'element-ui/src/utils/util'
3
+ import throttle from 'lodash/throttle'
4
+
5
+ // 判断是否是滚动容器
6
+ export function isScroller (el) {
7
+ const style = window.getComputedStyle(el, null)
8
+ const scrollValues = ['auto', 'scroll']
9
+ return scrollValues.includes(style.overflow) || scrollValues.includes(style['overflow-y'])
10
+ }
11
+
12
+ // 获取父层滚动容器
13
+ export function getParentScroller (el) {
14
+ let parent = el
15
+ while (parent) {
16
+ if ([window, document, document.documentElement].includes(parent)) {
17
+ return window
18
+ }
19
+ if (isScroller(parent)) {
20
+ return parent
21
+ }
22
+ parent = parent.parentNode
23
+ }
24
+
25
+ return parent || window
26
+ }
27
+
28
+ // 获取容器滚动位置
29
+ export function getScrollTop (el) {
30
+ return el === window ? window.pageYOffset : el.scrollTop
31
+ }
32
+
33
+ // 获取容器高度
34
+ export function getOffsetHeight (el) {
35
+ return el === window ? window.innerHeight : el.offsetHeight
36
+ }
37
+
38
+ // 滚动到某个位置
39
+ export function scrollToY (el, y) {
40
+ if (el === window) {
41
+ window.scroll(0, y)
42
+ } else {
43
+ el.scrollTop = y
44
+ }
45
+ }
46
+
47
+ // 是否为空 undefine or null
48
+ export function isEmpty (val) {
49
+ return typeof val === 'undefined' || val === null
50
+ }
51
+
52
+ export const isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1
53
+
54
+ // 设置滚轮速度(完全参考 element-ui > table > handleFixedMousewheel方法)
55
+ export function setMousewheelSlow (scroller, slow) {
56
+ function handler (event) {
57
+ const data = normalizeWheel(event)
58
+ if (Math.abs(data.spinY) > 0) {
59
+ const currentScrollTop = scroller.scrollTop
60
+ if (data.pixelY < 0 && currentScrollTop !== 0) {
61
+ event.preventDefault()
62
+ }
63
+ if (data.pixelY > 0 && scroller.scrollHeight - scroller.clientHeight > currentScrollTop) {
64
+ event.preventDefault()
65
+ }
66
+ scroller.scrollTop += Math.ceil(data.pixelY / slow)
67
+ }
68
+ }
69
+ const throttleHandler = throttle(handler, 0)
70
+ scroller.addEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', throttleHandler, { passive: false })
71
+ return function destory () {
72
+ scroller.removeEventListener(isFirefox ? 'DOMMouseScroll' : 'mousewheel', throttleHandler)
73
+ }
74
+ }
75
+
76
+ const isObject = function (obj) {
77
+ return obj !== null && typeof obj === 'object'
78
+ }
79
+
80
+ // 排序(来源:element-ui/table/util的orderBy方法)
81
+ export const orderBy = function (array, sortKey, reverse, sortMethod, sortBy) {
82
+ // eslint-disable-next-line no-mixed-operators
83
+ if (!sortKey && !sortMethod && (!sortBy || Array.isArray(sortBy) && !sortBy.length)) {
84
+ return array
85
+ }
86
+ if (typeof reverse === 'string') {
87
+ reverse = reverse === 'descending' ? -1 : 1
88
+ } else {
89
+ reverse = (reverse && reverse < 0) ? -1 : 1
90
+ }
91
+ const getKey = sortMethod ? null : function (value, index) {
92
+ if (sortBy) {
93
+ if (!Array.isArray(sortBy)) {
94
+ sortBy = [sortBy]
95
+ }
96
+ return sortBy.map(function (by) {
97
+ if (typeof by === 'string') {
98
+ return getValueByPath(value, by)
99
+ } else {
100
+ return by(value, index, array)
101
+ }
102
+ })
103
+ }
104
+ if (sortKey !== '$key') {
105
+ if (isObject(value) && '$value' in value) value = value.$value
106
+ }
107
+ return [isObject(value) ? getValueByPath(value, sortKey) : value]
108
+ }
109
+ const compare = function (a, b) {
110
+ if (sortMethod) {
111
+ return sortMethod(a.value, b.value)
112
+ }
113
+ for (let i = 0, len = a.key.length; i < len; i++) {
114
+ if (a.key[i] < b.key[i]) {
115
+ return -1
116
+ }
117
+ if (a.key[i] > b.key[i]) {
118
+ return 1
119
+ }
120
+ }
121
+ return 0
122
+ }
123
+ return array.map(function (value, index) {
124
+ return {
125
+ value: value,
126
+ index: index,
127
+ key: getKey ? getKey(value, index) : null
128
+ }
129
+ }).sort(function (a, b) {
130
+ let order = compare(a, b)
131
+ if (!order) {
132
+ // make stable https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
133
+ order = a.index - b.index
134
+ }
135
+ return order * reverse
136
+ }).map(item => item.value)
137
+ }
138
+
139
+ export const getColumnById = function (table, columnId) {
140
+ let column = null
141
+ table.columns.forEach(function (item) {
142
+ if (item.id === columnId) {
143
+ column = item
144
+ }
145
+ })
146
+ return column
147
+ }
package/src/index.js CHANGED
@@ -57,7 +57,7 @@ if (typeof window !== 'undefined' && window.Vue) {
57
57
  }
58
58
 
59
59
  export default {
60
- version: '2.1.62',
60
+ version: '2.1.64',
61
61
  locale: locale.use,
62
62
  i18n: locale.i18n,
63
63
  install,