@vxe-ui/core 4.4.31 → 4.4.32
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.
- package/dist/all.esm.js +192 -3
- package/es/index.esm.js +3 -0
- package/es/src/core.js +1 -1
- package/es/src/log.js +1 -1
- package/es/src/popper-utils.js +188 -0
- package/lib/index.common.js +13 -0
- package/lib/index.umd.js +198 -2
- package/lib/index.umd.min.js +1 -1
- package/lib/src/core.js +1 -1
- package/lib/src/core.min.js +1 -1
- package/lib/src/log.js +1 -1
- package/lib/src/log.min.js +1 -1
- package/lib/src/popper-utils.js +198 -0
- package/lib/src/popper-utils.min.js +1 -0
- package/package.json +1 -1
- package/packages/index.ts +3 -0
- package/packages/src/popper-utils.ts +194 -0
- package/types/core/index.d.ts +7 -0
- package/types/core/popper-utils.d.ts +44 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.popperUtils=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function getWrapperElement(e){var t;return e&&(t=document.body,(e=e.parentElement)===t?document.documentElement:e)||null}function getAppendSelector(e){return(e&&_xeUtils.default.isFunction(e)?e({}):e)||"body"}function getAppendElement(e){e=getAppendSelector(e);return _xeUtils.default.isString(e)?document.querySelector(e)||document.body:e}let popperUtils=exports.popperUtils={updatePlacement(e,t,o){var{defaultTop:o,defaultLeft:l,placement:n,defaultPlacement:p,appendTo:i,teleportTo:r,marginSize:d,isMinWidth:u}=Object.assign({appendTo:"",teleportTo:!1,marginSize:18,isMinWidth:!0},o);let f="bottom",a="",s="",m=0;var c="";let g="";var b,x,_,h,W,E,U,A,S,v,y,T={};return t&&e&&(E=document.body,i=getWrapperElement(r?getAppendElement(i):t))&&(b=e.offsetWidth,x=e.offsetHeight,_=t.offsetWidth,h=t.offsetHeight,S=i.getBoundingClientRect(),t=t.getBoundingClientRect(),y=e.getBoundingClientRect(),W=E.clientHeight,E=E.clientWidth,U=i.scrollLeft,i=i.scrollTop,A=S.left,S=S.top,v=y.left,y=y.top,c=e.offsetWidth,r?(m=(l||v-(_-b)/2)-U,a=(o||y+x)-i,"top"===n?(f="top",a=y-h):n||("top"===p?(f="top",(a=o?a:y-h)<d&&(f="bottom",a=y+x),a+h+d>W&&(f="top",a=y-h)):(a+h+d>W&&(f="top",a=y-h),a<d&&(f="bottom",a=y+x))),m+_+d>E&&(m-=m+_+d-E),m<d&&(m=d),a-=S,m-=A):("top"===n?(f="top",s=x):n||W<y+(a=x)+h+d&&d<y-x-h&&(f="top",a="",s=x),t.left+t.width+d>E&&(m=-(t.left+t.width+d-E))),_xeUtils.default.isNumber(a)&&(T.top=a+"px"),_xeUtils.default.isNumber(s)&&(T.bottom=s+"px"),_xeUtils.default.isNumber(m)&&(T.left=m+"px"),u&&_xeUtils.default.isNumber(c)&&(T.minWidth=c+"px"),m===v?b<=_&&(g=b/2):m<v&&(g=m+_>v+b?v-m+b/2:v-m+(_-(v-m))/2)),{top:a||0,bottom:s||0,left:m||0,arrowLeft:g||0,style:T,placement:f}},getWrapperElement:getWrapperElement,getAppendSelector:getAppendSelector,getAppendElement:getAppendElement};
|
package/package.json
CHANGED
package/packages/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { permission } from './src/permission'
|
|
|
18
18
|
import { baseUtils } from './src/base-utils'
|
|
19
19
|
import { domUtils } from './src/dom-utils'
|
|
20
20
|
import { scrollbarUtils } from './src/scrollbar-utils'
|
|
21
|
+
import { popperUtils } from './src/popper-utils'
|
|
21
22
|
import { log } from './src/log'
|
|
22
23
|
import { hooks } from './src/hooks'
|
|
23
24
|
import { useFns } from './src/useFns'
|
|
@@ -111,6 +112,7 @@ export const VxeUI = Object.assign(VxeCore, {
|
|
|
111
112
|
baseUtils,
|
|
112
113
|
domUtils,
|
|
113
114
|
scrollbarUtils,
|
|
115
|
+
popperUtils,
|
|
114
116
|
|
|
115
117
|
globalStore,
|
|
116
118
|
|
|
@@ -149,6 +151,7 @@ export * from './src/permission'
|
|
|
149
151
|
export * from './src/base-utils'
|
|
150
152
|
export * from './src/dom-utils'
|
|
151
153
|
export * from './src/scrollbar-utils'
|
|
154
|
+
export * from './src/popper-utils'
|
|
152
155
|
|
|
153
156
|
export * from './src/dataStore'
|
|
154
157
|
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
|
|
3
|
+
import type { VxePopperUtils, VxePopperOptions } from '../../types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 获取包裹容器的元素
|
|
7
|
+
*/
|
|
8
|
+
function getWrapperElement (panelElem: HTMLElement | null | undefined) {
|
|
9
|
+
if (!panelElem) {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
const bodyEl = document.body
|
|
13
|
+
const parentEl = panelElem.parentElement
|
|
14
|
+
return (parentEl === bodyEl ? document.documentElement : parentEl) || null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 获取插入到指定容器的元素或字符串
|
|
19
|
+
*/
|
|
20
|
+
function getAppendSelector (appendTo: string | HTMLElement | ((params: any) => string | HTMLElement) | undefined) {
|
|
21
|
+
const selectElem = appendTo && XEUtils.isFunction(appendTo) ? appendTo({}) : appendTo
|
|
22
|
+
return selectElem || 'body'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 获取插入到指定容器的元素
|
|
27
|
+
*/
|
|
28
|
+
function getAppendElement (appendTo: string | HTMLElement | ((params: any) => string | HTMLElement) | undefined) {
|
|
29
|
+
const selectElem = getAppendSelector(appendTo)
|
|
30
|
+
if (XEUtils.isString(selectElem)) {
|
|
31
|
+
return document.querySelector<HTMLElement>(selectElem) || document.body
|
|
32
|
+
}
|
|
33
|
+
return selectElem
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const popperUtils: VxePopperUtils = {
|
|
37
|
+
/**
|
|
38
|
+
* 更新位置
|
|
39
|
+
*/
|
|
40
|
+
updatePlacement (targetElem: HTMLElement | null | undefined, panelElem: HTMLElement | null | undefined, options: VxePopperOptions) {
|
|
41
|
+
const { defaultTop, defaultLeft, placement, defaultPlacement, appendTo, teleportTo, marginSize, isMinWidth } = Object.assign({
|
|
42
|
+
appendTo: '',
|
|
43
|
+
teleportTo: false,
|
|
44
|
+
marginSize: 18,
|
|
45
|
+
isMinWidth: true
|
|
46
|
+
}, options)
|
|
47
|
+
let panelPlacement: 'top' | 'bottom' = 'bottom'
|
|
48
|
+
let top: number | '' = ''
|
|
49
|
+
let bottom: number | '' = ''
|
|
50
|
+
let left = 0
|
|
51
|
+
let minWidth: number | '' = ''
|
|
52
|
+
let arrowLeft: number | '' = ''
|
|
53
|
+
const stys: Record<string, string> = {}
|
|
54
|
+
if (panelElem && targetElem) {
|
|
55
|
+
const bodyEl = document.body
|
|
56
|
+
const parentWrapperEl = getWrapperElement(teleportTo ? getAppendElement(appendTo) : panelElem)
|
|
57
|
+
if (parentWrapperEl) {
|
|
58
|
+
const targetWidth = targetElem.offsetWidth
|
|
59
|
+
const targetHeight = targetElem.offsetHeight
|
|
60
|
+
const panelWidth = panelElem.offsetWidth
|
|
61
|
+
const panelHeight = panelElem.offsetHeight
|
|
62
|
+
|
|
63
|
+
const parentWrapperRect = parentWrapperEl.getBoundingClientRect()
|
|
64
|
+
const panelRect = panelElem.getBoundingClientRect()
|
|
65
|
+
const targetRect = targetElem.getBoundingClientRect()
|
|
66
|
+
const visibleHeight = bodyEl.clientHeight
|
|
67
|
+
const visibleWidth = bodyEl.clientWidth
|
|
68
|
+
|
|
69
|
+
const parentWrapperScrollLeft = parentWrapperEl.scrollLeft
|
|
70
|
+
const parentWrapperScrollTop = parentWrapperEl.scrollTop
|
|
71
|
+
const parentWrapperOffsetLeft = parentWrapperRect.left
|
|
72
|
+
const parentWrapperOffsetTop = parentWrapperRect.top
|
|
73
|
+
const targetLeft = targetRect.left
|
|
74
|
+
const targetTop = targetRect.top
|
|
75
|
+
|
|
76
|
+
minWidth = targetElem.offsetWidth
|
|
77
|
+
|
|
78
|
+
if (teleportTo) {
|
|
79
|
+
left = (defaultLeft || (targetLeft - (panelWidth - targetWidth) / 2)) - parentWrapperScrollLeft
|
|
80
|
+
top = (defaultTop || (targetTop + targetHeight)) - parentWrapperScrollTop
|
|
81
|
+
if (placement === 'top') {
|
|
82
|
+
panelPlacement = 'top'
|
|
83
|
+
top = targetTop - panelHeight
|
|
84
|
+
} else if (!placement) {
|
|
85
|
+
if (defaultPlacement === 'top') {
|
|
86
|
+
panelPlacement = 'top'
|
|
87
|
+
if (!defaultTop) {
|
|
88
|
+
top = targetTop - panelHeight
|
|
89
|
+
}
|
|
90
|
+
// 如果上面不够放,则向下
|
|
91
|
+
if (top < marginSize) {
|
|
92
|
+
panelPlacement = 'bottom'
|
|
93
|
+
top = targetTop + targetHeight
|
|
94
|
+
}
|
|
95
|
+
// 如果下面不够放,则向上(优先)
|
|
96
|
+
if (top + panelHeight + marginSize > visibleHeight) {
|
|
97
|
+
panelPlacement = 'top'
|
|
98
|
+
top = targetTop - panelHeight
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
// 如果下面不够放,则向上
|
|
102
|
+
if (top + panelHeight + marginSize > visibleHeight) {
|
|
103
|
+
panelPlacement = 'top'
|
|
104
|
+
top = targetTop - panelHeight
|
|
105
|
+
}
|
|
106
|
+
// 如果上面不够放,则向下(优先)
|
|
107
|
+
if (top < marginSize) {
|
|
108
|
+
panelPlacement = 'bottom'
|
|
109
|
+
top = targetTop + targetHeight
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// 如果溢出右边
|
|
114
|
+
if (left + panelWidth + marginSize > visibleWidth) {
|
|
115
|
+
left -= left + panelWidth + marginSize - visibleWidth
|
|
116
|
+
}
|
|
117
|
+
// 如果溢出左边
|
|
118
|
+
if (left < marginSize) {
|
|
119
|
+
left = marginSize
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 偏移
|
|
123
|
+
top -= parentWrapperOffsetTop
|
|
124
|
+
left -= parentWrapperOffsetLeft
|
|
125
|
+
} else {
|
|
126
|
+
if (placement === 'top') {
|
|
127
|
+
panelPlacement = 'top'
|
|
128
|
+
bottom = targetHeight
|
|
129
|
+
} else if (!placement) {
|
|
130
|
+
// 如果下面不够放,则向上
|
|
131
|
+
top = targetHeight
|
|
132
|
+
if (targetTop + targetHeight + panelHeight + marginSize > visibleHeight) {
|
|
133
|
+
// 如果上面不够放,则向下(优先)
|
|
134
|
+
if (targetTop - targetHeight - panelHeight > marginSize) {
|
|
135
|
+
panelPlacement = 'top'
|
|
136
|
+
top = ''
|
|
137
|
+
bottom = targetHeight
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// 是否超出右侧
|
|
142
|
+
if (panelRect.left + panelRect.width + marginSize > visibleWidth) {
|
|
143
|
+
left = -(panelRect.left + panelRect.width + marginSize - visibleWidth)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (XEUtils.isNumber(top)) {
|
|
147
|
+
stys.top = top + 'px'
|
|
148
|
+
}
|
|
149
|
+
if (XEUtils.isNumber(bottom)) {
|
|
150
|
+
stys.bottom = bottom + 'px'
|
|
151
|
+
}
|
|
152
|
+
if (XEUtils.isNumber(left)) {
|
|
153
|
+
stys.left = left + 'px'
|
|
154
|
+
}
|
|
155
|
+
if (isMinWidth && XEUtils.isNumber(minWidth)) {
|
|
156
|
+
stys.minWidth = minWidth + 'px'
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 箭头
|
|
160
|
+
if (left === targetLeft) {
|
|
161
|
+
if (targetWidth <= panelWidth) {
|
|
162
|
+
arrowLeft = targetWidth / 2
|
|
163
|
+
}
|
|
164
|
+
} else if (left < targetLeft) {
|
|
165
|
+
if (left + panelWidth > targetLeft + targetWidth) {
|
|
166
|
+
arrowLeft = (targetLeft - left) + targetWidth / 2
|
|
167
|
+
} else {
|
|
168
|
+
arrowLeft = (targetLeft - left) + (panelWidth - (targetLeft - left)) / 2
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
top: top || 0,
|
|
175
|
+
bottom: bottom || 0,
|
|
176
|
+
left: left || 0,
|
|
177
|
+
arrowLeft: arrowLeft || 0,
|
|
178
|
+
style: stys,
|
|
179
|
+
placement: panelPlacement
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
/**
|
|
183
|
+
* 获取包裹容器的元素
|
|
184
|
+
*/
|
|
185
|
+
getWrapperElement,
|
|
186
|
+
/**
|
|
187
|
+
* 获取插入到指定容器的元素或字符串
|
|
188
|
+
*/
|
|
189
|
+
getAppendSelector,
|
|
190
|
+
/**
|
|
191
|
+
* 获取插入到指定容器的元素
|
|
192
|
+
*/
|
|
193
|
+
getAppendElement
|
|
194
|
+
}
|
package/types/core/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { VxeGlobalPermission } from './permission'
|
|
|
17
17
|
import { VxeBaseUtils } from './base-utils'
|
|
18
18
|
import { VxeDomUtils } from './dom-utils'
|
|
19
19
|
import { VxeScrollbarUtils } from './scrollbar-utils'
|
|
20
|
+
import { VxePopperUtils } from './popper-utils'
|
|
20
21
|
import { VxeGlobalComponentMethod, VxeGlobalGetComponentMethod, VxeGlobalHasComponentMethod } from './components'
|
|
21
22
|
import { VxeGlobalUseFns } from './useFn'
|
|
22
23
|
import { VxeGlobalHooks } from './hooks'
|
|
@@ -76,6 +77,7 @@ export const permission: VxeGlobalPermission
|
|
|
76
77
|
export const baseUtils: VxeBaseUtils
|
|
77
78
|
export const domUtils: VxeDomUtils
|
|
78
79
|
export const scrollbarUtils: VxeScrollbarUtils
|
|
80
|
+
export const popperUtils: VxePopperUtils
|
|
79
81
|
|
|
80
82
|
export const globalEvents: VxeGlobalEvents
|
|
81
83
|
|
|
@@ -223,6 +225,10 @@ export interface VxeUIExport {
|
|
|
223
225
|
* 滚动条工具函数
|
|
224
226
|
*/
|
|
225
227
|
scrollbarUtils: VxeScrollbarUtils
|
|
228
|
+
/**
|
|
229
|
+
* 弹出元素定位工具函数
|
|
230
|
+
*/
|
|
231
|
+
popperUtils: VxePopperUtils
|
|
226
232
|
|
|
227
233
|
/**
|
|
228
234
|
* 全局事件管理
|
|
@@ -309,6 +315,7 @@ export * from './permission'
|
|
|
309
315
|
export * from './base-utils'
|
|
310
316
|
export * from './dom-utils'
|
|
311
317
|
export * from './scrollbar-utils'
|
|
318
|
+
export * from './popper-utils'
|
|
312
319
|
|
|
313
320
|
export * from './log'
|
|
314
321
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface VxePopperOptions {
|
|
2
|
+
defaultTop?: number
|
|
3
|
+
defaultLeft?: number
|
|
4
|
+
placement?: '' | 'top' | 'bottom' | null
|
|
5
|
+
defaultPlacement?: '' | 'top' | 'bottom' | null
|
|
6
|
+
appendTo?: string | HTMLElement | ((params: any) => string | HTMLElement)
|
|
7
|
+
teleportTo?: boolean
|
|
8
|
+
marginSize?: number
|
|
9
|
+
isMinWidth?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface VxePopperPlacementResult {
|
|
13
|
+
top: number
|
|
14
|
+
bottom: number
|
|
15
|
+
left: number
|
|
16
|
+
arrowLeft: number
|
|
17
|
+
style: Record<string, string>
|
|
18
|
+
placement: 'top' | 'bottom'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface VxePopperUtils {
|
|
22
|
+
/**
|
|
23
|
+
* 更新位置
|
|
24
|
+
* @param targetElem
|
|
25
|
+
* @param panelElem
|
|
26
|
+
* @param options
|
|
27
|
+
*/
|
|
28
|
+
updatePlacement (targetElem: HTMLElement | null | undefined, panelElem: HTMLElement | null | undefined, options: VxePopperOptions): VxePopperPlacementResult
|
|
29
|
+
/**
|
|
30
|
+
* 获取包裹容器的元素
|
|
31
|
+
* @param panelElem
|
|
32
|
+
*/
|
|
33
|
+
getWrapperElement (panelElem: HTMLElement | null | undefined): HTMLElement | null
|
|
34
|
+
/**
|
|
35
|
+
* 获取插入到指定容器的元素或字符串
|
|
36
|
+
* @param appendTo
|
|
37
|
+
*/
|
|
38
|
+
getAppendSelector (appendTo: string | HTMLElement | ((params: any) => string | HTMLElement) | undefined): HTMLElement | string
|
|
39
|
+
/**
|
|
40
|
+
* 获取插入到指定容器的元素
|
|
41
|
+
* @param appendTo
|
|
42
|
+
*/
|
|
43
|
+
getAppendElement (appendTo: string | HTMLElement | ((params: any) => string | HTMLElement) | undefined): HTMLElement | null
|
|
44
|
+
}
|