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