@vxe-ui/core 4.4.31 → 4.4.33
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 +263 -3
- package/es/index.esm.js +3 -0
- package/es/src/base-utils.js +15 -0
- package/es/src/core.js +1 -1
- package/es/src/dom-utils.js +56 -0
- 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 +269 -2
- package/lib/index.umd.min.js +1 -1
- package/lib/src/base-utils.js +15 -0
- package/lib/src/base-utils.min.js +1 -1
- package/lib/src/core.js +1 -1
- package/lib/src/core.min.js +1 -1
- package/lib/src/dom-utils.js +56 -0
- package/lib/src/dom-utils.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/base-utils.ts +15 -0
- package/packages/src/dom-utils.ts +60 -0
- package/packages/src/popper-utils.ts +194 -0
- package/types/core/base-utils.d.ts +18 -0
- package/types/core/dom-utils.d.ts +28 -0
- package/types/core/index.d.ts +7 -0
- package/types/core/popper-utils.d.ts +44 -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.33";
|
|
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.33";
|
|
406
406
|
const log = {
|
|
407
407
|
create: createLog,
|
|
408
408
|
warn: createLog('warn', `v${version}`),
|
|
@@ -837,10 +837,81 @@ const baseUtils = {
|
|
|
837
837
|
*/
|
|
838
838
|
getDefVal(value, defVal) {
|
|
839
839
|
return XEUtils.eqNull(value) ? defVal : value;
|
|
840
|
+
},
|
|
841
|
+
/**
|
|
842
|
+
* 判断是否启用
|
|
843
|
+
*/
|
|
844
|
+
isEnabled(conf) {
|
|
845
|
+
return !!(conf && conf.enabled !== false);
|
|
846
|
+
},
|
|
847
|
+
/**
|
|
848
|
+
* 用于开关类型的配置项
|
|
849
|
+
* 局部启用规则:conf={}
|
|
850
|
+
* 局部禁用规则:conf={enabled:false}
|
|
851
|
+
* 全局默认启用规则:conf.enabled=true
|
|
852
|
+
*/
|
|
853
|
+
hasEnableConf(conf, opts) {
|
|
854
|
+
return !!(opts && (conf ? opts.enabled !== false : opts.enabled));
|
|
840
855
|
}
|
|
841
856
|
};
|
|
842
857
|
|
|
858
|
+
const reClsMap = {};
|
|
859
|
+
function getClsRE(cls) {
|
|
860
|
+
if (!reClsMap[cls]) {
|
|
861
|
+
reClsMap[cls] = new RegExp(`(?:^|\\s)${cls}(?!\\S)`, 'g');
|
|
862
|
+
}
|
|
863
|
+
return reClsMap[cls];
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* 判断元素是否包含 class
|
|
867
|
+
*/
|
|
868
|
+
function hasClass(elem, cls) {
|
|
869
|
+
if (elem) {
|
|
870
|
+
if (elem.classList) {
|
|
871
|
+
return elem.classList.contains(cls);
|
|
872
|
+
}
|
|
873
|
+
return !!(elem.className && elem.className.match && elem.className.match(getClsRE(cls)));
|
|
874
|
+
}
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* 给元素删除 class
|
|
879
|
+
*/
|
|
880
|
+
function removeClass(elem, cls) {
|
|
881
|
+
if (elem && hasClass(elem, cls)) {
|
|
882
|
+
elem.className = elem.className.replace(getClsRE(cls), '');
|
|
883
|
+
}
|
|
884
|
+
}
|
|
843
885
|
const domUtils = {
|
|
886
|
+
/**
|
|
887
|
+
* 判断是否像素px单位 '100px' | 100
|
|
888
|
+
*/
|
|
889
|
+
isPx(val) {
|
|
890
|
+
return val && /^\d+(\.\d+)?(px)?$/.test(val);
|
|
891
|
+
},
|
|
892
|
+
/**
|
|
893
|
+
* 判断是否百分比%单位 '100%'
|
|
894
|
+
*/
|
|
895
|
+
isScale(val) {
|
|
896
|
+
return val && /^\d+(\.\d+)?%$/.test(val);
|
|
897
|
+
},
|
|
898
|
+
/**
|
|
899
|
+
* 判断元素是否包含 class
|
|
900
|
+
*/
|
|
901
|
+
hasClass,
|
|
902
|
+
/**
|
|
903
|
+
* 给元素删除 class
|
|
904
|
+
*/
|
|
905
|
+
removeClass,
|
|
906
|
+
/**
|
|
907
|
+
* 给元素增加 class
|
|
908
|
+
*/
|
|
909
|
+
addClass(elem, cls) {
|
|
910
|
+
if (elem && !hasClass(elem, cls)) {
|
|
911
|
+
removeClass(elem, cls);
|
|
912
|
+
elem.className = elem.className + ' ' + cls;
|
|
913
|
+
}
|
|
914
|
+
},
|
|
844
915
|
/**
|
|
845
916
|
* 生成 className
|
|
846
917
|
*/
|
|
@@ -920,6 +991,194 @@ const scrollbarUtils = {
|
|
|
920
991
|
}
|
|
921
992
|
};
|
|
922
993
|
|
|
994
|
+
/**
|
|
995
|
+
* 获取包裹容器的元素
|
|
996
|
+
*/
|
|
997
|
+
function getWrapperElement(panelElem) {
|
|
998
|
+
if (!panelElem) {
|
|
999
|
+
return null;
|
|
1000
|
+
}
|
|
1001
|
+
const bodyEl = document.body;
|
|
1002
|
+
const parentEl = panelElem.parentElement;
|
|
1003
|
+
return (parentEl === bodyEl ? document.documentElement : parentEl) || null;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* 获取插入到指定容器的元素或字符串
|
|
1007
|
+
*/
|
|
1008
|
+
function getAppendSelector(appendTo) {
|
|
1009
|
+
const selectElem = appendTo && XEUtils.isFunction(appendTo) ? appendTo({}) : appendTo;
|
|
1010
|
+
return selectElem || 'body';
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* 获取插入到指定容器的元素
|
|
1014
|
+
*/
|
|
1015
|
+
function getAppendElement(appendTo) {
|
|
1016
|
+
const selectElem = getAppendSelector(appendTo);
|
|
1017
|
+
if (XEUtils.isString(selectElem)) {
|
|
1018
|
+
return document.querySelector(selectElem) || document.body;
|
|
1019
|
+
}
|
|
1020
|
+
return selectElem;
|
|
1021
|
+
}
|
|
1022
|
+
const popperUtils = {
|
|
1023
|
+
/**
|
|
1024
|
+
* 更新位置
|
|
1025
|
+
*/
|
|
1026
|
+
updatePlacement(targetElem, panelElem, options) {
|
|
1027
|
+
const { defaultTop, defaultLeft, placement, defaultPlacement, appendTo, teleportTo, marginSize, isMinWidth } = Object.assign({
|
|
1028
|
+
appendTo: '',
|
|
1029
|
+
teleportTo: false,
|
|
1030
|
+
marginSize: 18,
|
|
1031
|
+
isMinWidth: true
|
|
1032
|
+
}, options);
|
|
1033
|
+
let panelPlacement = 'bottom';
|
|
1034
|
+
let top = '';
|
|
1035
|
+
let bottom = '';
|
|
1036
|
+
let left = 0;
|
|
1037
|
+
let minWidth = '';
|
|
1038
|
+
let arrowLeft = '';
|
|
1039
|
+
const stys = {};
|
|
1040
|
+
if (panelElem && targetElem) {
|
|
1041
|
+
const bodyEl = document.body;
|
|
1042
|
+
const parentWrapperEl = getWrapperElement(teleportTo ? getAppendElement(appendTo) : panelElem);
|
|
1043
|
+
if (parentWrapperEl) {
|
|
1044
|
+
const targetWidth = targetElem.offsetWidth;
|
|
1045
|
+
const targetHeight = targetElem.offsetHeight;
|
|
1046
|
+
const panelWidth = panelElem.offsetWidth;
|
|
1047
|
+
const panelHeight = panelElem.offsetHeight;
|
|
1048
|
+
const parentWrapperRect = parentWrapperEl.getBoundingClientRect();
|
|
1049
|
+
const panelRect = panelElem.getBoundingClientRect();
|
|
1050
|
+
const targetRect = targetElem.getBoundingClientRect();
|
|
1051
|
+
const visibleHeight = bodyEl.clientHeight;
|
|
1052
|
+
const visibleWidth = bodyEl.clientWidth;
|
|
1053
|
+
const parentWrapperScrollLeft = parentWrapperEl.scrollLeft;
|
|
1054
|
+
const parentWrapperScrollTop = parentWrapperEl.scrollTop;
|
|
1055
|
+
const parentWrapperOffsetLeft = parentWrapperRect.left;
|
|
1056
|
+
const parentWrapperOffsetTop = parentWrapperRect.top;
|
|
1057
|
+
const targetLeft = targetRect.left;
|
|
1058
|
+
const targetTop = targetRect.top;
|
|
1059
|
+
minWidth = targetElem.offsetWidth;
|
|
1060
|
+
if (teleportTo) {
|
|
1061
|
+
left = (defaultLeft || (targetLeft - (panelWidth - targetWidth) / 2)) - parentWrapperScrollLeft;
|
|
1062
|
+
top = (defaultTop || (targetTop + targetHeight)) - parentWrapperScrollTop;
|
|
1063
|
+
if (placement === 'top') {
|
|
1064
|
+
panelPlacement = 'top';
|
|
1065
|
+
top = targetTop - panelHeight;
|
|
1066
|
+
}
|
|
1067
|
+
else if (!placement) {
|
|
1068
|
+
if (defaultPlacement === 'top') {
|
|
1069
|
+
panelPlacement = 'top';
|
|
1070
|
+
if (!defaultTop) {
|
|
1071
|
+
top = targetTop - panelHeight;
|
|
1072
|
+
}
|
|
1073
|
+
// 如果上面不够放,则向下
|
|
1074
|
+
if (top < marginSize) {
|
|
1075
|
+
panelPlacement = 'bottom';
|
|
1076
|
+
top = targetTop + targetHeight;
|
|
1077
|
+
}
|
|
1078
|
+
// 如果下面不够放,则向上(优先)
|
|
1079
|
+
if (top + panelHeight + marginSize > visibleHeight) {
|
|
1080
|
+
panelPlacement = 'top';
|
|
1081
|
+
top = targetTop - panelHeight;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
else {
|
|
1085
|
+
// 如果下面不够放,则向上
|
|
1086
|
+
if (top + panelHeight + marginSize > visibleHeight) {
|
|
1087
|
+
panelPlacement = 'top';
|
|
1088
|
+
top = targetTop - panelHeight;
|
|
1089
|
+
}
|
|
1090
|
+
// 如果上面不够放,则向下(优先)
|
|
1091
|
+
if (top < marginSize) {
|
|
1092
|
+
panelPlacement = 'bottom';
|
|
1093
|
+
top = targetTop + targetHeight;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
// 如果溢出右边
|
|
1098
|
+
if (left + panelWidth + marginSize > visibleWidth) {
|
|
1099
|
+
left -= left + panelWidth + marginSize - visibleWidth;
|
|
1100
|
+
}
|
|
1101
|
+
// 如果溢出左边
|
|
1102
|
+
if (left < marginSize) {
|
|
1103
|
+
left = marginSize;
|
|
1104
|
+
}
|
|
1105
|
+
// 偏移
|
|
1106
|
+
top -= parentWrapperOffsetTop;
|
|
1107
|
+
left -= parentWrapperOffsetLeft;
|
|
1108
|
+
}
|
|
1109
|
+
else {
|
|
1110
|
+
if (placement === 'top') {
|
|
1111
|
+
panelPlacement = 'top';
|
|
1112
|
+
bottom = targetHeight;
|
|
1113
|
+
}
|
|
1114
|
+
else if (!placement) {
|
|
1115
|
+
// 如果下面不够放,则向上
|
|
1116
|
+
top = targetHeight;
|
|
1117
|
+
if (targetTop + targetHeight + panelHeight + marginSize > visibleHeight) {
|
|
1118
|
+
// 如果上面不够放,则向下(优先)
|
|
1119
|
+
if (targetTop - targetHeight - panelHeight > marginSize) {
|
|
1120
|
+
panelPlacement = 'top';
|
|
1121
|
+
top = '';
|
|
1122
|
+
bottom = targetHeight;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
// 是否超出右侧
|
|
1127
|
+
if (panelRect.left + panelRect.width + marginSize > visibleWidth) {
|
|
1128
|
+
left = -(panelRect.left + panelRect.width + marginSize - visibleWidth);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
if (XEUtils.isNumber(top)) {
|
|
1132
|
+
stys.top = top + 'px';
|
|
1133
|
+
}
|
|
1134
|
+
if (XEUtils.isNumber(bottom)) {
|
|
1135
|
+
stys.bottom = bottom + 'px';
|
|
1136
|
+
}
|
|
1137
|
+
if (XEUtils.isNumber(left)) {
|
|
1138
|
+
stys.left = left + 'px';
|
|
1139
|
+
}
|
|
1140
|
+
if (isMinWidth && XEUtils.isNumber(minWidth)) {
|
|
1141
|
+
stys.minWidth = minWidth + 'px';
|
|
1142
|
+
}
|
|
1143
|
+
// 箭头
|
|
1144
|
+
if (left === targetLeft) {
|
|
1145
|
+
if (targetWidth <= panelWidth) {
|
|
1146
|
+
arrowLeft = targetWidth / 2;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
else if (left < targetLeft) {
|
|
1150
|
+
if (left + panelWidth > targetLeft + targetWidth) {
|
|
1151
|
+
arrowLeft = (targetLeft - left) + targetWidth / 2;
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
arrowLeft = (targetLeft - left) + (panelWidth - (targetLeft - left)) / 2;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return {
|
|
1160
|
+
top: top || 0,
|
|
1161
|
+
bottom: bottom || 0,
|
|
1162
|
+
left: left || 0,
|
|
1163
|
+
arrowLeft: arrowLeft || 0,
|
|
1164
|
+
style: stys,
|
|
1165
|
+
placement: panelPlacement
|
|
1166
|
+
};
|
|
1167
|
+
},
|
|
1168
|
+
/**
|
|
1169
|
+
* 获取包裹容器的元素
|
|
1170
|
+
*/
|
|
1171
|
+
getWrapperElement,
|
|
1172
|
+
/**
|
|
1173
|
+
* 获取插入到指定容器的元素或字符串
|
|
1174
|
+
*/
|
|
1175
|
+
getAppendSelector,
|
|
1176
|
+
/**
|
|
1177
|
+
* 获取插入到指定容器的元素
|
|
1178
|
+
*/
|
|
1179
|
+
getAppendElement
|
|
1180
|
+
};
|
|
1181
|
+
|
|
923
1182
|
const hooks = new Store();
|
|
924
1183
|
|
|
925
1184
|
function useSize(props) {
|
|
@@ -1015,6 +1274,7 @@ const VxeUI = Object.assign(VxeCore, {
|
|
|
1015
1274
|
baseUtils,
|
|
1016
1275
|
domUtils,
|
|
1017
1276
|
scrollbarUtils,
|
|
1277
|
+
popperUtils,
|
|
1018
1278
|
globalStore,
|
|
1019
1279
|
hooks,
|
|
1020
1280
|
component,
|
|
@@ -1027,4 +1287,4 @@ const VxeUI = Object.assign(VxeCore, {
|
|
|
1027
1287
|
});
|
|
1028
1288
|
setTheme();
|
|
1029
1289
|
|
|
1030
|
-
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, scrollbarUtils, setConfig, setI18n, setIcon, setLanguage, setTheme, use, useFns, usePermission, useSize, validators };
|
|
1290
|
+
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
|
@@ -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';
|
|
@@ -94,6 +95,7 @@ export const VxeUI = Object.assign(VxeCore, {
|
|
|
94
95
|
baseUtils,
|
|
95
96
|
domUtils,
|
|
96
97
|
scrollbarUtils,
|
|
98
|
+
popperUtils,
|
|
97
99
|
globalStore,
|
|
98
100
|
hooks,
|
|
99
101
|
component,
|
|
@@ -123,6 +125,7 @@ export * from './src/permission';
|
|
|
123
125
|
export * from './src/base-utils';
|
|
124
126
|
export * from './src/dom-utils';
|
|
125
127
|
export * from './src/scrollbar-utils';
|
|
128
|
+
export * from './src/popper-utils';
|
|
126
129
|
export * from './src/dataStore';
|
|
127
130
|
export * from './src/useFns';
|
|
128
131
|
export * from './src/vm';
|
package/es/src/base-utils.js
CHANGED
|
@@ -20,5 +20,20 @@ export const baseUtils = {
|
|
|
20
20
|
*/
|
|
21
21
|
getDefVal(value, defVal) {
|
|
22
22
|
return XEUtils.eqNull(value) ? defVal : value;
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* 判断是否启用
|
|
26
|
+
*/
|
|
27
|
+
isEnabled(conf) {
|
|
28
|
+
return !!(conf && conf.enabled !== false);
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* 用于开关类型的配置项
|
|
32
|
+
* 局部启用规则:conf={}
|
|
33
|
+
* 局部禁用规则:conf={enabled:false}
|
|
34
|
+
* 全局默认启用规则:conf.enabled=true
|
|
35
|
+
*/
|
|
36
|
+
hasEnableConf(conf, opts) {
|
|
37
|
+
return !!(opts && (conf ? opts.enabled !== false : opts.enabled));
|
|
23
38
|
}
|
|
24
39
|
};
|
package/es/src/core.js
CHANGED
package/es/src/dom-utils.js
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
import XEUtils from 'xe-utils';
|
|
2
|
+
const reClsMap = {};
|
|
3
|
+
function getClsRE(cls) {
|
|
4
|
+
if (!reClsMap[cls]) {
|
|
5
|
+
reClsMap[cls] = new RegExp(`(?:^|\\s)${cls}(?!\\S)`, 'g');
|
|
6
|
+
}
|
|
7
|
+
return reClsMap[cls];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 判断元素是否包含 class
|
|
11
|
+
*/
|
|
12
|
+
function hasClass(elem, cls) {
|
|
13
|
+
if (elem) {
|
|
14
|
+
if (elem.classList) {
|
|
15
|
+
return elem.classList.contains(cls);
|
|
16
|
+
}
|
|
17
|
+
return !!(elem.className && elem.className.match && elem.className.match(getClsRE(cls)));
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 给元素删除 class
|
|
23
|
+
*/
|
|
24
|
+
function removeClass(elem, cls) {
|
|
25
|
+
if (elem && hasClass(elem, cls)) {
|
|
26
|
+
elem.className = elem.className.replace(getClsRE(cls), '');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
2
29
|
export const domUtils = {
|
|
30
|
+
/**
|
|
31
|
+
* 判断是否像素px单位 '100px' | 100
|
|
32
|
+
*/
|
|
33
|
+
isPx(val) {
|
|
34
|
+
return val && /^\d+(\.\d+)?(px)?$/.test(val);
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* 判断是否百分比%单位 '100%'
|
|
38
|
+
*/
|
|
39
|
+
isScale(val) {
|
|
40
|
+
return val && /^\d+(\.\d+)?%$/.test(val);
|
|
41
|
+
},
|
|
42
|
+
/**
|
|
43
|
+
* 判断元素是否包含 class
|
|
44
|
+
*/
|
|
45
|
+
hasClass,
|
|
46
|
+
/**
|
|
47
|
+
* 给元素删除 class
|
|
48
|
+
*/
|
|
49
|
+
removeClass,
|
|
50
|
+
/**
|
|
51
|
+
* 给元素增加 class
|
|
52
|
+
*/
|
|
53
|
+
addClass(elem, cls) {
|
|
54
|
+
if (elem && !hasClass(elem, cls)) {
|
|
55
|
+
removeClass(elem, cls);
|
|
56
|
+
elem.className = elem.className + ' ' + cls;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
3
59
|
/**
|
|
4
60
|
* 生成 className
|
|
5
61
|
*/
|
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
|
+
};
|
package/lib/index.common.js
CHANGED
|
@@ -249,6 +249,18 @@ Object.keys(_scrollbarUtils).forEach(function (key) {
|
|
|
249
249
|
}
|
|
250
250
|
});
|
|
251
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
|
+
});
|
|
252
264
|
var _log = require("./src/log");
|
|
253
265
|
Object.keys(_log).forEach(function (key) {
|
|
254
266
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -370,6 +382,7 @@ const VxeUI = exports.VxeUI = Object.assign(_core.VxeCore, {
|
|
|
370
382
|
baseUtils: _baseUtils.baseUtils,
|
|
371
383
|
domUtils: _domUtils.domUtils,
|
|
372
384
|
scrollbarUtils: _scrollbarUtils.scrollbarUtils,
|
|
385
|
+
popperUtils: _popperUtils.popperUtils,
|
|
373
386
|
globalStore: _dataStore.globalStore,
|
|
374
387
|
hooks: _hooks.hooks,
|
|
375
388
|
component,
|