doway-coms 1.1.37 → 1.1.38

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,181 @@
1
+ import XEUtils from 'xe-utils'
2
+
3
+ export const browse = XEUtils.browse()
4
+ const reClsMap = {}
5
+
6
+ function getClsRE (cls) {
7
+ if (!reClsMap[cls]) {
8
+ reClsMap[cls] = new RegExp(`(?:^|\\s)${cls}(?!\\S)`, 'g')
9
+ }
10
+ return reClsMap[cls]
11
+ }
12
+
13
+ function getNodeOffset (elem, container, rest) {
14
+ if (elem) {
15
+ const parentElem = elem.parentNode
16
+ rest.top += elem.offsetTop
17
+ rest.left += elem.offsetLeft
18
+ if (parentElem && parentElem !== document.documentElement && parentElem !== document.body) {
19
+ rest.top -= parentElem.scrollTop
20
+ rest.left -= parentElem.scrollLeft
21
+ }
22
+ if (container && (elem === container || elem.offsetParent === container) ? 0 : elem.offsetParent) {
23
+ return getNodeOffset(elem.offsetParent, container, rest)
24
+ }
25
+ }
26
+ return rest
27
+ }
28
+
29
+ function isScale (val) {
30
+ return val && /^\d+%$/.test(val)
31
+ }
32
+
33
+ function hasClass (elem, cls) {
34
+ return elem && elem.className && elem.className.match && elem.className.match(getClsRE(cls))
35
+ }
36
+
37
+ function removeClass (elem, cls) {
38
+ if (elem && hasClass(elem, cls)) {
39
+ elem.className = elem.className.replace(getClsRE(cls), '')
40
+ }
41
+ }
42
+
43
+ function getDomNode () {
44
+ const documentElement = document.documentElement
45
+ const bodyElem = document.body
46
+ return {
47
+ scrollTop: documentElement.scrollTop || bodyElem.scrollTop,
48
+ scrollLeft: documentElement.scrollLeft || bodyElem.scrollLeft,
49
+ visibleHeight: documentElement.clientHeight || bodyElem.clientHeight,
50
+ visibleWidth: documentElement.clientWidth || bodyElem.clientWidth
51
+ }
52
+ }
53
+
54
+ export function getOffsetHeight (elem) {
55
+ return elem ? elem.offsetHeight : 0
56
+ }
57
+
58
+ export function getPaddingTopBottomSize (elem) {
59
+ if (elem) {
60
+ const computedStyle = getComputedStyle(elem)
61
+ const paddingTop = XEUtils.toNumber(computedStyle.paddingTop)
62
+ const paddingBottom = XEUtils.toNumber(computedStyle.paddingBottom)
63
+ return paddingTop + paddingBottom
64
+ }
65
+ return 0
66
+ }
67
+
68
+ export function setScrollTop (elem, scrollTop) {
69
+ if (elem) {
70
+ elem.scrollTop = scrollTop
71
+ }
72
+ }
73
+
74
+ export function setScrollLeft (elem, scrollLeft) {
75
+ if (elem) {
76
+ elem.scrollLeft = scrollLeft
77
+ }
78
+ }
79
+
80
+ // export function setScrollLeftAndTop (elem, scrollLeft, scrollTop) {
81
+ // if (elem) {
82
+ // elem.scrollLeft = scrollLeft
83
+ // elem.scrollTop = scrollTop
84
+ // }
85
+ // }
86
+
87
+ function isNodeElement (elem) {
88
+ return elem && elem.nodeType === 1
89
+ }
90
+
91
+ export const DomTools = {
92
+ browse,
93
+ isPx (val) {
94
+ return val && /^\d+(px)?$/.test(val)
95
+ },
96
+ isScale,
97
+ hasClass,
98
+ removeClass,
99
+ addClass (elem, cls) {
100
+ if (elem && !hasClass(elem, cls)) {
101
+ removeClass(elem, cls)
102
+ elem.className = `${elem.className} ${cls}`
103
+ }
104
+ },
105
+ updateCellTitle (overflowElem, column) {
106
+ const content = column.type === 'html' ? overflowElem.innerText : overflowElem.textContent
107
+ if (overflowElem.getAttribute('title') !== content) {
108
+ overflowElem.setAttribute('title', content)
109
+ }
110
+ },
111
+ getDomNode,
112
+ /**
113
+ * 检查触发源是否属于目标节点
114
+ */
115
+ getEventTargetNode (evnt, container, queryCls, queryMethod) {
116
+ let targetElem
117
+ let target =
118
+ evnt.target.shadowRoot && evnt.composed
119
+ ? evnt.composedPath()[0] || evnt.target
120
+ : evnt.target
121
+ while (target && target.nodeType && target !== document) {
122
+ if (queryCls && hasClass(target, queryCls) && (!queryMethod || queryMethod(target))) {
123
+ targetElem = target
124
+ } else if (target === container) {
125
+ return { flag: queryCls ? !!targetElem : true, container, targetElem: targetElem }
126
+ }
127
+ target = target.parentNode
128
+ }
129
+ return { flag: false }
130
+ },
131
+ /**
132
+ * 获取元素相对于 document 的位置
133
+ */
134
+ getOffsetPos (elem, container) {
135
+ return getNodeOffset(elem, container, { left: 0, top: 0 })
136
+ },
137
+ getAbsolutePos (elem) {
138
+ const bounding = elem.getBoundingClientRect()
139
+ const boundingTop = bounding.top
140
+ const boundingLeft = bounding.left
141
+ const { scrollTop, scrollLeft, visibleHeight, visibleWidth } = getDomNode()
142
+ return { boundingTop, top: scrollTop + boundingTop, boundingLeft, left: scrollLeft + boundingLeft, visibleHeight, visibleWidth }
143
+ },
144
+ scrollToView (elem) {
145
+ const scrollIntoViewIfNeeded = 'scrollIntoViewIfNeeded'
146
+ const scrollIntoView = 'scrollIntoView'
147
+ if (elem) {
148
+ if (elem[scrollIntoViewIfNeeded]) {
149
+ elem[scrollIntoViewIfNeeded]()
150
+ } else if (elem[scrollIntoView]) {
151
+ elem[scrollIntoView]()
152
+ }
153
+ }
154
+ },
155
+ triggerEvent (targetElem, type) {
156
+ if (targetElem) {
157
+ targetElem.dispatchEvent(new Event(type))
158
+ }
159
+ },
160
+ calcHeight ($xetable, key) {
161
+ const val = $xetable[key]
162
+ let num = 0
163
+ if (val) {
164
+ if (val === 'auto') {
165
+ num = $xetable.parentHeight
166
+ } else {
167
+ const excludeHeight = $xetable.getExcludeHeight()
168
+ if (isScale(val)) {
169
+ num = Math.floor((XEUtils.toInteger(val) || 1) / 100 * $xetable.parentHeight)
170
+ } else {
171
+ num = XEUtils.toNumber(val)
172
+ }
173
+ num = Math.max(40, num - excludeHeight)
174
+ }
175
+ }
176
+ return num
177
+ },
178
+ isNodeElement
179
+ }
180
+
181
+ export default DomTools
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doway-coms",
3
- "version": "1.1.37",
3
+ "version": "1.1.38",
4
4
  "description": "doway组件库",
5
5
  "author": "dowaysoft",
6
6
  "main": "lib/doway-coms.umd.min.js",
@@ -9,7 +9,8 @@
9
9
  "dev": "vue-cli-service serve",
10
10
  "build": "vue-cli-service build",
11
11
  "lint": "vue-cli-service lint",
12
- "lib": "vue-cli-service build --target lib --name doway-coms --dest lib packages/index.js"
12
+ "lib": "npm run patchFiles && vue-cli-service build --target lib --name doway-coms --dest lib packages/index.js",
13
+ "patchFiles": "node ./packages/utils/patchFiles.js"
13
14
  },
14
15
  "dependencies": {
15
16
  "ant-design-vue": "1.7.8",