@whitesev/pops 2.3.3 → 2.3.4
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/index.amd.js +257 -122
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +257 -122
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +257 -122
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +257 -122
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +257 -122
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +257 -122
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Pops.d.ts +14 -8
- package/dist/types/src/components/searchSuggestion/index.d.ts +16 -7
- package/dist/types/src/components/searchSuggestion/types/index.d.ts +21 -10
- package/dist/types/src/utils/PopsDOMUtils.d.ts +14 -6
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1819,11 +1819,11 @@
|
|
|
1819
1819
|
}
|
|
1820
1820
|
/**
|
|
1821
1821
|
* 添加className
|
|
1822
|
-
* @param
|
|
1822
|
+
* @param $el 目标元素
|
|
1823
1823
|
* @param className className属性
|
|
1824
1824
|
*/
|
|
1825
|
-
addClassName(
|
|
1826
|
-
if (
|
|
1825
|
+
addClassName($el, className) {
|
|
1826
|
+
if ($el == null) {
|
|
1827
1827
|
return;
|
|
1828
1828
|
}
|
|
1829
1829
|
if (typeof className !== "string") {
|
|
@@ -1832,15 +1832,16 @@
|
|
|
1832
1832
|
if (className.trim() === "") {
|
|
1833
1833
|
return;
|
|
1834
1834
|
}
|
|
1835
|
-
|
|
1835
|
+
const classNameList = className.split(" ").filter((item) => item.trim() !== "");
|
|
1836
|
+
$el.classList.add(...classNameList);
|
|
1836
1837
|
}
|
|
1837
1838
|
/**
|
|
1838
1839
|
* 删除className
|
|
1839
|
-
* @param
|
|
1840
|
+
* @param $el 目标元素
|
|
1840
1841
|
* @param className className属性
|
|
1841
1842
|
*/
|
|
1842
|
-
removeClassName(
|
|
1843
|
-
if (
|
|
1843
|
+
removeClassName($el, className) {
|
|
1844
|
+
if ($el == null) {
|
|
1844
1845
|
return;
|
|
1845
1846
|
}
|
|
1846
1847
|
if (typeof className !== "string") {
|
|
@@ -1849,15 +1850,16 @@
|
|
|
1849
1850
|
if (className.trim() === "") {
|
|
1850
1851
|
return;
|
|
1851
1852
|
}
|
|
1852
|
-
|
|
1853
|
+
const classNameList = className.split(" ").filter((item) => item.trim() !== "");
|
|
1854
|
+
$el.classList.remove(...classNameList);
|
|
1853
1855
|
}
|
|
1854
1856
|
/**
|
|
1855
1857
|
* 判断元素是否包含某个className
|
|
1856
|
-
* @param
|
|
1858
|
+
* @param $el 目标元素
|
|
1857
1859
|
* @param className className属性
|
|
1858
1860
|
*/
|
|
1859
|
-
containsClassName(
|
|
1860
|
-
if (
|
|
1861
|
+
containsClassName($el, className) {
|
|
1862
|
+
if ($el == null) {
|
|
1861
1863
|
return false;
|
|
1862
1864
|
}
|
|
1863
1865
|
if (typeof className !== "string") {
|
|
@@ -1866,7 +1868,7 @@
|
|
|
1866
1868
|
if (className.trim() === "") {
|
|
1867
1869
|
return false;
|
|
1868
1870
|
}
|
|
1869
|
-
return
|
|
1871
|
+
return $el.classList.contains(className);
|
|
1870
1872
|
}
|
|
1871
1873
|
css(element, property, value) {
|
|
1872
1874
|
/**
|
|
@@ -2489,6 +2491,24 @@
|
|
|
2489
2491
|
}
|
|
2490
2492
|
return useChangeColor();
|
|
2491
2493
|
}
|
|
2494
|
+
/**
|
|
2495
|
+
* 获取移动元素的transform偏移
|
|
2496
|
+
* @param element 元素
|
|
2497
|
+
*/
|
|
2498
|
+
getTransform(element) {
|
|
2499
|
+
let transform_left = 0;
|
|
2500
|
+
let transform_top = 0;
|
|
2501
|
+
let elementTransform = PopsCore.globalThis.getComputedStyle(element).transform;
|
|
2502
|
+
if (elementTransform !== "none" && elementTransform != null && elementTransform !== "") {
|
|
2503
|
+
let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
|
|
2504
|
+
transform_left = Math.abs(parseInt(elementTransformSplit[4]));
|
|
2505
|
+
transform_top = Math.abs(parseInt(elementTransformSplit[5]));
|
|
2506
|
+
}
|
|
2507
|
+
return {
|
|
2508
|
+
transformLeft: transform_left,
|
|
2509
|
+
transformTop: transform_top,
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2492
2512
|
}
|
|
2493
2513
|
const popsDOMUtils = new PopsDOMUtils();
|
|
2494
2514
|
|
|
@@ -3288,23 +3308,6 @@
|
|
|
3288
3308
|
popsDOMUtils.css(options.dragElement, {
|
|
3289
3309
|
cursor: "move",
|
|
3290
3310
|
});
|
|
3291
|
-
/**
|
|
3292
|
-
* 获取移动元素的transform偏移
|
|
3293
|
-
*/
|
|
3294
|
-
function getTransform(element) {
|
|
3295
|
-
let transform_left = 0;
|
|
3296
|
-
let transform_top = 0;
|
|
3297
|
-
let elementTransform = PopsCore.globalThis.getComputedStyle(element).transform;
|
|
3298
|
-
if (elementTransform !== "none" && elementTransform != null && elementTransform !== "") {
|
|
3299
|
-
let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
|
|
3300
|
-
transform_left = Math.abs(parseInt(elementTransformSplit[4]));
|
|
3301
|
-
transform_top = Math.abs(parseInt(elementTransformSplit[5]));
|
|
3302
|
-
}
|
|
3303
|
-
return {
|
|
3304
|
-
transformLeft: transform_left,
|
|
3305
|
-
transformTop: transform_top,
|
|
3306
|
-
};
|
|
3307
|
-
}
|
|
3308
3311
|
/**
|
|
3309
3312
|
* 修改移动的元素的style
|
|
3310
3313
|
*/
|
|
@@ -3346,9 +3349,8 @@
|
|
|
3346
3349
|
};
|
|
3347
3350
|
}
|
|
3348
3351
|
}
|
|
3349
|
-
|
|
3350
|
-
let
|
|
3351
|
-
let transformTop = transformInfo.transformTop;
|
|
3352
|
+
// 获取transform偏移
|
|
3353
|
+
let transformInfo = popsDOMUtils.getTransform(moveElement);
|
|
3352
3354
|
let resumeMoveElementStyle = null;
|
|
3353
3355
|
anyTouchElement.on("pan", function (event) {
|
|
3354
3356
|
if (!isMove) {
|
|
@@ -3356,9 +3358,7 @@
|
|
|
3356
3358
|
let rect = options.dragElement.getBoundingClientRect();
|
|
3357
3359
|
clickElementLeftOffset = event.x - rect.left;
|
|
3358
3360
|
clickElementTopOffset = event.y - rect.top;
|
|
3359
|
-
transformInfo = getTransform(moveElement);
|
|
3360
|
-
transformLeft = transformInfo.transformLeft;
|
|
3361
|
-
transformTop = transformInfo.transformTop;
|
|
3361
|
+
transformInfo = popsDOMUtils.getTransform(moveElement);
|
|
3362
3362
|
//if (event.nativeEvent.offsetX) {
|
|
3363
3363
|
// clickElementLeftOffset = parseInt(event.nativeEvent.offsetX);
|
|
3364
3364
|
//} else {
|
|
@@ -3372,9 +3372,9 @@
|
|
|
3372
3372
|
resumeMoveElementStyle = changeMoveElementStyle(moveElement);
|
|
3373
3373
|
}
|
|
3374
3374
|
/** 当前移动的left偏移 */
|
|
3375
|
-
let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformLeft;
|
|
3375
|
+
let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformInfo.transformLeft;
|
|
3376
3376
|
/** 当前移动的top偏移 */
|
|
3377
|
-
let currentMoveTopOffset = event.y - clickElementTopOffset + transformTop;
|
|
3377
|
+
let currentMoveTopOffset = event.y - clickElementTopOffset + transformInfo.transformTop;
|
|
3378
3378
|
/* 拖拽移动 */
|
|
3379
3379
|
if (event.phase === "move") {
|
|
3380
3380
|
if (options.limit) {
|
|
@@ -3382,12 +3382,12 @@
|
|
|
3382
3382
|
/* left偏移最大值 */
|
|
3383
3383
|
let maxLeftOffset = getContainerWidthOrHeight(options.container).width -
|
|
3384
3384
|
popsDOMUtils.width(moveElement) +
|
|
3385
|
-
transformLeft;
|
|
3385
|
+
transformInfo.transformLeft;
|
|
3386
3386
|
let { left: minLeftOffset, top: minTopOffset } = getContainerTopOrLeft(options.container);
|
|
3387
3387
|
/* top偏移的最大值 */
|
|
3388
3388
|
let maxTopOffset = getContainerWidthOrHeight(options.container).height -
|
|
3389
3389
|
popsDOMUtils.height(moveElement) +
|
|
3390
|
-
transformTop;
|
|
3390
|
+
transformInfo.transformTop;
|
|
3391
3391
|
if (currentMoveLeftOffset > maxLeftOffset) {
|
|
3392
3392
|
/* 不允许超过容器的最大宽度 */
|
|
3393
3393
|
currentMoveLeftOffset = maxLeftOffset;
|
|
@@ -3396,9 +3396,10 @@
|
|
|
3396
3396
|
/* 不允许超过容器的最大高度 */
|
|
3397
3397
|
currentMoveTopOffset = maxTopOffset;
|
|
3398
3398
|
}
|
|
3399
|
-
if (currentMoveLeftOffset - options.extraDistance * 2 <
|
|
3399
|
+
if (currentMoveLeftOffset - options.extraDistance * 2 <
|
|
3400
|
+
minLeftOffset + transformInfo.transformLeft) {
|
|
3400
3401
|
/* 不允许left偏移小于容器最小值 */
|
|
3401
|
-
currentMoveLeftOffset = minLeftOffset + transformLeft;
|
|
3402
|
+
currentMoveLeftOffset = minLeftOffset + transformInfo.transformLeft;
|
|
3402
3403
|
/* 最左边 +额外距离 */
|
|
3403
3404
|
currentMoveLeftOffset += options.extraDistance;
|
|
3404
3405
|
}
|
|
@@ -3406,9 +3407,9 @@
|
|
|
3406
3407
|
/* 最右边 -额外距离 */
|
|
3407
3408
|
currentMoveLeftOffset -= options.extraDistance;
|
|
3408
3409
|
}
|
|
3409
|
-
if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformTop) {
|
|
3410
|
+
if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformInfo.transformTop) {
|
|
3410
3411
|
/* 不允许top偏移小于容器最小值 */
|
|
3411
|
-
currentMoveTopOffset = minTopOffset + transformTop;
|
|
3412
|
+
currentMoveTopOffset = minTopOffset + transformInfo.transformTop;
|
|
3412
3413
|
/* 最上面 +额外距离 */
|
|
3413
3414
|
currentMoveTopOffset += options.extraDistance;
|
|
3414
3415
|
}
|
|
@@ -10834,33 +10835,34 @@
|
|
|
10834
10835
|
};
|
|
10835
10836
|
|
|
10836
10837
|
const searchSuggestionConfig = () => {
|
|
10838
|
+
const data = [];
|
|
10839
|
+
for (let index = 0; index < 10; index++) {
|
|
10840
|
+
data.push({
|
|
10841
|
+
value: `测试${index}`,
|
|
10842
|
+
text: `测试${index}-html`,
|
|
10843
|
+
});
|
|
10844
|
+
}
|
|
10837
10845
|
return {
|
|
10838
10846
|
// @ts-ignore
|
|
10839
10847
|
target: null,
|
|
10840
10848
|
// @ts-ignore
|
|
10841
10849
|
inputTarget: null,
|
|
10842
10850
|
selfDocument: document,
|
|
10843
|
-
data:
|
|
10844
|
-
{
|
|
10845
|
-
value: "数据1",
|
|
10846
|
-
text: "数据1-html",
|
|
10847
|
-
},
|
|
10848
|
-
{
|
|
10849
|
-
value: "数据2",
|
|
10850
|
-
text: "数据2-html",
|
|
10851
|
-
},
|
|
10852
|
-
],
|
|
10851
|
+
data: data,
|
|
10853
10852
|
deleteIcon: {
|
|
10854
10853
|
enable: true,
|
|
10855
|
-
callback(event, liElement,
|
|
10856
|
-
console.log("删除当前项", [event, liElement,
|
|
10854
|
+
callback(event, liElement, dataItem) {
|
|
10855
|
+
console.log("删除当前项", [event, liElement, dataItem]);
|
|
10856
|
+
data.splice(data.indexOf(dataItem), 1);
|
|
10857
10857
|
liElement.remove();
|
|
10858
10858
|
},
|
|
10859
10859
|
},
|
|
10860
10860
|
useShadowRoot: true,
|
|
10861
10861
|
className: "",
|
|
10862
10862
|
isAbsolute: true,
|
|
10863
|
-
isAnimation:
|
|
10863
|
+
isAnimation: false,
|
|
10864
|
+
useFoldAnimation: true,
|
|
10865
|
+
useArrow: false,
|
|
10864
10866
|
width: "250px",
|
|
10865
10867
|
maxHeight: "300px",
|
|
10866
10868
|
followTargetWidth: true,
|
|
@@ -10875,9 +10877,9 @@
|
|
|
10875
10877
|
getItemHTML(item) {
|
|
10876
10878
|
return item.text ?? item;
|
|
10877
10879
|
},
|
|
10878
|
-
async getData(value) {
|
|
10880
|
+
async getData(value, data) {
|
|
10879
10881
|
console.log("当前输入框的值是:", value);
|
|
10880
|
-
return
|
|
10882
|
+
return data.filter((it) => it.value.includes(value));
|
|
10881
10883
|
},
|
|
10882
10884
|
itemClickCallBack(event, liElement, data) {
|
|
10883
10885
|
console.log("item项的点击回调", [event, liElement, data]);
|
|
@@ -10949,74 +10951,168 @@
|
|
|
10949
10951
|
/** 是否结果为空 */
|
|
10950
10952
|
isEmpty: true,
|
|
10951
10953
|
},
|
|
10954
|
+
/** 初始化元素变量 */
|
|
10955
|
+
initEl() {
|
|
10956
|
+
this.$el.root = SearchSuggestion.createSearchSelectElement();
|
|
10957
|
+
this.$el.$dynamicCSS = this.$el.root.querySelector("style[data-dynamic]");
|
|
10958
|
+
this.$el.$hintULContainer = SearchSuggestion.$el.root.querySelector("ul");
|
|
10959
|
+
},
|
|
10952
10960
|
/**
|
|
10953
10961
|
* 初始化
|
|
10954
10962
|
*/
|
|
10955
10963
|
init(parentElement = document.body || document.documentElement) {
|
|
10956
10964
|
this.initEl();
|
|
10957
|
-
SearchSuggestion.update(
|
|
10958
|
-
SearchSuggestion.
|
|
10959
|
-
SearchSuggestion.changeHintULElementWidth();
|
|
10960
|
-
SearchSuggestion.changeHintULElementPosition();
|
|
10965
|
+
SearchSuggestion.update(this.getData());
|
|
10966
|
+
SearchSuggestion.updateStyleSheet();
|
|
10961
10967
|
SearchSuggestion.hide();
|
|
10962
|
-
if (config.isAnimation) {
|
|
10963
|
-
SearchSuggestion.$el.root.classList.add(`pops-${popsType}-animation`);
|
|
10964
|
-
}
|
|
10965
10968
|
$shadowRoot.appendChild(SearchSuggestion.$el.root);
|
|
10966
10969
|
parentElement.appendChild($shadowContainer);
|
|
10967
10970
|
},
|
|
10968
|
-
/**
|
|
10969
|
-
|
|
10970
|
-
|
|
10971
|
-
|
|
10972
|
-
|
|
10971
|
+
/**
|
|
10972
|
+
* 获取数据
|
|
10973
|
+
*/
|
|
10974
|
+
getData() {
|
|
10975
|
+
return typeof config.data === "function" ? config.data() : config.data;
|
|
10973
10976
|
},
|
|
10974
10977
|
/**
|
|
10975
10978
|
* 获取显示出搜索建议框的html
|
|
10976
10979
|
*/
|
|
10977
|
-
|
|
10978
|
-
let
|
|
10980
|
+
createSearchSelectElement() {
|
|
10981
|
+
let $el = popsDOMUtils.createElement("div", {
|
|
10979
10982
|
className: `pops pops-${popsType}-search-suggestion`,
|
|
10980
10983
|
innerHTML: /*html*/ `
|
|
10984
|
+
<style>
|
|
10985
|
+
.pops-${popsType}-animation{
|
|
10986
|
+
-moz-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10987
|
+
-webkit-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10988
|
+
-o-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10989
|
+
-ms-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10990
|
+
}
|
|
10991
|
+
</style>
|
|
10992
|
+
<style>
|
|
10993
|
+
.pops-${popsType}-search-suggestion-arrow{
|
|
10994
|
+
--suggestion-arrow-box-shadow-left-color: rgba(0, 0, 0, 0.24);
|
|
10995
|
+
--suggestion-arrow-box-shadow-right-color: rgba(0, 0, 0, 0.12);
|
|
10996
|
+
--suggestion-arrow--after-color: rgb(78, 78, 78);
|
|
10997
|
+
--suggestion-arrow--after-bg-color: rgb(255, 255, 255, var(--pops-bg-opacity));
|
|
10998
|
+
--suggestion-arrow--after-width: 10px;
|
|
10999
|
+
--suggestion-arrow--after-height: 10px;
|
|
11000
|
+
}
|
|
11001
|
+
.pops-${popsType}-search-suggestion-arrow{
|
|
11002
|
+
position: absolute;
|
|
11003
|
+
top: 100%;
|
|
11004
|
+
left: 50%;
|
|
11005
|
+
overflow: hidden;
|
|
11006
|
+
width: 100%;
|
|
11007
|
+
height: 12.5px;
|
|
11008
|
+
transform: translateX(-50%);
|
|
11009
|
+
}
|
|
11010
|
+
.pops-${popsType}-search-suggestion-arrow::after{
|
|
11011
|
+
position: absolute;
|
|
11012
|
+
top: 0;
|
|
11013
|
+
left: 50%;
|
|
11014
|
+
width: var(--suggestion-arrow--after-width);
|
|
11015
|
+
height: var(--suggestion-arrow--after-height);
|
|
11016
|
+
background: var(--suggestion-arrow--after-bg-color);
|
|
11017
|
+
color: var(--suggestion-arrow--after-color);
|
|
11018
|
+
box-shadow:
|
|
11019
|
+
0 1px 7px var(--suggestion-arrow-box-shadow-left-color),
|
|
11020
|
+
0 1px 7px var(--suggestion-arrow-box-shadow-right-color);
|
|
11021
|
+
content: "";
|
|
11022
|
+
transform: translateX(-50%) translateY(-50%) rotate(45deg);
|
|
11023
|
+
}
|
|
11024
|
+
.pops-${popsType}-search-suggestion[data-popper-placement^="top"] .pops-${popsType}-search-suggestion-arrow{
|
|
11025
|
+
position: absolute;
|
|
11026
|
+
top: 100%;
|
|
11027
|
+
left: 50%;
|
|
11028
|
+
overflow: hidden;
|
|
11029
|
+
width: 100%;
|
|
11030
|
+
height: 12.5px;
|
|
11031
|
+
transform: translateX(-50%);
|
|
11032
|
+
}
|
|
11033
|
+
.pops-${popsType}-search-suggestion[data-popper-placement^="top"] .pops-${popsType}-search-suggestion-arrow::after{
|
|
11034
|
+
position: absolute;
|
|
11035
|
+
top: 0;
|
|
11036
|
+
left: 50%;
|
|
11037
|
+
width: var(--suggestion-arrow--after-width);
|
|
11038
|
+
height: var(--suggestion-arrow--after-height);
|
|
11039
|
+
background: var(--suggestion-arrow--after-bg-color);
|
|
11040
|
+
box-shadow:
|
|
11041
|
+
0 1px 7px var(--suggestion-arrow-box-shadow-left-color),
|
|
11042
|
+
0 1px 7px var(--suggestion-arrow-box-shadow-right-color);
|
|
11043
|
+
content: "";
|
|
11044
|
+
transform: translateX(-50%) translateY(-50%) rotate(45deg);
|
|
11045
|
+
}
|
|
11046
|
+
.pops-${popsType}-search-suggestion[data-popper-placement^="bottom"] .pops-${popsType}-search-suggestion-arrow{
|
|
11047
|
+
top: -12.5px;
|
|
11048
|
+
left: 50%;
|
|
11049
|
+
transform: translateX(-50%);
|
|
11050
|
+
}
|
|
11051
|
+
.pops-${popsType}-search-suggestion[data-popper-placement^="bottom"] .pops-${popsType}-search-suggestion-arrow::after{
|
|
11052
|
+
position: absolute;
|
|
11053
|
+
top: 100%;
|
|
11054
|
+
left: 50%;
|
|
11055
|
+
content: "";
|
|
11056
|
+
}
|
|
11057
|
+
</style>
|
|
10981
11058
|
<style data-dynamic="true">
|
|
10982
11059
|
${this.getDynamicCSS()}
|
|
10983
11060
|
</style>
|
|
10984
|
-
<
|
|
11061
|
+
<style>
|
|
11062
|
+
.el-zoom-in-top-animation{
|
|
11063
|
+
--el-transition-md-fade: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1),
|
|
11064
|
+
opacity 0.3s cubic-bezier(0.23, 1, 0.32, 1);
|
|
11065
|
+
transition: var(--el-transition-md-fade);
|
|
11066
|
+
transform-origin: center top;
|
|
11067
|
+
}
|
|
11068
|
+
.el-zoom-in-top-animation[data-popper-placement^="top"] {
|
|
11069
|
+
transform-origin: center bottom;
|
|
11070
|
+
}
|
|
11071
|
+
.el-zoom-in-top-animation-hide{
|
|
11072
|
+
opacity: 0;
|
|
11073
|
+
transform: scaleY(0);
|
|
11074
|
+
}
|
|
11075
|
+
.el-zoom-in-top-animation-show{
|
|
11076
|
+
opacity: 1;
|
|
11077
|
+
transform: scaleY(1);
|
|
11078
|
+
}
|
|
11079
|
+
</style>
|
|
11080
|
+
<ul class="pops-${popsType}-search-suggestion-hint ${PopsCommonCSSClassName.userSelectNone}">${config.toSearhNotResultHTML}</ul>
|
|
11081
|
+
${config.useArrow ? /*html*/ `<div class="pops-${popsType}-search-suggestion-arrow"></div>` : ""}
|
|
10985
11082
|
`,
|
|
10986
11083
|
}, {
|
|
10987
11084
|
"data-guid": guid,
|
|
10988
11085
|
"type-value": popsType,
|
|
10989
11086
|
});
|
|
10990
11087
|
if (config.className !== "" && config.className != null) {
|
|
10991
|
-
popsDOMUtils.addClassName(
|
|
11088
|
+
popsDOMUtils.addClassName($el, config.className);
|
|
11089
|
+
}
|
|
11090
|
+
if (config.isAnimation) {
|
|
11091
|
+
popsDOMUtils.addClassName($el, `pops-${popsType}-animation`);
|
|
11092
|
+
}
|
|
11093
|
+
if (config.useFoldAnimation) {
|
|
11094
|
+
popsDOMUtils.addClassName($el, "el-zoom-in-top-animation");
|
|
10992
11095
|
}
|
|
10993
|
-
return
|
|
11096
|
+
return $el;
|
|
10994
11097
|
},
|
|
10995
11098
|
/** 动态获取CSS */
|
|
10996
11099
|
getDynamicCSS() {
|
|
10997
11100
|
return /*css*/ `
|
|
10998
|
-
.pops-${popsType}-animation{
|
|
10999
|
-
-moz-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11000
|
-
-webkit-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11001
|
-
-o-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11002
|
-
-ms-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11003
|
-
}
|
|
11004
11101
|
.pops-${popsType}-search-suggestion{
|
|
11005
11102
|
--search-suggestion-bg-color: #ffffff;
|
|
11006
11103
|
--search-suggestion-box-shadow-color: rgb(0 0 0 / 20%);
|
|
11007
11104
|
--search-suggestion-item-color: #515a6e;
|
|
11008
11105
|
--search-suggestion-item-none-color: #8e8e8e;
|
|
11009
|
-
--search-suggestion-item-hover-bg-color:
|
|
11106
|
+
--search-suggestion-item-is-hover-bg-color: #f5f7fa;
|
|
11107
|
+
--search-suggestion-item-is-select-bg-color: #409eff;
|
|
11010
11108
|
}
|
|
11011
11109
|
.pops-${popsType}-search-suggestion{
|
|
11012
11110
|
border: initial;
|
|
11013
11111
|
overflow: initial;
|
|
11014
|
-
}
|
|
11015
|
-
ul.pops-${popsType}-search-suggestion-hint{
|
|
11016
11112
|
position: ${config.isAbsolute ? "absolute" : "fixed"};
|
|
11017
11113
|
z-index: ${PopsHandler.handleZIndex(config.zIndex)};
|
|
11018
|
-
|
|
11019
|
-
|
|
11114
|
+
}
|
|
11115
|
+
ul.pops-${popsType}-search-suggestion-hint{
|
|
11020
11116
|
max-height: ${config.maxHeight};
|
|
11021
11117
|
overflow-x: hidden;
|
|
11022
11118
|
overflow-y: auto;
|
|
@@ -11027,11 +11123,11 @@
|
|
|
11027
11123
|
box-shadow: 0 1px 6px var(--search-suggestion-box-shadow-color);
|
|
11028
11124
|
}
|
|
11029
11125
|
/* 建议框在上面时 */
|
|
11030
|
-
|
|
11126
|
+
.pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-hint{
|
|
11031
11127
|
display: flex;
|
|
11032
11128
|
flex-direction: column-reverse;
|
|
11033
11129
|
}
|
|
11034
|
-
|
|
11130
|
+
.pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-hint li{
|
|
11035
11131
|
flex-shrink: 0;
|
|
11036
11132
|
}
|
|
11037
11133
|
ul.pops-${popsType}-search-suggestion-hint li{
|
|
@@ -11053,14 +11149,13 @@
|
|
|
11053
11149
|
color: var(--search-suggestion-item-none-color);
|
|
11054
11150
|
}
|
|
11055
11151
|
ul.pops-${popsType}-search-suggestion-hint li:not([data-none]):hover{
|
|
11056
|
-
background-color: var(--search-suggestion-item-hover-bg-color);
|
|
11152
|
+
background-color: var(--search-suggestion-item-is-hover-bg-color);
|
|
11057
11153
|
}
|
|
11058
|
-
|
|
11059
11154
|
@media (prefers-color-scheme: dark){
|
|
11060
11155
|
.pops-${popsType}-search-suggestion{
|
|
11061
11156
|
--search-suggestion-bg-color: #1d1e1f;
|
|
11062
11157
|
--search-suggestion-item-color: #cfd3d4;
|
|
11063
|
-
--search-suggestion-item-hover-bg-color: rgba(175, 175, 175, .1);
|
|
11158
|
+
--search-suggestion-item-is-hover-bg-color: rgba(175, 175, 175, .1);
|
|
11064
11159
|
}
|
|
11065
11160
|
}
|
|
11066
11161
|
`;
|
|
@@ -11070,7 +11165,7 @@
|
|
|
11070
11165
|
* @param data 当前项的值
|
|
11071
11166
|
* @param index 当前项的下标
|
|
11072
11167
|
*/
|
|
11073
|
-
|
|
11168
|
+
createSearchItemLiElement(data, index) {
|
|
11074
11169
|
let $li = popsDOMUtils.createElement("li", {
|
|
11075
11170
|
className: `pops-${popsType}-search-suggestion-hint-item`,
|
|
11076
11171
|
"data-index": index,
|
|
@@ -11090,25 +11185,28 @@
|
|
|
11090
11185
|
},
|
|
11091
11186
|
/**
|
|
11092
11187
|
* 设置搜索建议框每一项的点击事件
|
|
11093
|
-
* @param
|
|
11188
|
+
* @param $searchItem
|
|
11094
11189
|
*/
|
|
11095
|
-
setSearchItemClickEvent(
|
|
11096
|
-
popsDOMUtils.on(
|
|
11190
|
+
setSearchItemClickEvent($searchItem) {
|
|
11191
|
+
popsDOMUtils.on($searchItem, "click", (event) => {
|
|
11097
11192
|
popsDOMUtils.preventEvent(event);
|
|
11098
11193
|
let $click = event.target;
|
|
11099
|
-
|
|
11100
|
-
|
|
11194
|
+
let dataValue = Reflect.get($searchItem, "data-value");
|
|
11195
|
+
let isDelete = Boolean($click.closest(`.pops-${popsType}-delete-icon`));
|
|
11196
|
+
if (isDelete) {
|
|
11197
|
+
// 删除
|
|
11101
11198
|
if (typeof config.deleteIcon.callback === "function") {
|
|
11102
|
-
config.deleteIcon.callback(event,
|
|
11199
|
+
config.deleteIcon.callback(event, $searchItem, dataValue);
|
|
11103
11200
|
}
|
|
11104
11201
|
if (!this.$el.$hintULContainer.children.length) {
|
|
11105
11202
|
/* 全删完了 */
|
|
11106
11203
|
this.clear();
|
|
11107
11204
|
}
|
|
11205
|
+
SearchSuggestion.updateStyleSheet();
|
|
11108
11206
|
}
|
|
11109
11207
|
else {
|
|
11110
|
-
|
|
11111
|
-
config.itemClickCallBack(event,
|
|
11208
|
+
// 点击选择项
|
|
11209
|
+
config.itemClickCallBack(event, $searchItem, dataValue);
|
|
11112
11210
|
}
|
|
11113
11211
|
}, {
|
|
11114
11212
|
capture: true,
|
|
@@ -11148,8 +11246,9 @@
|
|
|
11148
11246
|
config.inputTarget.setAttribute("autocomplete", "off");
|
|
11149
11247
|
/* 内容改变事件 */
|
|
11150
11248
|
popsDOMUtils.on(config.inputTarget, "input", void 0, async (event) => {
|
|
11151
|
-
let getListResult = await config.getData(
|
|
11249
|
+
let getListResult = await config.getData(config.inputTarget.value, this.getData());
|
|
11152
11250
|
SearchSuggestion.update(getListResult);
|
|
11251
|
+
SearchSuggestion.updateStyleSheet();
|
|
11153
11252
|
}, option);
|
|
11154
11253
|
},
|
|
11155
11254
|
/**
|
|
@@ -11164,12 +11263,10 @@
|
|
|
11164
11263
|
* 显示搜索建议框的事件
|
|
11165
11264
|
*/
|
|
11166
11265
|
showEvent() {
|
|
11167
|
-
SearchSuggestion.
|
|
11168
|
-
SearchSuggestion.changeHintULElementWidth();
|
|
11169
|
-
SearchSuggestion.changeHintULElementPosition();
|
|
11266
|
+
SearchSuggestion.updateStyleSheet();
|
|
11170
11267
|
if (config.toHideWithNotResult) {
|
|
11171
11268
|
if (SearchSuggestion.$data.isEmpty) {
|
|
11172
|
-
SearchSuggestion.hide();
|
|
11269
|
+
SearchSuggestion.hide(true);
|
|
11173
11270
|
}
|
|
11174
11271
|
else {
|
|
11175
11272
|
SearchSuggestion.show();
|
|
@@ -11228,7 +11325,7 @@
|
|
|
11228
11325
|
/* 点击在目标input内 */
|
|
11229
11326
|
return;
|
|
11230
11327
|
}
|
|
11231
|
-
SearchSuggestion.hide();
|
|
11328
|
+
SearchSuggestion.hide(true);
|
|
11232
11329
|
}
|
|
11233
11330
|
},
|
|
11234
11331
|
/**
|
|
@@ -11353,29 +11450,39 @@
|
|
|
11353
11450
|
else {
|
|
11354
11451
|
// 在下面
|
|
11355
11452
|
position = "bottom";
|
|
11356
|
-
SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top");
|
|
11357
11453
|
}
|
|
11358
11454
|
}
|
|
11359
11455
|
if (position === "top") {
|
|
11456
|
+
// 在上面
|
|
11360
11457
|
if (config.positionTopToReverse) {
|
|
11361
|
-
|
|
11458
|
+
// 自动翻转
|
|
11459
|
+
SearchSuggestion.$el.root.setAttribute("data-top-reverse", "true");
|
|
11362
11460
|
}
|
|
11363
|
-
|
|
11364
|
-
|
|
11365
|
-
|
|
11366
|
-
|
|
11461
|
+
if (config.useFoldAnimation) {
|
|
11462
|
+
// 翻转折叠
|
|
11463
|
+
SearchSuggestion.$el.root.setAttribute("data-popper-placement", "top");
|
|
11464
|
+
}
|
|
11465
|
+
let bottom = documentHeight - targetRect.top + config.topDistance;
|
|
11466
|
+
SearchSuggestion.$el.root.style.top = "";
|
|
11467
|
+
SearchSuggestion.$el.root.style.bottom = bottom + "px";
|
|
11367
11468
|
}
|
|
11368
11469
|
else if (position === "bottom") {
|
|
11369
11470
|
// 在下面
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
|
|
11471
|
+
if (config.useFoldAnimation) {
|
|
11472
|
+
SearchSuggestion.$el.root.setAttribute("data-popper-placement", "bottom-center");
|
|
11473
|
+
}
|
|
11474
|
+
let top = targetRect.height + targetRect.top + config.topDistance;
|
|
11475
|
+
SearchSuggestion.$el.root.removeAttribute("data-top-reverse");
|
|
11476
|
+
SearchSuggestion.$el.root.style.bottom = "";
|
|
11477
|
+
SearchSuggestion.$el.root.style.top = top + "px";
|
|
11374
11478
|
}
|
|
11479
|
+
let left = targetRect.left;
|
|
11375
11480
|
let hintUIWidth = popsDOMUtils.width(SearchSuggestion.$el.$hintULContainer);
|
|
11376
|
-
|
|
11377
|
-
|
|
11378
|
-
|
|
11481
|
+
if (hintUIWidth > documentWidth) {
|
|
11482
|
+
// 超出宽度
|
|
11483
|
+
left = left + documentWidth - hintUIWidth;
|
|
11484
|
+
}
|
|
11485
|
+
SearchSuggestion.$el.root.style.left = left + "px";
|
|
11379
11486
|
},
|
|
11380
11487
|
/**
|
|
11381
11488
|
* 更新搜索建议框的width
|
|
@@ -11397,6 +11504,17 @@
|
|
|
11397
11504
|
let cssText = this.getDynamicCSS();
|
|
11398
11505
|
PopsSafeUtils.setSafeHTML(this.$el.$dynamicCSS, cssText);
|
|
11399
11506
|
},
|
|
11507
|
+
/**
|
|
11508
|
+
* 数据项的数量改变时调用
|
|
11509
|
+
*/
|
|
11510
|
+
updateStyleSheet() {
|
|
11511
|
+
// 更新z-index
|
|
11512
|
+
SearchSuggestion.updateDynamicCSS();
|
|
11513
|
+
// 更新宽度
|
|
11514
|
+
SearchSuggestion.changeHintULElementWidth();
|
|
11515
|
+
// 更新位置
|
|
11516
|
+
SearchSuggestion.changeHintULElementPosition();
|
|
11517
|
+
},
|
|
11400
11518
|
/**
|
|
11401
11519
|
* 更新页面显示的搜索结果
|
|
11402
11520
|
* @param data
|
|
@@ -11415,7 +11533,7 @@
|
|
|
11415
11533
|
SearchSuggestion.clearAllSearchItemLi();
|
|
11416
11534
|
/* 添加进ul中 */
|
|
11417
11535
|
config.data.forEach((item, index) => {
|
|
11418
|
-
let itemElement = SearchSuggestion.
|
|
11536
|
+
let itemElement = SearchSuggestion.createSearchItemLiElement(item, index);
|
|
11419
11537
|
SearchSuggestion.setSearchItemClickEvent(itemElement);
|
|
11420
11538
|
SearchSuggestion.setSearchItemSelectEvent(itemElement);
|
|
11421
11539
|
SearchSuggestion.$el.$hintULContainer.appendChild(itemElement);
|
|
@@ -11439,15 +11557,32 @@
|
|
|
11439
11557
|
},
|
|
11440
11558
|
/**
|
|
11441
11559
|
* 隐藏搜索建议框
|
|
11560
|
+
* @param useAnimationToHide 是否使用动画隐藏
|
|
11442
11561
|
*/
|
|
11443
|
-
hide() {
|
|
11444
|
-
|
|
11562
|
+
hide(useAnimationToHide = false) {
|
|
11563
|
+
if (config.useFoldAnimation) {
|
|
11564
|
+
if (!useAnimationToHide) {
|
|
11565
|
+
// 去掉动画
|
|
11566
|
+
popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation");
|
|
11567
|
+
}
|
|
11568
|
+
popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation");
|
|
11569
|
+
popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation-hide");
|
|
11570
|
+
popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation-show");
|
|
11571
|
+
}
|
|
11572
|
+
else {
|
|
11573
|
+
this.$el.root.style.display = "none";
|
|
11574
|
+
}
|
|
11445
11575
|
},
|
|
11446
11576
|
/**
|
|
11447
11577
|
* 显示搜索建议框
|
|
11448
11578
|
*/
|
|
11449
11579
|
show() {
|
|
11450
11580
|
this.$el.root.style.display = "";
|
|
11581
|
+
if (config.useFoldAnimation) {
|
|
11582
|
+
popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation");
|
|
11583
|
+
popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation-hide");
|
|
11584
|
+
popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation-show");
|
|
11585
|
+
}
|
|
11451
11586
|
},
|
|
11452
11587
|
};
|
|
11453
11588
|
return SearchSuggestion;
|