@vxe-ui/core 4.4.30 → 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 +250 -3
- package/es/index.esm.js +6 -0
- package/es/src/core.js +1 -1
- package/es/src/log.js +1 -1
- package/es/src/popper-utils.js +188 -0
- package/es/src/scrollbar-utils.js +56 -0
- package/lib/index.common.js +26 -0
- package/lib/index.umd.js +259 -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/lib/src/scrollbar-utils.js +62 -0
- package/lib/src/scrollbar-utils.min.js +1 -0
- package/package.json +1 -1
- package/packages/index.ts +6 -0
- package/packages/src/popper-utils.ts +194 -0
- package/packages/src/scrollbar-utils.ts +58 -0
- package/types/core/index.d.ts +14 -0
- package/types/core/popper-utils.d.ts +44 -0
- package/types/core/scrollbar-utils.d.ts +38 -0
package/dist/all.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import { h, reactive, computed, inject, provide, createCommentVNode } from 'vue'
|
|
|
2
2
|
import XEUtils from 'xe-utils';
|
|
3
3
|
import DomZIndex from 'dom-zindex';
|
|
4
4
|
|
|
5
|
-
const coreVersion = "4.4.
|
|
5
|
+
const coreVersion = "4.4.32";
|
|
6
6
|
const VxeCore = {
|
|
7
7
|
coreVersion,
|
|
8
8
|
uiVersion: '',
|
|
@@ -402,7 +402,7 @@ function createLog(type, name) {
|
|
|
402
402
|
return msg;
|
|
403
403
|
};
|
|
404
404
|
}
|
|
405
|
-
const version = "4.4.
|
|
405
|
+
const version = "4.4.32";
|
|
406
406
|
const log = {
|
|
407
407
|
create: createLog,
|
|
408
408
|
warn: createLog('warn', `v${version}`),
|
|
@@ -863,6 +863,251 @@ const domUtils = {
|
|
|
863
863
|
}
|
|
864
864
|
};
|
|
865
865
|
|
|
866
|
+
const scrollbarUtils = {
|
|
867
|
+
/**
|
|
868
|
+
* 计算滚动条滑块的长度
|
|
869
|
+
*/
|
|
870
|
+
getThumbSize(viewportSize, contentSize, trackSize) {
|
|
871
|
+
if (contentSize <= viewportSize) {
|
|
872
|
+
return 0;
|
|
873
|
+
}
|
|
874
|
+
const ratio = viewportSize / contentSize;
|
|
875
|
+
const ideal = trackSize * ratio;
|
|
876
|
+
return Math.max(20, Math.min(ideal, trackSize));
|
|
877
|
+
},
|
|
878
|
+
/**
|
|
879
|
+
* 计算滚动条滑块的偏移位置
|
|
880
|
+
*/
|
|
881
|
+
getThumbOffsetSize(offsetSize, viewportSize, contentSize, trackSize, thumbSize) {
|
|
882
|
+
const maxScroll = contentSize - viewportSize;
|
|
883
|
+
if (maxScroll <= 0) {
|
|
884
|
+
return 0;
|
|
885
|
+
}
|
|
886
|
+
const maxThumbOffset = trackSize - thumbSize;
|
|
887
|
+
if (maxThumbOffset <= 0) {
|
|
888
|
+
return 0;
|
|
889
|
+
}
|
|
890
|
+
const clamped = Math.min(Math.max(offsetSize, 0), maxScroll);
|
|
891
|
+
const ratio = clamped / maxScroll;
|
|
892
|
+
return ratio * maxThumbOffset;
|
|
893
|
+
},
|
|
894
|
+
/**
|
|
895
|
+
* 根据点击轨道的位置,计算滑块的偏移位置
|
|
896
|
+
*/
|
|
897
|
+
getScrollFromClick(clickPosition, viewportSize, contentSize, trackSize, thumbSize) {
|
|
898
|
+
const maxThumbOffset = trackSize - thumbSize;
|
|
899
|
+
const maxScroll = contentSize - viewportSize;
|
|
900
|
+
if (maxScroll <= 0 || maxThumbOffset <= 0) {
|
|
901
|
+
return 0;
|
|
902
|
+
}
|
|
903
|
+
let thumbOffset = clickPosition - thumbSize / 2;
|
|
904
|
+
thumbOffset = Math.min(Math.max(thumbOffset, 0), maxThumbOffset);
|
|
905
|
+
const scrollOffset = (thumbOffset / maxThumbOffset) * maxScroll;
|
|
906
|
+
return scrollOffset;
|
|
907
|
+
},
|
|
908
|
+
/**
|
|
909
|
+
* 拖拽 thumb 时,根据鼠标位置计算滑块的偏移位置
|
|
910
|
+
*/
|
|
911
|
+
getScrollFromDrag(pointerPosition, dragOffset, viewportSize, contentSize, trackSize, thumbSize) {
|
|
912
|
+
const maxScroll = contentSize - viewportSize;
|
|
913
|
+
const maxThumbOffset = trackSize - thumbSize;
|
|
914
|
+
if (maxScroll <= 0 || maxThumbOffset <= 0) {
|
|
915
|
+
return 0;
|
|
916
|
+
}
|
|
917
|
+
let thumbOffset = pointerPosition - dragOffset;
|
|
918
|
+
thumbOffset = Math.min(Math.max(thumbOffset, 0), maxThumbOffset);
|
|
919
|
+
return (thumbOffset / maxThumbOffset) * maxScroll;
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* 获取包裹容器的元素
|
|
925
|
+
*/
|
|
926
|
+
function getWrapperElement(panelElem) {
|
|
927
|
+
if (!panelElem) {
|
|
928
|
+
return null;
|
|
929
|
+
}
|
|
930
|
+
const bodyEl = document.body;
|
|
931
|
+
const parentEl = panelElem.parentElement;
|
|
932
|
+
return (parentEl === bodyEl ? document.documentElement : parentEl) || null;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* 获取插入到指定容器的元素或字符串
|
|
936
|
+
*/
|
|
937
|
+
function getAppendSelector(appendTo) {
|
|
938
|
+
const selectElem = appendTo && XEUtils.isFunction(appendTo) ? appendTo({}) : appendTo;
|
|
939
|
+
return selectElem || 'body';
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* 获取插入到指定容器的元素
|
|
943
|
+
*/
|
|
944
|
+
function getAppendElement(appendTo) {
|
|
945
|
+
const selectElem = getAppendSelector(appendTo);
|
|
946
|
+
if (XEUtils.isString(selectElem)) {
|
|
947
|
+
return document.querySelector(selectElem) || document.body;
|
|
948
|
+
}
|
|
949
|
+
return selectElem;
|
|
950
|
+
}
|
|
951
|
+
const popperUtils = {
|
|
952
|
+
/**
|
|
953
|
+
* 更新位置
|
|
954
|
+
*/
|
|
955
|
+
updatePlacement(targetElem, panelElem, options) {
|
|
956
|
+
const { defaultTop, defaultLeft, placement, defaultPlacement, appendTo, teleportTo, marginSize, isMinWidth } = Object.assign({
|
|
957
|
+
appendTo: '',
|
|
958
|
+
teleportTo: false,
|
|
959
|
+
marginSize: 18,
|
|
960
|
+
isMinWidth: true
|
|
961
|
+
}, options);
|
|
962
|
+
let panelPlacement = 'bottom';
|
|
963
|
+
let top = '';
|
|
964
|
+
let bottom = '';
|
|
965
|
+
let left = 0;
|
|
966
|
+
let minWidth = '';
|
|
967
|
+
let arrowLeft = '';
|
|
968
|
+
const stys = {};
|
|
969
|
+
if (panelElem && targetElem) {
|
|
970
|
+
const bodyEl = document.body;
|
|
971
|
+
const parentWrapperEl = getWrapperElement(teleportTo ? getAppendElement(appendTo) : panelElem);
|
|
972
|
+
if (parentWrapperEl) {
|
|
973
|
+
const targetWidth = targetElem.offsetWidth;
|
|
974
|
+
const targetHeight = targetElem.offsetHeight;
|
|
975
|
+
const panelWidth = panelElem.offsetWidth;
|
|
976
|
+
const panelHeight = panelElem.offsetHeight;
|
|
977
|
+
const parentWrapperRect = parentWrapperEl.getBoundingClientRect();
|
|
978
|
+
const panelRect = panelElem.getBoundingClientRect();
|
|
979
|
+
const targetRect = targetElem.getBoundingClientRect();
|
|
980
|
+
const visibleHeight = bodyEl.clientHeight;
|
|
981
|
+
const visibleWidth = bodyEl.clientWidth;
|
|
982
|
+
const parentWrapperScrollLeft = parentWrapperEl.scrollLeft;
|
|
983
|
+
const parentWrapperScrollTop = parentWrapperEl.scrollTop;
|
|
984
|
+
const parentWrapperOffsetLeft = parentWrapperRect.left;
|
|
985
|
+
const parentWrapperOffsetTop = parentWrapperRect.top;
|
|
986
|
+
const targetLeft = targetRect.left;
|
|
987
|
+
const targetTop = targetRect.top;
|
|
988
|
+
minWidth = targetElem.offsetWidth;
|
|
989
|
+
if (teleportTo) {
|
|
990
|
+
left = (defaultLeft || (targetLeft - (panelWidth - targetWidth) / 2)) - parentWrapperScrollLeft;
|
|
991
|
+
top = (defaultTop || (targetTop + targetHeight)) - parentWrapperScrollTop;
|
|
992
|
+
if (placement === 'top') {
|
|
993
|
+
panelPlacement = 'top';
|
|
994
|
+
top = targetTop - panelHeight;
|
|
995
|
+
}
|
|
996
|
+
else if (!placement) {
|
|
997
|
+
if (defaultPlacement === 'top') {
|
|
998
|
+
panelPlacement = 'top';
|
|
999
|
+
if (!defaultTop) {
|
|
1000
|
+
top = targetTop - panelHeight;
|
|
1001
|
+
}
|
|
1002
|
+
// 如果上面不够放,则向下
|
|
1003
|
+
if (top < marginSize) {
|
|
1004
|
+
panelPlacement = 'bottom';
|
|
1005
|
+
top = targetTop + targetHeight;
|
|
1006
|
+
}
|
|
1007
|
+
// 如果下面不够放,则向上(优先)
|
|
1008
|
+
if (top + panelHeight + marginSize > visibleHeight) {
|
|
1009
|
+
panelPlacement = 'top';
|
|
1010
|
+
top = targetTop - panelHeight;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
else {
|
|
1014
|
+
// 如果下面不够放,则向上
|
|
1015
|
+
if (top + panelHeight + marginSize > visibleHeight) {
|
|
1016
|
+
panelPlacement = 'top';
|
|
1017
|
+
top = targetTop - panelHeight;
|
|
1018
|
+
}
|
|
1019
|
+
// 如果上面不够放,则向下(优先)
|
|
1020
|
+
if (top < marginSize) {
|
|
1021
|
+
panelPlacement = 'bottom';
|
|
1022
|
+
top = targetTop + targetHeight;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
// 如果溢出右边
|
|
1027
|
+
if (left + panelWidth + marginSize > visibleWidth) {
|
|
1028
|
+
left -= left + panelWidth + marginSize - visibleWidth;
|
|
1029
|
+
}
|
|
1030
|
+
// 如果溢出左边
|
|
1031
|
+
if (left < marginSize) {
|
|
1032
|
+
left = marginSize;
|
|
1033
|
+
}
|
|
1034
|
+
// 偏移
|
|
1035
|
+
top -= parentWrapperOffsetTop;
|
|
1036
|
+
left -= parentWrapperOffsetLeft;
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
if (placement === 'top') {
|
|
1040
|
+
panelPlacement = 'top';
|
|
1041
|
+
bottom = targetHeight;
|
|
1042
|
+
}
|
|
1043
|
+
else if (!placement) {
|
|
1044
|
+
// 如果下面不够放,则向上
|
|
1045
|
+
top = targetHeight;
|
|
1046
|
+
if (targetTop + targetHeight + panelHeight + marginSize > visibleHeight) {
|
|
1047
|
+
// 如果上面不够放,则向下(优先)
|
|
1048
|
+
if (targetTop - targetHeight - panelHeight > marginSize) {
|
|
1049
|
+
panelPlacement = 'top';
|
|
1050
|
+
top = '';
|
|
1051
|
+
bottom = targetHeight;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
// 是否超出右侧
|
|
1056
|
+
if (panelRect.left + panelRect.width + marginSize > visibleWidth) {
|
|
1057
|
+
left = -(panelRect.left + panelRect.width + marginSize - visibleWidth);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
if (XEUtils.isNumber(top)) {
|
|
1061
|
+
stys.top = top + 'px';
|
|
1062
|
+
}
|
|
1063
|
+
if (XEUtils.isNumber(bottom)) {
|
|
1064
|
+
stys.bottom = bottom + 'px';
|
|
1065
|
+
}
|
|
1066
|
+
if (XEUtils.isNumber(left)) {
|
|
1067
|
+
stys.left = left + 'px';
|
|
1068
|
+
}
|
|
1069
|
+
if (isMinWidth && XEUtils.isNumber(minWidth)) {
|
|
1070
|
+
stys.minWidth = minWidth + 'px';
|
|
1071
|
+
}
|
|
1072
|
+
// 箭头
|
|
1073
|
+
if (left === targetLeft) {
|
|
1074
|
+
if (targetWidth <= panelWidth) {
|
|
1075
|
+
arrowLeft = targetWidth / 2;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
else if (left < targetLeft) {
|
|
1079
|
+
if (left + panelWidth > targetLeft + targetWidth) {
|
|
1080
|
+
arrowLeft = (targetLeft - left) + targetWidth / 2;
|
|
1081
|
+
}
|
|
1082
|
+
else {
|
|
1083
|
+
arrowLeft = (targetLeft - left) + (panelWidth - (targetLeft - left)) / 2;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
return {
|
|
1089
|
+
top: top || 0,
|
|
1090
|
+
bottom: bottom || 0,
|
|
1091
|
+
left: left || 0,
|
|
1092
|
+
arrowLeft: arrowLeft || 0,
|
|
1093
|
+
style: stys,
|
|
1094
|
+
placement: panelPlacement
|
|
1095
|
+
};
|
|
1096
|
+
},
|
|
1097
|
+
/**
|
|
1098
|
+
* 获取包裹容器的元素
|
|
1099
|
+
*/
|
|
1100
|
+
getWrapperElement,
|
|
1101
|
+
/**
|
|
1102
|
+
* 获取插入到指定容器的元素或字符串
|
|
1103
|
+
*/
|
|
1104
|
+
getAppendSelector,
|
|
1105
|
+
/**
|
|
1106
|
+
* 获取插入到指定容器的元素
|
|
1107
|
+
*/
|
|
1108
|
+
getAppendElement
|
|
1109
|
+
};
|
|
1110
|
+
|
|
866
1111
|
const hooks = new Store();
|
|
867
1112
|
|
|
868
1113
|
function useSize(props) {
|
|
@@ -957,6 +1202,8 @@ const VxeUI = Object.assign(VxeCore, {
|
|
|
957
1202
|
permission,
|
|
958
1203
|
baseUtils,
|
|
959
1204
|
domUtils,
|
|
1205
|
+
scrollbarUtils,
|
|
1206
|
+
popperUtils,
|
|
960
1207
|
globalStore,
|
|
961
1208
|
hooks,
|
|
962
1209
|
component,
|
|
@@ -969,4 +1216,4 @@ const VxeUI = Object.assign(VxeCore, {
|
|
|
969
1216
|
});
|
|
970
1217
|
setTheme();
|
|
971
1218
|
|
|
972
|
-
export { GLOBAL_EVENT_KEYS, VxeCore, VxeUI, baseUtils, checkVersion, clipboard, commands, component, coreVersion, createEvent, VxeUI as default, domUtils, formats, getComponent, getConfig, getI18n, getIcon, getLanguage, getSlotVNs, getTheme, globalEvents, globalResize, globalStore, handleCheckInfo, hasComponent, hasLanguage, hooks, interceptor, log, menus, permission, renderCustomIcon, renderEmptyElement, renderGlobalIcon, renderer, setConfig, setI18n, setIcon, setLanguage, setTheme, use, useFns, usePermission, useSize, validators };
|
|
1219
|
+
export { GLOBAL_EVENT_KEYS, VxeCore, VxeUI, baseUtils, checkVersion, clipboard, commands, component, coreVersion, createEvent, VxeUI as default, domUtils, formats, getComponent, getConfig, getI18n, getIcon, getLanguage, getSlotVNs, getTheme, globalEvents, globalResize, globalStore, handleCheckInfo, hasComponent, hasLanguage, hooks, interceptor, log, menus, permission, popperUtils, renderCustomIcon, renderEmptyElement, renderGlobalIcon, renderer, scrollbarUtils, setConfig, setI18n, setIcon, setLanguage, setTheme, use, useFns, usePermission, useSize, validators };
|
package/es/index.esm.js
CHANGED
|
@@ -17,6 +17,8 @@ import { clipboard } from './src/clipboard';
|
|
|
17
17
|
import { permission } from './src/permission';
|
|
18
18
|
import { baseUtils } from './src/base-utils';
|
|
19
19
|
import { domUtils } from './src/dom-utils';
|
|
20
|
+
import { scrollbarUtils } from './src/scrollbar-utils';
|
|
21
|
+
import { popperUtils } from './src/popper-utils';
|
|
20
22
|
import { log } from './src/log';
|
|
21
23
|
import { hooks } from './src/hooks';
|
|
22
24
|
import { useFns } from './src/useFns';
|
|
@@ -92,6 +94,8 @@ export const VxeUI = Object.assign(VxeCore, {
|
|
|
92
94
|
permission,
|
|
93
95
|
baseUtils,
|
|
94
96
|
domUtils,
|
|
97
|
+
scrollbarUtils,
|
|
98
|
+
popperUtils,
|
|
95
99
|
globalStore,
|
|
96
100
|
hooks,
|
|
97
101
|
component,
|
|
@@ -120,6 +124,8 @@ export * from './src/clipboard';
|
|
|
120
124
|
export * from './src/permission';
|
|
121
125
|
export * from './src/base-utils';
|
|
122
126
|
export * from './src/dom-utils';
|
|
127
|
+
export * from './src/scrollbar-utils';
|
|
128
|
+
export * from './src/popper-utils';
|
|
123
129
|
export * from './src/dataStore';
|
|
124
130
|
export * from './src/useFns';
|
|
125
131
|
export * from './src/vm';
|
package/es/src/core.js
CHANGED
package/es/src/log.js
CHANGED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import XEUtils from 'xe-utils';
|
|
2
|
+
/**
|
|
3
|
+
* 获取包裹容器的元素
|
|
4
|
+
*/
|
|
5
|
+
function getWrapperElement(panelElem) {
|
|
6
|
+
if (!panelElem) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const bodyEl = document.body;
|
|
10
|
+
const parentEl = panelElem.parentElement;
|
|
11
|
+
return (parentEl === bodyEl ? document.documentElement : parentEl) || null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 获取插入到指定容器的元素或字符串
|
|
15
|
+
*/
|
|
16
|
+
function getAppendSelector(appendTo) {
|
|
17
|
+
const selectElem = appendTo && XEUtils.isFunction(appendTo) ? appendTo({}) : appendTo;
|
|
18
|
+
return selectElem || 'body';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 获取插入到指定容器的元素
|
|
22
|
+
*/
|
|
23
|
+
function getAppendElement(appendTo) {
|
|
24
|
+
const selectElem = getAppendSelector(appendTo);
|
|
25
|
+
if (XEUtils.isString(selectElem)) {
|
|
26
|
+
return document.querySelector(selectElem) || document.body;
|
|
27
|
+
}
|
|
28
|
+
return selectElem;
|
|
29
|
+
}
|
|
30
|
+
export const popperUtils = {
|
|
31
|
+
/**
|
|
32
|
+
* 更新位置
|
|
33
|
+
*/
|
|
34
|
+
updatePlacement(targetElem, panelElem, options) {
|
|
35
|
+
const { defaultTop, defaultLeft, placement, defaultPlacement, appendTo, teleportTo, marginSize, isMinWidth } = Object.assign({
|
|
36
|
+
appendTo: '',
|
|
37
|
+
teleportTo: false,
|
|
38
|
+
marginSize: 18,
|
|
39
|
+
isMinWidth: true
|
|
40
|
+
}, options);
|
|
41
|
+
let panelPlacement = 'bottom';
|
|
42
|
+
let top = '';
|
|
43
|
+
let bottom = '';
|
|
44
|
+
let left = 0;
|
|
45
|
+
let minWidth = '';
|
|
46
|
+
let arrowLeft = '';
|
|
47
|
+
const stys = {};
|
|
48
|
+
if (panelElem && targetElem) {
|
|
49
|
+
const bodyEl = document.body;
|
|
50
|
+
const parentWrapperEl = getWrapperElement(teleportTo ? getAppendElement(appendTo) : panelElem);
|
|
51
|
+
if (parentWrapperEl) {
|
|
52
|
+
const targetWidth = targetElem.offsetWidth;
|
|
53
|
+
const targetHeight = targetElem.offsetHeight;
|
|
54
|
+
const panelWidth = panelElem.offsetWidth;
|
|
55
|
+
const panelHeight = panelElem.offsetHeight;
|
|
56
|
+
const parentWrapperRect = parentWrapperEl.getBoundingClientRect();
|
|
57
|
+
const panelRect = panelElem.getBoundingClientRect();
|
|
58
|
+
const targetRect = targetElem.getBoundingClientRect();
|
|
59
|
+
const visibleHeight = bodyEl.clientHeight;
|
|
60
|
+
const visibleWidth = bodyEl.clientWidth;
|
|
61
|
+
const parentWrapperScrollLeft = parentWrapperEl.scrollLeft;
|
|
62
|
+
const parentWrapperScrollTop = parentWrapperEl.scrollTop;
|
|
63
|
+
const parentWrapperOffsetLeft = parentWrapperRect.left;
|
|
64
|
+
const parentWrapperOffsetTop = parentWrapperRect.top;
|
|
65
|
+
const targetLeft = targetRect.left;
|
|
66
|
+
const targetTop = targetRect.top;
|
|
67
|
+
minWidth = targetElem.offsetWidth;
|
|
68
|
+
if (teleportTo) {
|
|
69
|
+
left = (defaultLeft || (targetLeft - (panelWidth - targetWidth) / 2)) - parentWrapperScrollLeft;
|
|
70
|
+
top = (defaultTop || (targetTop + targetHeight)) - parentWrapperScrollTop;
|
|
71
|
+
if (placement === 'top') {
|
|
72
|
+
panelPlacement = 'top';
|
|
73
|
+
top = targetTop - panelHeight;
|
|
74
|
+
}
|
|
75
|
+
else if (!placement) {
|
|
76
|
+
if (defaultPlacement === 'top') {
|
|
77
|
+
panelPlacement = 'top';
|
|
78
|
+
if (!defaultTop) {
|
|
79
|
+
top = targetTop - panelHeight;
|
|
80
|
+
}
|
|
81
|
+
// 如果上面不够放,则向下
|
|
82
|
+
if (top < marginSize) {
|
|
83
|
+
panelPlacement = 'bottom';
|
|
84
|
+
top = targetTop + targetHeight;
|
|
85
|
+
}
|
|
86
|
+
// 如果下面不够放,则向上(优先)
|
|
87
|
+
if (top + panelHeight + marginSize > visibleHeight) {
|
|
88
|
+
panelPlacement = 'top';
|
|
89
|
+
top = targetTop - panelHeight;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// 如果下面不够放,则向上
|
|
94
|
+
if (top + panelHeight + marginSize > visibleHeight) {
|
|
95
|
+
panelPlacement = 'top';
|
|
96
|
+
top = targetTop - panelHeight;
|
|
97
|
+
}
|
|
98
|
+
// 如果上面不够放,则向下(优先)
|
|
99
|
+
if (top < marginSize) {
|
|
100
|
+
panelPlacement = 'bottom';
|
|
101
|
+
top = targetTop + targetHeight;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// 如果溢出右边
|
|
106
|
+
if (left + panelWidth + marginSize > visibleWidth) {
|
|
107
|
+
left -= left + panelWidth + marginSize - visibleWidth;
|
|
108
|
+
}
|
|
109
|
+
// 如果溢出左边
|
|
110
|
+
if (left < marginSize) {
|
|
111
|
+
left = marginSize;
|
|
112
|
+
}
|
|
113
|
+
// 偏移
|
|
114
|
+
top -= parentWrapperOffsetTop;
|
|
115
|
+
left -= parentWrapperOffsetLeft;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
if (placement === 'top') {
|
|
119
|
+
panelPlacement = 'top';
|
|
120
|
+
bottom = targetHeight;
|
|
121
|
+
}
|
|
122
|
+
else if (!placement) {
|
|
123
|
+
// 如果下面不够放,则向上
|
|
124
|
+
top = targetHeight;
|
|
125
|
+
if (targetTop + targetHeight + panelHeight + marginSize > visibleHeight) {
|
|
126
|
+
// 如果上面不够放,则向下(优先)
|
|
127
|
+
if (targetTop - targetHeight - panelHeight > marginSize) {
|
|
128
|
+
panelPlacement = 'top';
|
|
129
|
+
top = '';
|
|
130
|
+
bottom = targetHeight;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// 是否超出右侧
|
|
135
|
+
if (panelRect.left + panelRect.width + marginSize > visibleWidth) {
|
|
136
|
+
left = -(panelRect.left + panelRect.width + marginSize - visibleWidth);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (XEUtils.isNumber(top)) {
|
|
140
|
+
stys.top = top + 'px';
|
|
141
|
+
}
|
|
142
|
+
if (XEUtils.isNumber(bottom)) {
|
|
143
|
+
stys.bottom = bottom + 'px';
|
|
144
|
+
}
|
|
145
|
+
if (XEUtils.isNumber(left)) {
|
|
146
|
+
stys.left = left + 'px';
|
|
147
|
+
}
|
|
148
|
+
if (isMinWidth && XEUtils.isNumber(minWidth)) {
|
|
149
|
+
stys.minWidth = minWidth + 'px';
|
|
150
|
+
}
|
|
151
|
+
// 箭头
|
|
152
|
+
if (left === targetLeft) {
|
|
153
|
+
if (targetWidth <= panelWidth) {
|
|
154
|
+
arrowLeft = targetWidth / 2;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (left < targetLeft) {
|
|
158
|
+
if (left + panelWidth > targetLeft + targetWidth) {
|
|
159
|
+
arrowLeft = (targetLeft - left) + targetWidth / 2;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
arrowLeft = (targetLeft - left) + (panelWidth - (targetLeft - left)) / 2;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
top: top || 0,
|
|
169
|
+
bottom: bottom || 0,
|
|
170
|
+
left: left || 0,
|
|
171
|
+
arrowLeft: arrowLeft || 0,
|
|
172
|
+
style: stys,
|
|
173
|
+
placement: panelPlacement
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* 获取包裹容器的元素
|
|
178
|
+
*/
|
|
179
|
+
getWrapperElement,
|
|
180
|
+
/**
|
|
181
|
+
* 获取插入到指定容器的元素或字符串
|
|
182
|
+
*/
|
|
183
|
+
getAppendSelector,
|
|
184
|
+
/**
|
|
185
|
+
* 获取插入到指定容器的元素
|
|
186
|
+
*/
|
|
187
|
+
getAppendElement
|
|
188
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const scrollbarUtils = {
|
|
2
|
+
/**
|
|
3
|
+
* 计算滚动条滑块的长度
|
|
4
|
+
*/
|
|
5
|
+
getThumbSize(viewportSize, contentSize, trackSize) {
|
|
6
|
+
if (contentSize <= viewportSize) {
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
const ratio = viewportSize / contentSize;
|
|
10
|
+
const ideal = trackSize * ratio;
|
|
11
|
+
return Math.max(20, Math.min(ideal, trackSize));
|
|
12
|
+
},
|
|
13
|
+
/**
|
|
14
|
+
* 计算滚动条滑块的偏移位置
|
|
15
|
+
*/
|
|
16
|
+
getThumbOffsetSize(offsetSize, viewportSize, contentSize, trackSize, thumbSize) {
|
|
17
|
+
const maxScroll = contentSize - viewportSize;
|
|
18
|
+
if (maxScroll <= 0) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
const maxThumbOffset = trackSize - thumbSize;
|
|
22
|
+
if (maxThumbOffset <= 0) {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
const clamped = Math.min(Math.max(offsetSize, 0), maxScroll);
|
|
26
|
+
const ratio = clamped / maxScroll;
|
|
27
|
+
return ratio * maxThumbOffset;
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* 根据点击轨道的位置,计算滑块的偏移位置
|
|
31
|
+
*/
|
|
32
|
+
getScrollFromClick(clickPosition, viewportSize, contentSize, trackSize, thumbSize) {
|
|
33
|
+
const maxThumbOffset = trackSize - thumbSize;
|
|
34
|
+
const maxScroll = contentSize - viewportSize;
|
|
35
|
+
if (maxScroll <= 0 || maxThumbOffset <= 0) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
let thumbOffset = clickPosition - thumbSize / 2;
|
|
39
|
+
thumbOffset = Math.min(Math.max(thumbOffset, 0), maxThumbOffset);
|
|
40
|
+
const scrollOffset = (thumbOffset / maxThumbOffset) * maxScroll;
|
|
41
|
+
return scrollOffset;
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* 拖拽 thumb 时,根据鼠标位置计算滑块的偏移位置
|
|
45
|
+
*/
|
|
46
|
+
getScrollFromDrag(pointerPosition, dragOffset, viewportSize, contentSize, trackSize, thumbSize) {
|
|
47
|
+
const maxScroll = contentSize - viewportSize;
|
|
48
|
+
const maxThumbOffset = trackSize - thumbSize;
|
|
49
|
+
if (maxScroll <= 0 || maxThumbOffset <= 0) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
let thumbOffset = pointerPosition - dragOffset;
|
|
53
|
+
thumbOffset = Math.min(Math.max(thumbOffset, 0), maxThumbOffset);
|
|
54
|
+
return (thumbOffset / maxThumbOffset) * maxScroll;
|
|
55
|
+
}
|
|
56
|
+
};
|
package/lib/index.common.js
CHANGED
|
@@ -237,6 +237,30 @@ Object.keys(_domUtils).forEach(function (key) {
|
|
|
237
237
|
}
|
|
238
238
|
});
|
|
239
239
|
});
|
|
240
|
+
var _scrollbarUtils = require("./src/scrollbar-utils");
|
|
241
|
+
Object.keys(_scrollbarUtils).forEach(function (key) {
|
|
242
|
+
if (key === "default" || key === "__esModule") return;
|
|
243
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
244
|
+
if (key in exports && exports[key] === _scrollbarUtils[key]) return;
|
|
245
|
+
Object.defineProperty(exports, key, {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
get: function () {
|
|
248
|
+
return _scrollbarUtils[key];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
var _popperUtils = require("./src/popper-utils");
|
|
253
|
+
Object.keys(_popperUtils).forEach(function (key) {
|
|
254
|
+
if (key === "default" || key === "__esModule") return;
|
|
255
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
256
|
+
if (key in exports && exports[key] === _popperUtils[key]) return;
|
|
257
|
+
Object.defineProperty(exports, key, {
|
|
258
|
+
enumerable: true,
|
|
259
|
+
get: function () {
|
|
260
|
+
return _popperUtils[key];
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
});
|
|
240
264
|
var _log = require("./src/log");
|
|
241
265
|
Object.keys(_log).forEach(function (key) {
|
|
242
266
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -357,6 +381,8 @@ const VxeUI = exports.VxeUI = Object.assign(_core.VxeCore, {
|
|
|
357
381
|
permission: _permission.permission,
|
|
358
382
|
baseUtils: _baseUtils.baseUtils,
|
|
359
383
|
domUtils: _domUtils.domUtils,
|
|
384
|
+
scrollbarUtils: _scrollbarUtils.scrollbarUtils,
|
|
385
|
+
popperUtils: _popperUtils.popperUtils,
|
|
360
386
|
globalStore: _dataStore.globalStore,
|
|
361
387
|
hooks: _hooks.hooks,
|
|
362
388
|
component,
|