@whitesev/pops 2.3.3 → 2.3.5
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 +284 -136
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +284 -136
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +284 -136
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +284 -136
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +284 -136
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +284 -136
- 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.iife.js
CHANGED
|
@@ -1816,11 +1816,11 @@ var pops = (function () {
|
|
|
1816
1816
|
}
|
|
1817
1817
|
/**
|
|
1818
1818
|
* 添加className
|
|
1819
|
-
* @param
|
|
1819
|
+
* @param $el 目标元素
|
|
1820
1820
|
* @param className className属性
|
|
1821
1821
|
*/
|
|
1822
|
-
addClassName(
|
|
1823
|
-
if (
|
|
1822
|
+
addClassName($el, className) {
|
|
1823
|
+
if ($el == null) {
|
|
1824
1824
|
return;
|
|
1825
1825
|
}
|
|
1826
1826
|
if (typeof className !== "string") {
|
|
@@ -1829,15 +1829,16 @@ var pops = (function () {
|
|
|
1829
1829
|
if (className.trim() === "") {
|
|
1830
1830
|
return;
|
|
1831
1831
|
}
|
|
1832
|
-
|
|
1832
|
+
const classNameList = className.split(" ").filter((item) => item.trim() !== "");
|
|
1833
|
+
$el.classList.add(...classNameList);
|
|
1833
1834
|
}
|
|
1834
1835
|
/**
|
|
1835
1836
|
* 删除className
|
|
1836
|
-
* @param
|
|
1837
|
+
* @param $el 目标元素
|
|
1837
1838
|
* @param className className属性
|
|
1838
1839
|
*/
|
|
1839
|
-
removeClassName(
|
|
1840
|
-
if (
|
|
1840
|
+
removeClassName($el, className) {
|
|
1841
|
+
if ($el == null) {
|
|
1841
1842
|
return;
|
|
1842
1843
|
}
|
|
1843
1844
|
if (typeof className !== "string") {
|
|
@@ -1846,15 +1847,16 @@ var pops = (function () {
|
|
|
1846
1847
|
if (className.trim() === "") {
|
|
1847
1848
|
return;
|
|
1848
1849
|
}
|
|
1849
|
-
|
|
1850
|
+
const classNameList = className.split(" ").filter((item) => item.trim() !== "");
|
|
1851
|
+
$el.classList.remove(...classNameList);
|
|
1850
1852
|
}
|
|
1851
1853
|
/**
|
|
1852
1854
|
* 判断元素是否包含某个className
|
|
1853
|
-
* @param
|
|
1855
|
+
* @param $el 目标元素
|
|
1854
1856
|
* @param className className属性
|
|
1855
1857
|
*/
|
|
1856
|
-
containsClassName(
|
|
1857
|
-
if (
|
|
1858
|
+
containsClassName($el, className) {
|
|
1859
|
+
if ($el == null) {
|
|
1858
1860
|
return false;
|
|
1859
1861
|
}
|
|
1860
1862
|
if (typeof className !== "string") {
|
|
@@ -1863,7 +1865,7 @@ var pops = (function () {
|
|
|
1863
1865
|
if (className.trim() === "") {
|
|
1864
1866
|
return false;
|
|
1865
1867
|
}
|
|
1866
|
-
return
|
|
1868
|
+
return $el.classList.contains(className);
|
|
1867
1869
|
}
|
|
1868
1870
|
css(element, property, value) {
|
|
1869
1871
|
/**
|
|
@@ -2486,6 +2488,24 @@ var pops = (function () {
|
|
|
2486
2488
|
}
|
|
2487
2489
|
return useChangeColor();
|
|
2488
2490
|
}
|
|
2491
|
+
/**
|
|
2492
|
+
* 获取移动元素的transform偏移
|
|
2493
|
+
* @param element 元素
|
|
2494
|
+
*/
|
|
2495
|
+
getTransform(element) {
|
|
2496
|
+
let transform_left = 0;
|
|
2497
|
+
let transform_top = 0;
|
|
2498
|
+
let elementTransform = PopsCore.globalThis.getComputedStyle(element).transform;
|
|
2499
|
+
if (elementTransform !== "none" && elementTransform != null && elementTransform !== "") {
|
|
2500
|
+
let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
|
|
2501
|
+
transform_left = Math.abs(parseInt(elementTransformSplit[4]));
|
|
2502
|
+
transform_top = Math.abs(parseInt(elementTransformSplit[5]));
|
|
2503
|
+
}
|
|
2504
|
+
return {
|
|
2505
|
+
transformLeft: transform_left,
|
|
2506
|
+
transformTop: transform_top,
|
|
2507
|
+
};
|
|
2508
|
+
}
|
|
2489
2509
|
}
|
|
2490
2510
|
const popsDOMUtils = new PopsDOMUtils();
|
|
2491
2511
|
|
|
@@ -3285,23 +3305,6 @@ var pops = (function () {
|
|
|
3285
3305
|
popsDOMUtils.css(options.dragElement, {
|
|
3286
3306
|
cursor: "move",
|
|
3287
3307
|
});
|
|
3288
|
-
/**
|
|
3289
|
-
* 获取移动元素的transform偏移
|
|
3290
|
-
*/
|
|
3291
|
-
function getTransform(element) {
|
|
3292
|
-
let transform_left = 0;
|
|
3293
|
-
let transform_top = 0;
|
|
3294
|
-
let elementTransform = PopsCore.globalThis.getComputedStyle(element).transform;
|
|
3295
|
-
if (elementTransform !== "none" && elementTransform != null && elementTransform !== "") {
|
|
3296
|
-
let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
|
|
3297
|
-
transform_left = Math.abs(parseInt(elementTransformSplit[4]));
|
|
3298
|
-
transform_top = Math.abs(parseInt(elementTransformSplit[5]));
|
|
3299
|
-
}
|
|
3300
|
-
return {
|
|
3301
|
-
transformLeft: transform_left,
|
|
3302
|
-
transformTop: transform_top,
|
|
3303
|
-
};
|
|
3304
|
-
}
|
|
3305
3308
|
/**
|
|
3306
3309
|
* 修改移动的元素的style
|
|
3307
3310
|
*/
|
|
@@ -3343,9 +3346,8 @@ var pops = (function () {
|
|
|
3343
3346
|
};
|
|
3344
3347
|
}
|
|
3345
3348
|
}
|
|
3346
|
-
|
|
3347
|
-
let
|
|
3348
|
-
let transformTop = transformInfo.transformTop;
|
|
3349
|
+
// 获取transform偏移
|
|
3350
|
+
let transformInfo = popsDOMUtils.getTransform(moveElement);
|
|
3349
3351
|
let resumeMoveElementStyle = null;
|
|
3350
3352
|
anyTouchElement.on("pan", function (event) {
|
|
3351
3353
|
if (!isMove) {
|
|
@@ -3353,9 +3355,7 @@ var pops = (function () {
|
|
|
3353
3355
|
let rect = options.dragElement.getBoundingClientRect();
|
|
3354
3356
|
clickElementLeftOffset = event.x - rect.left;
|
|
3355
3357
|
clickElementTopOffset = event.y - rect.top;
|
|
3356
|
-
transformInfo = getTransform(moveElement);
|
|
3357
|
-
transformLeft = transformInfo.transformLeft;
|
|
3358
|
-
transformTop = transformInfo.transformTop;
|
|
3358
|
+
transformInfo = popsDOMUtils.getTransform(moveElement);
|
|
3359
3359
|
//if (event.nativeEvent.offsetX) {
|
|
3360
3360
|
// clickElementLeftOffset = parseInt(event.nativeEvent.offsetX);
|
|
3361
3361
|
//} else {
|
|
@@ -3369,9 +3369,9 @@ var pops = (function () {
|
|
|
3369
3369
|
resumeMoveElementStyle = changeMoveElementStyle(moveElement);
|
|
3370
3370
|
}
|
|
3371
3371
|
/** 当前移动的left偏移 */
|
|
3372
|
-
let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformLeft;
|
|
3372
|
+
let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformInfo.transformLeft;
|
|
3373
3373
|
/** 当前移动的top偏移 */
|
|
3374
|
-
let currentMoveTopOffset = event.y - clickElementTopOffset + transformTop;
|
|
3374
|
+
let currentMoveTopOffset = event.y - clickElementTopOffset + transformInfo.transformTop;
|
|
3375
3375
|
/* 拖拽移动 */
|
|
3376
3376
|
if (event.phase === "move") {
|
|
3377
3377
|
if (options.limit) {
|
|
@@ -3379,12 +3379,12 @@ var pops = (function () {
|
|
|
3379
3379
|
/* left偏移最大值 */
|
|
3380
3380
|
let maxLeftOffset = getContainerWidthOrHeight(options.container).width -
|
|
3381
3381
|
popsDOMUtils.width(moveElement) +
|
|
3382
|
-
transformLeft;
|
|
3382
|
+
transformInfo.transformLeft;
|
|
3383
3383
|
let { left: minLeftOffset, top: minTopOffset } = getContainerTopOrLeft(options.container);
|
|
3384
3384
|
/* top偏移的最大值 */
|
|
3385
3385
|
let maxTopOffset = getContainerWidthOrHeight(options.container).height -
|
|
3386
3386
|
popsDOMUtils.height(moveElement) +
|
|
3387
|
-
transformTop;
|
|
3387
|
+
transformInfo.transformTop;
|
|
3388
3388
|
if (currentMoveLeftOffset > maxLeftOffset) {
|
|
3389
3389
|
/* 不允许超过容器的最大宽度 */
|
|
3390
3390
|
currentMoveLeftOffset = maxLeftOffset;
|
|
@@ -3393,9 +3393,10 @@ var pops = (function () {
|
|
|
3393
3393
|
/* 不允许超过容器的最大高度 */
|
|
3394
3394
|
currentMoveTopOffset = maxTopOffset;
|
|
3395
3395
|
}
|
|
3396
|
-
if (currentMoveLeftOffset - options.extraDistance * 2 <
|
|
3396
|
+
if (currentMoveLeftOffset - options.extraDistance * 2 <
|
|
3397
|
+
minLeftOffset + transformInfo.transformLeft) {
|
|
3397
3398
|
/* 不允许left偏移小于容器最小值 */
|
|
3398
|
-
currentMoveLeftOffset = minLeftOffset + transformLeft;
|
|
3399
|
+
currentMoveLeftOffset = minLeftOffset + transformInfo.transformLeft;
|
|
3399
3400
|
/* 最左边 +额外距离 */
|
|
3400
3401
|
currentMoveLeftOffset += options.extraDistance;
|
|
3401
3402
|
}
|
|
@@ -3403,9 +3404,9 @@ var pops = (function () {
|
|
|
3403
3404
|
/* 最右边 -额外距离 */
|
|
3404
3405
|
currentMoveLeftOffset -= options.extraDistance;
|
|
3405
3406
|
}
|
|
3406
|
-
if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformTop) {
|
|
3407
|
+
if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformInfo.transformTop) {
|
|
3407
3408
|
/* 不允许top偏移小于容器最小值 */
|
|
3408
|
-
currentMoveTopOffset = minTopOffset + transformTop;
|
|
3409
|
+
currentMoveTopOffset = minTopOffset + transformInfo.transformTop;
|
|
3409
3410
|
/* 最上面 +额外距离 */
|
|
3410
3411
|
currentMoveTopOffset += options.extraDistance;
|
|
3411
3412
|
}
|
|
@@ -10744,28 +10745,42 @@ var pops = (function () {
|
|
|
10744
10745
|
popsDOMUtils.addClassName(menuLiElement, `pops-${popsType}-item`);
|
|
10745
10746
|
}
|
|
10746
10747
|
/* 鼠标|触摸 移入事件 */
|
|
10747
|
-
|
|
10748
|
+
// 在移动端会先触发touchstart再然后mouseenter
|
|
10749
|
+
let isTriggerTouchEvent = false;
|
|
10750
|
+
/**
|
|
10751
|
+
* 鼠标|触摸 移入事件
|
|
10752
|
+
*/
|
|
10753
|
+
function liElementHoverEvent(event) {
|
|
10754
|
+
if (event.type === "touchstart") {
|
|
10755
|
+
isTriggerTouchEvent = true;
|
|
10756
|
+
}
|
|
10757
|
+
if (isTriggerTouchEvent && event.type === "mouseenter") {
|
|
10758
|
+
return;
|
|
10759
|
+
}
|
|
10748
10760
|
Array.from(menuULElement.children).forEach((liElement) => {
|
|
10749
10761
|
popsDOMUtils.removeClassName(liElement, `pops-${popsType}-is-visited`);
|
|
10750
|
-
|
|
10762
|
+
let li_menuData = Reflect.get(liElement, "__menuData__");
|
|
10763
|
+
if (!li_menuData) {
|
|
10751
10764
|
return;
|
|
10752
10765
|
}
|
|
10753
10766
|
function removeElement(element) {
|
|
10754
|
-
element.querySelectorAll("ul li").forEach((ele) => {
|
|
10755
|
-
|
|
10756
|
-
|
|
10767
|
+
element.querySelectorAll("ul li").forEach(($ele) => {
|
|
10768
|
+
let menuData = Reflect.get($ele, "__menuData__");
|
|
10769
|
+
if (menuData?.child) {
|
|
10770
|
+
removeElement(menuData.child);
|
|
10757
10771
|
}
|
|
10758
10772
|
});
|
|
10759
10773
|
element.remove();
|
|
10760
10774
|
}
|
|
10761
10775
|
/* 遍历根元素的上的__menuData__.child,判断 */
|
|
10762
|
-
removeElement(
|
|
10776
|
+
removeElement(li_menuData.child);
|
|
10763
10777
|
});
|
|
10764
10778
|
/* 清理根元素上的children不存在于页面中的元素 */
|
|
10765
|
-
|
|
10766
|
-
|
|
10779
|
+
let root_menuData = Reflect.get(rootElement, "__menuData__");
|
|
10780
|
+
for (let index = 0; index < root_menuData.child.length; index++) {
|
|
10781
|
+
let element = root_menuData.child[index];
|
|
10767
10782
|
if (!$shadowRoot.contains(element)) {
|
|
10768
|
-
|
|
10783
|
+
root_menuData.child.splice(index, 1);
|
|
10769
10784
|
index--;
|
|
10770
10785
|
}
|
|
10771
10786
|
}
|
|
@@ -10778,14 +10793,13 @@ var pops = (function () {
|
|
|
10778
10793
|
clientX: rect.left + popsDOMUtils.outerWidth(menuLiElement),
|
|
10779
10794
|
clientY: rect.top,
|
|
10780
10795
|
}, item.item, rootElement, menuLiElement, menuListenerRootNode);
|
|
10781
|
-
menuLiElement
|
|
10796
|
+
Reflect.set(menuLiElement, "__menuData__", {
|
|
10782
10797
|
child: childMenu,
|
|
10783
|
-
};
|
|
10798
|
+
});
|
|
10784
10799
|
}
|
|
10785
10800
|
/**
|
|
10786
10801
|
* 点击事件
|
|
10787
10802
|
* @param clickEvent
|
|
10788
|
-
* @returns
|
|
10789
10803
|
*/
|
|
10790
10804
|
async function liElementClickEvent(clickEvent) {
|
|
10791
10805
|
if (typeof item.callback === "function") {
|
|
@@ -10808,9 +10822,9 @@ var pops = (function () {
|
|
|
10808
10822
|
});
|
|
10809
10823
|
PopsContextMenu.closeAllMenu(rootElement);
|
|
10810
10824
|
}
|
|
10811
|
-
popsDOMUtils.on(menuLiElement, "mouseenter touchstart",
|
|
10825
|
+
popsDOMUtils.on(menuLiElement, "mouseenter touchstart", liElementHoverEvent);
|
|
10812
10826
|
/* 项-点击事件 */
|
|
10813
|
-
popsDOMUtils.on(menuLiElement, "click",
|
|
10827
|
+
popsDOMUtils.on(menuLiElement, "click", liElementClickEvent);
|
|
10814
10828
|
menuULElement.appendChild(menuLiElement);
|
|
10815
10829
|
});
|
|
10816
10830
|
},
|
|
@@ -10831,33 +10845,34 @@ var pops = (function () {
|
|
|
10831
10845
|
};
|
|
10832
10846
|
|
|
10833
10847
|
const searchSuggestionConfig = () => {
|
|
10848
|
+
const data = [];
|
|
10849
|
+
for (let index = 0; index < 10; index++) {
|
|
10850
|
+
data.push({
|
|
10851
|
+
value: `测试${index}`,
|
|
10852
|
+
text: `测试${index}-html`,
|
|
10853
|
+
});
|
|
10854
|
+
}
|
|
10834
10855
|
return {
|
|
10835
10856
|
// @ts-ignore
|
|
10836
10857
|
target: null,
|
|
10837
10858
|
// @ts-ignore
|
|
10838
10859
|
inputTarget: null,
|
|
10839
10860
|
selfDocument: document,
|
|
10840
|
-
data:
|
|
10841
|
-
{
|
|
10842
|
-
value: "数据1",
|
|
10843
|
-
text: "数据1-html",
|
|
10844
|
-
},
|
|
10845
|
-
{
|
|
10846
|
-
value: "数据2",
|
|
10847
|
-
text: "数据2-html",
|
|
10848
|
-
},
|
|
10849
|
-
],
|
|
10861
|
+
data: data,
|
|
10850
10862
|
deleteIcon: {
|
|
10851
10863
|
enable: true,
|
|
10852
|
-
callback(event, liElement,
|
|
10853
|
-
console.log("删除当前项", [event, liElement,
|
|
10864
|
+
callback(event, liElement, dataItem) {
|
|
10865
|
+
console.log("删除当前项", [event, liElement, dataItem]);
|
|
10866
|
+
data.splice(data.indexOf(dataItem), 1);
|
|
10854
10867
|
liElement.remove();
|
|
10855
10868
|
},
|
|
10856
10869
|
},
|
|
10857
10870
|
useShadowRoot: true,
|
|
10858
10871
|
className: "",
|
|
10859
10872
|
isAbsolute: true,
|
|
10860
|
-
isAnimation:
|
|
10873
|
+
isAnimation: false,
|
|
10874
|
+
useFoldAnimation: true,
|
|
10875
|
+
useArrow: false,
|
|
10861
10876
|
width: "250px",
|
|
10862
10877
|
maxHeight: "300px",
|
|
10863
10878
|
followTargetWidth: true,
|
|
@@ -10872,9 +10887,9 @@ var pops = (function () {
|
|
|
10872
10887
|
getItemHTML(item) {
|
|
10873
10888
|
return item.text ?? item;
|
|
10874
10889
|
},
|
|
10875
|
-
async getData(value) {
|
|
10890
|
+
async getData(value, data) {
|
|
10876
10891
|
console.log("当前输入框的值是:", value);
|
|
10877
|
-
return
|
|
10892
|
+
return data.filter((it) => it.value.includes(value));
|
|
10878
10893
|
},
|
|
10879
10894
|
itemClickCallBack(event, liElement, data) {
|
|
10880
10895
|
console.log("item项的点击回调", [event, liElement, data]);
|
|
@@ -10946,74 +10961,168 @@ var pops = (function () {
|
|
|
10946
10961
|
/** 是否结果为空 */
|
|
10947
10962
|
isEmpty: true,
|
|
10948
10963
|
},
|
|
10964
|
+
/** 初始化元素变量 */
|
|
10965
|
+
initEl() {
|
|
10966
|
+
this.$el.root = SearchSuggestion.createSearchSelectElement();
|
|
10967
|
+
this.$el.$dynamicCSS = this.$el.root.querySelector("style[data-dynamic]");
|
|
10968
|
+
this.$el.$hintULContainer = SearchSuggestion.$el.root.querySelector("ul");
|
|
10969
|
+
},
|
|
10949
10970
|
/**
|
|
10950
10971
|
* 初始化
|
|
10951
10972
|
*/
|
|
10952
10973
|
init(parentElement = document.body || document.documentElement) {
|
|
10953
10974
|
this.initEl();
|
|
10954
|
-
SearchSuggestion.update(
|
|
10955
|
-
SearchSuggestion.
|
|
10956
|
-
SearchSuggestion.changeHintULElementWidth();
|
|
10957
|
-
SearchSuggestion.changeHintULElementPosition();
|
|
10975
|
+
SearchSuggestion.update(this.getData());
|
|
10976
|
+
SearchSuggestion.updateStyleSheet();
|
|
10958
10977
|
SearchSuggestion.hide();
|
|
10959
|
-
if (config.isAnimation) {
|
|
10960
|
-
SearchSuggestion.$el.root.classList.add(`pops-${popsType}-animation`);
|
|
10961
|
-
}
|
|
10962
10978
|
$shadowRoot.appendChild(SearchSuggestion.$el.root);
|
|
10963
10979
|
parentElement.appendChild($shadowContainer);
|
|
10964
10980
|
},
|
|
10965
|
-
/**
|
|
10966
|
-
|
|
10967
|
-
|
|
10968
|
-
|
|
10969
|
-
|
|
10981
|
+
/**
|
|
10982
|
+
* 获取数据
|
|
10983
|
+
*/
|
|
10984
|
+
getData() {
|
|
10985
|
+
return typeof config.data === "function" ? config.data() : config.data;
|
|
10970
10986
|
},
|
|
10971
10987
|
/**
|
|
10972
10988
|
* 获取显示出搜索建议框的html
|
|
10973
10989
|
*/
|
|
10974
|
-
|
|
10975
|
-
let
|
|
10990
|
+
createSearchSelectElement() {
|
|
10991
|
+
let $el = popsDOMUtils.createElement("div", {
|
|
10976
10992
|
className: `pops pops-${popsType}-search-suggestion`,
|
|
10977
10993
|
innerHTML: /*html*/ `
|
|
10994
|
+
<style>
|
|
10995
|
+
.pops-${popsType}-animation{
|
|
10996
|
+
-moz-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10997
|
+
-webkit-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10998
|
+
-o-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10999
|
+
-ms-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11000
|
+
}
|
|
11001
|
+
</style>
|
|
11002
|
+
<style>
|
|
11003
|
+
.pops-${popsType}-search-suggestion-arrow{
|
|
11004
|
+
--suggestion-arrow-box-shadow-left-color: rgba(0, 0, 0, 0.24);
|
|
11005
|
+
--suggestion-arrow-box-shadow-right-color: rgba(0, 0, 0, 0.12);
|
|
11006
|
+
--suggestion-arrow--after-color: rgb(78, 78, 78);
|
|
11007
|
+
--suggestion-arrow--after-bg-color: rgb(255, 255, 255, var(--pops-bg-opacity));
|
|
11008
|
+
--suggestion-arrow--after-width: 10px;
|
|
11009
|
+
--suggestion-arrow--after-height: 10px;
|
|
11010
|
+
}
|
|
11011
|
+
.pops-${popsType}-search-suggestion-arrow{
|
|
11012
|
+
position: absolute;
|
|
11013
|
+
top: 100%;
|
|
11014
|
+
left: 50%;
|
|
11015
|
+
overflow: hidden;
|
|
11016
|
+
width: 100%;
|
|
11017
|
+
height: 12.5px;
|
|
11018
|
+
transform: translateX(-50%);
|
|
11019
|
+
}
|
|
11020
|
+
.pops-${popsType}-search-suggestion-arrow::after{
|
|
11021
|
+
position: absolute;
|
|
11022
|
+
top: 0;
|
|
11023
|
+
left: 50%;
|
|
11024
|
+
width: var(--suggestion-arrow--after-width);
|
|
11025
|
+
height: var(--suggestion-arrow--after-height);
|
|
11026
|
+
background: var(--suggestion-arrow--after-bg-color);
|
|
11027
|
+
color: var(--suggestion-arrow--after-color);
|
|
11028
|
+
box-shadow:
|
|
11029
|
+
0 1px 7px var(--suggestion-arrow-box-shadow-left-color),
|
|
11030
|
+
0 1px 7px var(--suggestion-arrow-box-shadow-right-color);
|
|
11031
|
+
content: "";
|
|
11032
|
+
transform: translateX(-50%) translateY(-50%) rotate(45deg);
|
|
11033
|
+
}
|
|
11034
|
+
.pops-${popsType}-search-suggestion[data-popper-placement^="top"] .pops-${popsType}-search-suggestion-arrow{
|
|
11035
|
+
position: absolute;
|
|
11036
|
+
top: 100%;
|
|
11037
|
+
left: 50%;
|
|
11038
|
+
overflow: hidden;
|
|
11039
|
+
width: 100%;
|
|
11040
|
+
height: 12.5px;
|
|
11041
|
+
transform: translateX(-50%);
|
|
11042
|
+
}
|
|
11043
|
+
.pops-${popsType}-search-suggestion[data-popper-placement^="top"] .pops-${popsType}-search-suggestion-arrow::after{
|
|
11044
|
+
position: absolute;
|
|
11045
|
+
top: 0;
|
|
11046
|
+
left: 50%;
|
|
11047
|
+
width: var(--suggestion-arrow--after-width);
|
|
11048
|
+
height: var(--suggestion-arrow--after-height);
|
|
11049
|
+
background: var(--suggestion-arrow--after-bg-color);
|
|
11050
|
+
box-shadow:
|
|
11051
|
+
0 1px 7px var(--suggestion-arrow-box-shadow-left-color),
|
|
11052
|
+
0 1px 7px var(--suggestion-arrow-box-shadow-right-color);
|
|
11053
|
+
content: "";
|
|
11054
|
+
transform: translateX(-50%) translateY(-50%) rotate(45deg);
|
|
11055
|
+
}
|
|
11056
|
+
.pops-${popsType}-search-suggestion[data-popper-placement^="bottom"] .pops-${popsType}-search-suggestion-arrow{
|
|
11057
|
+
top: -12.5px;
|
|
11058
|
+
left: 50%;
|
|
11059
|
+
transform: translateX(-50%);
|
|
11060
|
+
}
|
|
11061
|
+
.pops-${popsType}-search-suggestion[data-popper-placement^="bottom"] .pops-${popsType}-search-suggestion-arrow::after{
|
|
11062
|
+
position: absolute;
|
|
11063
|
+
top: 100%;
|
|
11064
|
+
left: 50%;
|
|
11065
|
+
content: "";
|
|
11066
|
+
}
|
|
11067
|
+
</style>
|
|
10978
11068
|
<style data-dynamic="true">
|
|
10979
11069
|
${this.getDynamicCSS()}
|
|
10980
11070
|
</style>
|
|
10981
|
-
<
|
|
11071
|
+
<style>
|
|
11072
|
+
.el-zoom-in-top-animation{
|
|
11073
|
+
--el-transition-md-fade: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1),
|
|
11074
|
+
opacity 0.3s cubic-bezier(0.23, 1, 0.32, 1);
|
|
11075
|
+
transition: var(--el-transition-md-fade);
|
|
11076
|
+
transform-origin: center top;
|
|
11077
|
+
}
|
|
11078
|
+
.el-zoom-in-top-animation[data-popper-placement^="top"] {
|
|
11079
|
+
transform-origin: center bottom;
|
|
11080
|
+
}
|
|
11081
|
+
.el-zoom-in-top-animation-hide{
|
|
11082
|
+
opacity: 0;
|
|
11083
|
+
transform: scaleY(0);
|
|
11084
|
+
}
|
|
11085
|
+
.el-zoom-in-top-animation-show{
|
|
11086
|
+
opacity: 1;
|
|
11087
|
+
transform: scaleY(1);
|
|
11088
|
+
}
|
|
11089
|
+
</style>
|
|
11090
|
+
<ul class="pops-${popsType}-search-suggestion-hint ${PopsCommonCSSClassName.userSelectNone}">${config.toSearhNotResultHTML}</ul>
|
|
11091
|
+
${config.useArrow ? /*html*/ `<div class="pops-${popsType}-search-suggestion-arrow"></div>` : ""}
|
|
10982
11092
|
`,
|
|
10983
11093
|
}, {
|
|
10984
11094
|
"data-guid": guid,
|
|
10985
11095
|
"type-value": popsType,
|
|
10986
11096
|
});
|
|
10987
11097
|
if (config.className !== "" && config.className != null) {
|
|
10988
|
-
popsDOMUtils.addClassName(
|
|
11098
|
+
popsDOMUtils.addClassName($el, config.className);
|
|
11099
|
+
}
|
|
11100
|
+
if (config.isAnimation) {
|
|
11101
|
+
popsDOMUtils.addClassName($el, `pops-${popsType}-animation`);
|
|
11102
|
+
}
|
|
11103
|
+
if (config.useFoldAnimation) {
|
|
11104
|
+
popsDOMUtils.addClassName($el, "el-zoom-in-top-animation");
|
|
10989
11105
|
}
|
|
10990
|
-
return
|
|
11106
|
+
return $el;
|
|
10991
11107
|
},
|
|
10992
11108
|
/** 动态获取CSS */
|
|
10993
11109
|
getDynamicCSS() {
|
|
10994
11110
|
return /*css*/ `
|
|
10995
|
-
.pops-${popsType}-animation{
|
|
10996
|
-
-moz-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10997
|
-
-webkit-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10998
|
-
-o-animation: searchSelectFalIn 0.5s 1 linear;
|
|
10999
|
-
-ms-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11000
|
-
}
|
|
11001
11111
|
.pops-${popsType}-search-suggestion{
|
|
11002
11112
|
--search-suggestion-bg-color: #ffffff;
|
|
11003
11113
|
--search-suggestion-box-shadow-color: rgb(0 0 0 / 20%);
|
|
11004
11114
|
--search-suggestion-item-color: #515a6e;
|
|
11005
11115
|
--search-suggestion-item-none-color: #8e8e8e;
|
|
11006
|
-
--search-suggestion-item-hover-bg-color:
|
|
11116
|
+
--search-suggestion-item-is-hover-bg-color: #f5f7fa;
|
|
11117
|
+
--search-suggestion-item-is-select-bg-color: #409eff;
|
|
11007
11118
|
}
|
|
11008
11119
|
.pops-${popsType}-search-suggestion{
|
|
11009
11120
|
border: initial;
|
|
11010
11121
|
overflow: initial;
|
|
11011
|
-
}
|
|
11012
|
-
ul.pops-${popsType}-search-suggestion-hint{
|
|
11013
11122
|
position: ${config.isAbsolute ? "absolute" : "fixed"};
|
|
11014
11123
|
z-index: ${PopsHandler.handleZIndex(config.zIndex)};
|
|
11015
|
-
|
|
11016
|
-
|
|
11124
|
+
}
|
|
11125
|
+
ul.pops-${popsType}-search-suggestion-hint{
|
|
11017
11126
|
max-height: ${config.maxHeight};
|
|
11018
11127
|
overflow-x: hidden;
|
|
11019
11128
|
overflow-y: auto;
|
|
@@ -11024,11 +11133,11 @@ var pops = (function () {
|
|
|
11024
11133
|
box-shadow: 0 1px 6px var(--search-suggestion-box-shadow-color);
|
|
11025
11134
|
}
|
|
11026
11135
|
/* 建议框在上面时 */
|
|
11027
|
-
|
|
11136
|
+
.pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-hint{
|
|
11028
11137
|
display: flex;
|
|
11029
11138
|
flex-direction: column-reverse;
|
|
11030
11139
|
}
|
|
11031
|
-
|
|
11140
|
+
.pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-hint li{
|
|
11032
11141
|
flex-shrink: 0;
|
|
11033
11142
|
}
|
|
11034
11143
|
ul.pops-${popsType}-search-suggestion-hint li{
|
|
@@ -11050,14 +11159,13 @@ var pops = (function () {
|
|
|
11050
11159
|
color: var(--search-suggestion-item-none-color);
|
|
11051
11160
|
}
|
|
11052
11161
|
ul.pops-${popsType}-search-suggestion-hint li:not([data-none]):hover{
|
|
11053
|
-
background-color: var(--search-suggestion-item-hover-bg-color);
|
|
11162
|
+
background-color: var(--search-suggestion-item-is-hover-bg-color);
|
|
11054
11163
|
}
|
|
11055
|
-
|
|
11056
11164
|
@media (prefers-color-scheme: dark){
|
|
11057
11165
|
.pops-${popsType}-search-suggestion{
|
|
11058
11166
|
--search-suggestion-bg-color: #1d1e1f;
|
|
11059
11167
|
--search-suggestion-item-color: #cfd3d4;
|
|
11060
|
-
--search-suggestion-item-hover-bg-color: rgba(175, 175, 175, .1);
|
|
11168
|
+
--search-suggestion-item-is-hover-bg-color: rgba(175, 175, 175, .1);
|
|
11061
11169
|
}
|
|
11062
11170
|
}
|
|
11063
11171
|
`;
|
|
@@ -11067,7 +11175,7 @@ var pops = (function () {
|
|
|
11067
11175
|
* @param data 当前项的值
|
|
11068
11176
|
* @param index 当前项的下标
|
|
11069
11177
|
*/
|
|
11070
|
-
|
|
11178
|
+
createSearchItemLiElement(data, index) {
|
|
11071
11179
|
let $li = popsDOMUtils.createElement("li", {
|
|
11072
11180
|
className: `pops-${popsType}-search-suggestion-hint-item`,
|
|
11073
11181
|
"data-index": index,
|
|
@@ -11087,25 +11195,28 @@ var pops = (function () {
|
|
|
11087
11195
|
},
|
|
11088
11196
|
/**
|
|
11089
11197
|
* 设置搜索建议框每一项的点击事件
|
|
11090
|
-
* @param
|
|
11198
|
+
* @param $searchItem
|
|
11091
11199
|
*/
|
|
11092
|
-
setSearchItemClickEvent(
|
|
11093
|
-
popsDOMUtils.on(
|
|
11200
|
+
setSearchItemClickEvent($searchItem) {
|
|
11201
|
+
popsDOMUtils.on($searchItem, "click", (event) => {
|
|
11094
11202
|
popsDOMUtils.preventEvent(event);
|
|
11095
11203
|
let $click = event.target;
|
|
11096
|
-
|
|
11097
|
-
|
|
11204
|
+
let dataValue = Reflect.get($searchItem, "data-value");
|
|
11205
|
+
let isDelete = Boolean($click.closest(`.pops-${popsType}-delete-icon`));
|
|
11206
|
+
if (isDelete) {
|
|
11207
|
+
// 删除
|
|
11098
11208
|
if (typeof config.deleteIcon.callback === "function") {
|
|
11099
|
-
config.deleteIcon.callback(event,
|
|
11209
|
+
config.deleteIcon.callback(event, $searchItem, dataValue);
|
|
11100
11210
|
}
|
|
11101
11211
|
if (!this.$el.$hintULContainer.children.length) {
|
|
11102
11212
|
/* 全删完了 */
|
|
11103
11213
|
this.clear();
|
|
11104
11214
|
}
|
|
11215
|
+
SearchSuggestion.updateStyleSheet();
|
|
11105
11216
|
}
|
|
11106
11217
|
else {
|
|
11107
|
-
|
|
11108
|
-
config.itemClickCallBack(event,
|
|
11218
|
+
// 点击选择项
|
|
11219
|
+
config.itemClickCallBack(event, $searchItem, dataValue);
|
|
11109
11220
|
}
|
|
11110
11221
|
}, {
|
|
11111
11222
|
capture: true,
|
|
@@ -11145,8 +11256,9 @@ var pops = (function () {
|
|
|
11145
11256
|
config.inputTarget.setAttribute("autocomplete", "off");
|
|
11146
11257
|
/* 内容改变事件 */
|
|
11147
11258
|
popsDOMUtils.on(config.inputTarget, "input", void 0, async (event) => {
|
|
11148
|
-
let getListResult = await config.getData(
|
|
11259
|
+
let getListResult = await config.getData(config.inputTarget.value, this.getData());
|
|
11149
11260
|
SearchSuggestion.update(getListResult);
|
|
11261
|
+
SearchSuggestion.updateStyleSheet();
|
|
11150
11262
|
}, option);
|
|
11151
11263
|
},
|
|
11152
11264
|
/**
|
|
@@ -11161,12 +11273,10 @@ var pops = (function () {
|
|
|
11161
11273
|
* 显示搜索建议框的事件
|
|
11162
11274
|
*/
|
|
11163
11275
|
showEvent() {
|
|
11164
|
-
SearchSuggestion.
|
|
11165
|
-
SearchSuggestion.changeHintULElementWidth();
|
|
11166
|
-
SearchSuggestion.changeHintULElementPosition();
|
|
11276
|
+
SearchSuggestion.updateStyleSheet();
|
|
11167
11277
|
if (config.toHideWithNotResult) {
|
|
11168
11278
|
if (SearchSuggestion.$data.isEmpty) {
|
|
11169
|
-
SearchSuggestion.hide();
|
|
11279
|
+
SearchSuggestion.hide(true);
|
|
11170
11280
|
}
|
|
11171
11281
|
else {
|
|
11172
11282
|
SearchSuggestion.show();
|
|
@@ -11225,7 +11335,7 @@ var pops = (function () {
|
|
|
11225
11335
|
/* 点击在目标input内 */
|
|
11226
11336
|
return;
|
|
11227
11337
|
}
|
|
11228
|
-
SearchSuggestion.hide();
|
|
11338
|
+
SearchSuggestion.hide(true);
|
|
11229
11339
|
}
|
|
11230
11340
|
},
|
|
11231
11341
|
/**
|
|
@@ -11350,29 +11460,39 @@ var pops = (function () {
|
|
|
11350
11460
|
else {
|
|
11351
11461
|
// 在下面
|
|
11352
11462
|
position = "bottom";
|
|
11353
|
-
SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top");
|
|
11354
11463
|
}
|
|
11355
11464
|
}
|
|
11356
11465
|
if (position === "top") {
|
|
11466
|
+
// 在上面
|
|
11357
11467
|
if (config.positionTopToReverse) {
|
|
11358
|
-
|
|
11468
|
+
// 自动翻转
|
|
11469
|
+
SearchSuggestion.$el.root.setAttribute("data-top-reverse", "true");
|
|
11359
11470
|
}
|
|
11360
|
-
|
|
11361
|
-
|
|
11362
|
-
|
|
11363
|
-
|
|
11471
|
+
if (config.useFoldAnimation) {
|
|
11472
|
+
// 翻转折叠
|
|
11473
|
+
SearchSuggestion.$el.root.setAttribute("data-popper-placement", "top");
|
|
11474
|
+
}
|
|
11475
|
+
let bottom = documentHeight - targetRect.top + config.topDistance;
|
|
11476
|
+
SearchSuggestion.$el.root.style.top = "";
|
|
11477
|
+
SearchSuggestion.$el.root.style.bottom = bottom + "px";
|
|
11364
11478
|
}
|
|
11365
11479
|
else if (position === "bottom") {
|
|
11366
11480
|
// 在下面
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11481
|
+
if (config.useFoldAnimation) {
|
|
11482
|
+
SearchSuggestion.$el.root.setAttribute("data-popper-placement", "bottom-center");
|
|
11483
|
+
}
|
|
11484
|
+
let top = targetRect.height + targetRect.top + config.topDistance;
|
|
11485
|
+
SearchSuggestion.$el.root.removeAttribute("data-top-reverse");
|
|
11486
|
+
SearchSuggestion.$el.root.style.bottom = "";
|
|
11487
|
+
SearchSuggestion.$el.root.style.top = top + "px";
|
|
11371
11488
|
}
|
|
11489
|
+
let left = targetRect.left;
|
|
11372
11490
|
let hintUIWidth = popsDOMUtils.width(SearchSuggestion.$el.$hintULContainer);
|
|
11373
|
-
|
|
11374
|
-
|
|
11375
|
-
|
|
11491
|
+
if (hintUIWidth > documentWidth) {
|
|
11492
|
+
// 超出宽度
|
|
11493
|
+
left = left + documentWidth - hintUIWidth;
|
|
11494
|
+
}
|
|
11495
|
+
SearchSuggestion.$el.root.style.left = left + "px";
|
|
11376
11496
|
},
|
|
11377
11497
|
/**
|
|
11378
11498
|
* 更新搜索建议框的width
|
|
@@ -11394,6 +11514,17 @@ var pops = (function () {
|
|
|
11394
11514
|
let cssText = this.getDynamicCSS();
|
|
11395
11515
|
PopsSafeUtils.setSafeHTML(this.$el.$dynamicCSS, cssText);
|
|
11396
11516
|
},
|
|
11517
|
+
/**
|
|
11518
|
+
* 数据项的数量改变时调用
|
|
11519
|
+
*/
|
|
11520
|
+
updateStyleSheet() {
|
|
11521
|
+
// 更新z-index
|
|
11522
|
+
SearchSuggestion.updateDynamicCSS();
|
|
11523
|
+
// 更新宽度
|
|
11524
|
+
SearchSuggestion.changeHintULElementWidth();
|
|
11525
|
+
// 更新位置
|
|
11526
|
+
SearchSuggestion.changeHintULElementPosition();
|
|
11527
|
+
},
|
|
11397
11528
|
/**
|
|
11398
11529
|
* 更新页面显示的搜索结果
|
|
11399
11530
|
* @param data
|
|
@@ -11412,7 +11543,7 @@ var pops = (function () {
|
|
|
11412
11543
|
SearchSuggestion.clearAllSearchItemLi();
|
|
11413
11544
|
/* 添加进ul中 */
|
|
11414
11545
|
config.data.forEach((item, index) => {
|
|
11415
|
-
let itemElement = SearchSuggestion.
|
|
11546
|
+
let itemElement = SearchSuggestion.createSearchItemLiElement(item, index);
|
|
11416
11547
|
SearchSuggestion.setSearchItemClickEvent(itemElement);
|
|
11417
11548
|
SearchSuggestion.setSearchItemSelectEvent(itemElement);
|
|
11418
11549
|
SearchSuggestion.$el.$hintULContainer.appendChild(itemElement);
|
|
@@ -11436,15 +11567,32 @@ var pops = (function () {
|
|
|
11436
11567
|
},
|
|
11437
11568
|
/**
|
|
11438
11569
|
* 隐藏搜索建议框
|
|
11570
|
+
* @param useAnimationToHide 是否使用动画隐藏
|
|
11439
11571
|
*/
|
|
11440
|
-
hide() {
|
|
11441
|
-
|
|
11572
|
+
hide(useAnimationToHide = false) {
|
|
11573
|
+
if (config.useFoldAnimation) {
|
|
11574
|
+
if (!useAnimationToHide) {
|
|
11575
|
+
// 去掉动画
|
|
11576
|
+
popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation");
|
|
11577
|
+
}
|
|
11578
|
+
popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation");
|
|
11579
|
+
popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation-hide");
|
|
11580
|
+
popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation-show");
|
|
11581
|
+
}
|
|
11582
|
+
else {
|
|
11583
|
+
this.$el.root.style.display = "none";
|
|
11584
|
+
}
|
|
11442
11585
|
},
|
|
11443
11586
|
/**
|
|
11444
11587
|
* 显示搜索建议框
|
|
11445
11588
|
*/
|
|
11446
11589
|
show() {
|
|
11447
11590
|
this.$el.root.style.display = "";
|
|
11591
|
+
if (config.useFoldAnimation) {
|
|
11592
|
+
popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation");
|
|
11593
|
+
popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation-hide");
|
|
11594
|
+
popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation-show");
|
|
11595
|
+
}
|
|
11448
11596
|
},
|
|
11449
11597
|
};
|
|
11450
11598
|
return SearchSuggestion;
|