@whitesev/pops 2.3.7 → 2.4.0
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 +217 -101
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +217 -101
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +217 -101
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +217 -101
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +217 -101
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +217 -101
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Pops.d.ts +16 -9
- package/dist/types/src/components/searchSuggestion/config.d.ts +1 -1
- package/dist/types/src/components/searchSuggestion/index.d.ts +45 -23
- package/dist/types/src/components/searchSuggestion/types/index.d.ts +129 -37
- package/dist/types/src/utils/PopsDOMUtils.d.ts +6 -0
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -2530,6 +2530,36 @@
|
|
|
2530
2530
|
transformTop: transform_top,
|
|
2531
2531
|
};
|
|
2532
2532
|
}
|
|
2533
|
+
/**
|
|
2534
|
+
* 监input、textarea的输入框值改变的事件
|
|
2535
|
+
*/
|
|
2536
|
+
onInput($el, callback, option) {
|
|
2537
|
+
let isComposite = false;
|
|
2538
|
+
let __callback = async (event) => {
|
|
2539
|
+
if (isComposite)
|
|
2540
|
+
return;
|
|
2541
|
+
await callback(event);
|
|
2542
|
+
};
|
|
2543
|
+
let __composition_start_callback = () => {
|
|
2544
|
+
isComposite = true;
|
|
2545
|
+
};
|
|
2546
|
+
let __composition_end_callback = () => {
|
|
2547
|
+
isComposite = false;
|
|
2548
|
+
this.trigger($el, "input", {
|
|
2549
|
+
isComposite,
|
|
2550
|
+
});
|
|
2551
|
+
};
|
|
2552
|
+
this.on($el, "input", __callback, option);
|
|
2553
|
+
this.on($el, "compositionstart", __composition_start_callback, option);
|
|
2554
|
+
this.on($el, "compositionend", __composition_end_callback, option);
|
|
2555
|
+
return {
|
|
2556
|
+
off: () => {
|
|
2557
|
+
this.off($el, "input", __callback, option);
|
|
2558
|
+
this.off($el, "compositionstart", __composition_start_callback, option);
|
|
2559
|
+
this.off($el, "compositionend", __composition_end_callback, option);
|
|
2560
|
+
},
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2533
2563
|
}
|
|
2534
2564
|
const popsDOMUtils = new PopsDOMUtils();
|
|
2535
2565
|
|
|
@@ -10896,6 +10926,22 @@
|
|
|
10896
10926
|
data.push({
|
|
10897
10927
|
value: `测试${index}`,
|
|
10898
10928
|
text: `测试${index}-html`,
|
|
10929
|
+
enableDeleteButton: true,
|
|
10930
|
+
deleteButtonClickCallback(event, $dataItem, dataItem, config) {
|
|
10931
|
+
console.log("删除当前项", [event, $dataItem, dataItem, config]);
|
|
10932
|
+
return true;
|
|
10933
|
+
},
|
|
10934
|
+
itemView(dateItem, $parent) {
|
|
10935
|
+
return dateItem.text;
|
|
10936
|
+
},
|
|
10937
|
+
clickCallback(event, $dataItem, dataItem, config) {
|
|
10938
|
+
console.log("item项的点击回调", [event, $dataItem, data, config]);
|
|
10939
|
+
// config.inputTarget!.value = dataItem.value;
|
|
10940
|
+
return index % 2 === 0 ? true : false;
|
|
10941
|
+
},
|
|
10942
|
+
selectCallback(event, $dataItem, dataItem, config) {
|
|
10943
|
+
console.log("item项的选中回调", [event, $dataItem, data, config]);
|
|
10944
|
+
},
|
|
10899
10945
|
});
|
|
10900
10946
|
}
|
|
10901
10947
|
return {
|
|
@@ -10905,14 +10951,6 @@
|
|
|
10905
10951
|
inputTarget: null,
|
|
10906
10952
|
selfDocument: document,
|
|
10907
10953
|
data: data,
|
|
10908
|
-
deleteIcon: {
|
|
10909
|
-
enable: true,
|
|
10910
|
-
callback(event, liElement, dataItem) {
|
|
10911
|
-
console.log("删除当前项", [event, liElement, dataItem]);
|
|
10912
|
-
data.splice(data.indexOf(dataItem), 1);
|
|
10913
|
-
liElement.remove();
|
|
10914
|
-
},
|
|
10915
|
-
},
|
|
10916
10954
|
useShadowRoot: true,
|
|
10917
10955
|
className: "",
|
|
10918
10956
|
isAbsolute: true,
|
|
@@ -10930,20 +10968,10 @@
|
|
|
10930
10968
|
toSearhNotResultHTML: '<li data-none="true">暂无其它数据</li>',
|
|
10931
10969
|
toHideWithNotResult: false,
|
|
10932
10970
|
followPosition: "target",
|
|
10933
|
-
|
|
10934
|
-
return item.text ?? item;
|
|
10935
|
-
},
|
|
10936
|
-
async getData(value, data) {
|
|
10971
|
+
async inputTargetChangeRefreshShowDataCallback(value, data) {
|
|
10937
10972
|
console.log("当前输入框的值是:", value);
|
|
10938
10973
|
return data.filter((it) => it.value.includes(value));
|
|
10939
10974
|
},
|
|
10940
|
-
itemClickCallBack(event, liElement, data) {
|
|
10941
|
-
console.log("item项的点击回调", [event, liElement, data]);
|
|
10942
|
-
this.inputTarget.value = data.value;
|
|
10943
|
-
},
|
|
10944
|
-
selectCallBack(event, liElement, data) {
|
|
10945
|
-
console.log("item项的选中回调", [event, liElement, data]);
|
|
10946
|
-
},
|
|
10947
10975
|
style: "",
|
|
10948
10976
|
};
|
|
10949
10977
|
};
|
|
@@ -11003,33 +11031,49 @@
|
|
|
11003
11031
|
/** 动态更新CSS */
|
|
11004
11032
|
$dynamicCSS: null,
|
|
11005
11033
|
},
|
|
11034
|
+
$evt: {
|
|
11035
|
+
offInputChangeEvtHandler: [],
|
|
11036
|
+
},
|
|
11006
11037
|
$data: {
|
|
11007
11038
|
/** 是否结果为空 */
|
|
11008
11039
|
isEmpty: true,
|
|
11009
11040
|
},
|
|
11010
|
-
/** 初始化元素变量 */
|
|
11011
|
-
initEl() {
|
|
11012
|
-
this.$el.root = SearchSuggestion.createSearchSelectElement();
|
|
11013
|
-
this.$el.$dynamicCSS = this.$el.root.querySelector("style[data-dynamic]");
|
|
11014
|
-
this.$el.$hintULContainer = SearchSuggestion.$el.root.querySelector("ul");
|
|
11015
|
-
},
|
|
11016
11041
|
/**
|
|
11017
11042
|
* 初始化
|
|
11043
|
+
* @param parentElement 父元素
|
|
11018
11044
|
*/
|
|
11019
11045
|
init(parentElement = document.body || document.documentElement) {
|
|
11020
|
-
|
|
11021
|
-
SearchSuggestion.update(
|
|
11046
|
+
SearchSuggestion.initEl();
|
|
11047
|
+
SearchSuggestion.update(SearchSuggestion.getData());
|
|
11022
11048
|
SearchSuggestion.updateStyleSheet();
|
|
11023
11049
|
SearchSuggestion.hide();
|
|
11024
11050
|
$shadowRoot.appendChild(SearchSuggestion.$el.root);
|
|
11025
11051
|
parentElement.appendChild($shadowContainer);
|
|
11026
11052
|
},
|
|
11053
|
+
/**
|
|
11054
|
+
* 初始化元素变量
|
|
11055
|
+
*/
|
|
11056
|
+
initEl() {
|
|
11057
|
+
SearchSuggestion.$el.root = SearchSuggestion.createSearchSelectElement();
|
|
11058
|
+
Reflect.set(SearchSuggestion.$el.root, "data-SearchSuggestion", SearchSuggestion);
|
|
11059
|
+
SearchSuggestion.$el.$dynamicCSS =
|
|
11060
|
+
SearchSuggestion.$el.root.querySelector("style[data-dynamic]");
|
|
11061
|
+
SearchSuggestion.$el.$hintULContainer =
|
|
11062
|
+
SearchSuggestion.$el.root.querySelector("ul");
|
|
11063
|
+
},
|
|
11027
11064
|
/**
|
|
11028
11065
|
* 获取数据
|
|
11029
11066
|
*/
|
|
11030
11067
|
getData() {
|
|
11031
11068
|
return typeof config.data === "function" ? config.data() : config.data;
|
|
11032
11069
|
},
|
|
11070
|
+
/**
|
|
11071
|
+
* 更新数据
|
|
11072
|
+
* @param data 数据
|
|
11073
|
+
*/
|
|
11074
|
+
setData(data) {
|
|
11075
|
+
config.data = data;
|
|
11076
|
+
},
|
|
11033
11077
|
/**
|
|
11034
11078
|
* 获取显示出搜索建议框的html
|
|
11035
11079
|
*/
|
|
@@ -11037,7 +11081,7 @@
|
|
|
11037
11081
|
let $el = popsDOMUtils.createElement("div", {
|
|
11038
11082
|
className: `pops pops-${popsType}-search-suggestion`,
|
|
11039
11083
|
innerHTML: /*html*/ `
|
|
11040
|
-
<style>
|
|
11084
|
+
<style type="text/css">
|
|
11041
11085
|
.pops-${popsType}-animation{
|
|
11042
11086
|
-moz-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11043
11087
|
-webkit-animation: searchSelectFalIn 0.5s 1 linear;
|
|
@@ -11045,7 +11089,7 @@
|
|
|
11045
11089
|
-ms-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11046
11090
|
}
|
|
11047
11091
|
</style>
|
|
11048
|
-
<style>
|
|
11092
|
+
<style type="text/css">
|
|
11049
11093
|
.pops-${popsType}-search-suggestion-arrow{
|
|
11050
11094
|
--suggestion-arrow-box-shadow-left-color: rgba(0, 0, 0, 0.24);
|
|
11051
11095
|
--suggestion-arrow-box-shadow-right-color: rgba(0, 0, 0, 0.12);
|
|
@@ -11111,8 +11155,8 @@
|
|
|
11111
11155
|
content: "";
|
|
11112
11156
|
}
|
|
11113
11157
|
</style>
|
|
11114
|
-
<style data-dynamic="true">
|
|
11115
|
-
${
|
|
11158
|
+
<style type="text/css" data-dynamic="true">
|
|
11159
|
+
${SearchSuggestion.getDynamicCSS()}
|
|
11116
11160
|
</style>
|
|
11117
11161
|
<style>
|
|
11118
11162
|
.el-zoom-in-top-animation{
|
|
@@ -11133,6 +11177,9 @@
|
|
|
11133
11177
|
transform: scaleY(1);
|
|
11134
11178
|
}
|
|
11135
11179
|
</style>
|
|
11180
|
+
<style type="text/css" data-user-css>
|
|
11181
|
+
${config.style || ""}
|
|
11182
|
+
</style>
|
|
11136
11183
|
<ul class="pops-${popsType}-search-suggestion-hint ${PopsCommonCSSClassName.userSelectNone}">${config.toSearhNotResultHTML}</ul>
|
|
11137
11184
|
${config.useArrow ? /*html*/ `<div class="pops-${popsType}-search-suggestion-arrow"></div>` : ""}
|
|
11138
11185
|
`,
|
|
@@ -11151,7 +11198,9 @@
|
|
|
11151
11198
|
}
|
|
11152
11199
|
return $el;
|
|
11153
11200
|
},
|
|
11154
|
-
/**
|
|
11201
|
+
/**
|
|
11202
|
+
* 动态获取CSS
|
|
11203
|
+
*/
|
|
11155
11204
|
getDynamicCSS() {
|
|
11156
11205
|
return /*css*/ `
|
|
11157
11206
|
.pops-${popsType}-search-suggestion{
|
|
@@ -11216,53 +11265,82 @@
|
|
|
11216
11265
|
}
|
|
11217
11266
|
`;
|
|
11218
11267
|
},
|
|
11268
|
+
/**
|
|
11269
|
+
* 获取data-value值
|
|
11270
|
+
* @param data 数据项
|
|
11271
|
+
*/
|
|
11272
|
+
getItemDataValue(data) {
|
|
11273
|
+
return data;
|
|
11274
|
+
},
|
|
11219
11275
|
/**
|
|
11220
11276
|
* 获取显示出搜索建议框的每一项的html
|
|
11221
|
-
* @param
|
|
11222
|
-
* @param
|
|
11277
|
+
* @param dataItem 当前项的值
|
|
11278
|
+
* @param dateItemIndex 当前项的下标
|
|
11223
11279
|
*/
|
|
11224
|
-
createSearchItemLiElement(
|
|
11280
|
+
createSearchItemLiElement(dataItem, dateItemIndex) {
|
|
11281
|
+
const dataValue = SearchSuggestion.getItemDataValue(dataItem);
|
|
11225
11282
|
let $li = popsDOMUtils.createElement("li", {
|
|
11226
11283
|
className: `pops-${popsType}-search-suggestion-hint-item`,
|
|
11227
|
-
"data-index":
|
|
11228
|
-
"data-value":
|
|
11229
|
-
innerHTML: `${config.getItemHTML(data)}${config.deleteIcon.enable ? SearchSuggestion.getDeleteIconHTML() : ""}`,
|
|
11284
|
+
"data-index": dateItemIndex,
|
|
11285
|
+
"data-value": dataValue,
|
|
11230
11286
|
});
|
|
11287
|
+
Reflect.set($li, "data-index", dateItemIndex);
|
|
11288
|
+
Reflect.set($li, "data-value", dataValue);
|
|
11289
|
+
// 项内容
|
|
11290
|
+
let $itemInner = dataItem.itemView(dataItem, $li, config);
|
|
11291
|
+
if (typeof $itemInner === "string") {
|
|
11292
|
+
PopsSafeUtils.setSafeHTML($li, $itemInner);
|
|
11293
|
+
}
|
|
11294
|
+
else {
|
|
11295
|
+
popsDOMUtils.append($li, $itemInner);
|
|
11296
|
+
}
|
|
11297
|
+
// 删除按钮
|
|
11298
|
+
const enableDeleteButton = dataItem.enableDeleteButton;
|
|
11299
|
+
if (typeof enableDeleteButton === "boolean" && enableDeleteButton) {
|
|
11300
|
+
let $deleteIcon = SearchSuggestion.createItemDeleteIcon();
|
|
11301
|
+
popsDOMUtils.append($li, $deleteIcon);
|
|
11302
|
+
}
|
|
11231
11303
|
popsDOMUtils.addClassName($li, PopsCommonCSSClassName.flexCenter);
|
|
11232
11304
|
popsDOMUtils.addClassName($li, PopsCommonCSSClassName.flexYCenter);
|
|
11233
11305
|
return $li;
|
|
11234
11306
|
},
|
|
11235
|
-
/**
|
|
11236
|
-
* 获取data-value值
|
|
11237
|
-
* @param data
|
|
11238
|
-
*/
|
|
11239
|
-
getItemDataValue(data) {
|
|
11240
|
-
return data;
|
|
11241
|
-
},
|
|
11242
11307
|
/**
|
|
11243
11308
|
* 设置搜索建议框每一项的点击事件
|
|
11244
|
-
* @param $searchItem
|
|
11309
|
+
* @param $searchItem 当前项的元素
|
|
11245
11310
|
*/
|
|
11246
11311
|
setSearchItemClickEvent($searchItem) {
|
|
11247
|
-
popsDOMUtils.on($searchItem, "click", (event) => {
|
|
11312
|
+
popsDOMUtils.on($searchItem, "click", async (event) => {
|
|
11248
11313
|
popsDOMUtils.preventEvent(event);
|
|
11249
11314
|
let $click = event.target;
|
|
11250
|
-
|
|
11315
|
+
const data = SearchSuggestion.getData();
|
|
11316
|
+
const dataItem = Reflect.get($searchItem, "data-value");
|
|
11251
11317
|
let isDelete = Boolean($click.closest(`.pops-${popsType}-delete-icon`));
|
|
11252
11318
|
if (isDelete) {
|
|
11253
11319
|
// 删除
|
|
11254
|
-
if (typeof
|
|
11255
|
-
|
|
11320
|
+
if (typeof dataItem.deleteButtonClickCallback === "function") {
|
|
11321
|
+
let result = await dataItem.deleteButtonClickCallback(event, $searchItem, dataItem, config);
|
|
11322
|
+
if (typeof result === "boolean" && result) {
|
|
11323
|
+
data.splice(data.indexOf(dataItem), 1);
|
|
11324
|
+
$searchItem.remove();
|
|
11325
|
+
}
|
|
11256
11326
|
}
|
|
11257
|
-
if (!
|
|
11327
|
+
if (!SearchSuggestion.$el.$hintULContainer.children.length) {
|
|
11258
11328
|
/* 全删完了 */
|
|
11259
|
-
|
|
11329
|
+
SearchSuggestion.clear();
|
|
11260
11330
|
}
|
|
11261
11331
|
SearchSuggestion.updateStyleSheet();
|
|
11262
11332
|
}
|
|
11263
11333
|
else {
|
|
11264
11334
|
// 点击选择项
|
|
11265
|
-
|
|
11335
|
+
if (typeof dataItem.clickCallback === "function") {
|
|
11336
|
+
let result = await dataItem.clickCallback(event, $searchItem, dataItem, config);
|
|
11337
|
+
if (typeof result === "boolean" && result) {
|
|
11338
|
+
if (config.inputTarget instanceof HTMLInputElement ||
|
|
11339
|
+
config.inputTarget instanceof HTMLTextAreaElement) {
|
|
11340
|
+
config.inputTarget.value = String(dataItem.value);
|
|
11341
|
+
}
|
|
11342
|
+
}
|
|
11343
|
+
}
|
|
11266
11344
|
}
|
|
11267
11345
|
}, {
|
|
11268
11346
|
capture: true,
|
|
@@ -11301,11 +11379,13 @@
|
|
|
11301
11379
|
/* 禁用输入框自动提示 */
|
|
11302
11380
|
config.inputTarget.setAttribute("autocomplete", "off");
|
|
11303
11381
|
/* 内容改变事件 */
|
|
11304
|
-
popsDOMUtils.
|
|
11305
|
-
|
|
11306
|
-
|
|
11382
|
+
const listenerHandler = popsDOMUtils.onInput(config.inputTarget, async (event) => {
|
|
11383
|
+
const data = SearchSuggestion.getData();
|
|
11384
|
+
let queryDataResult = await config.inputTargetChangeRefreshShowDataCallback(config.inputTarget.value, data, config);
|
|
11385
|
+
SearchSuggestion.update(queryDataResult);
|
|
11307
11386
|
SearchSuggestion.updateStyleSheet();
|
|
11308
11387
|
}, option);
|
|
11388
|
+
SearchSuggestion.$evt.offInputChangeEvtHandler.push(listenerHandler.off);
|
|
11309
11389
|
},
|
|
11310
11390
|
/**
|
|
11311
11391
|
* 移除输入框内容改变的监听
|
|
@@ -11313,7 +11393,12 @@
|
|
|
11313
11393
|
removeInputChangeEvent(option = {
|
|
11314
11394
|
capture: true,
|
|
11315
11395
|
}) {
|
|
11316
|
-
|
|
11396
|
+
for (let index = 0; index < SearchSuggestion.$evt.offInputChangeEvtHandler.length; index++) {
|
|
11397
|
+
const handler = SearchSuggestion.$evt.offInputChangeEvtHandler[index];
|
|
11398
|
+
handler();
|
|
11399
|
+
SearchSuggestion.$evt.offInputChangeEvtHandler.splice(index, 1);
|
|
11400
|
+
index--;
|
|
11401
|
+
}
|
|
11317
11402
|
},
|
|
11318
11403
|
/**
|
|
11319
11404
|
* 显示搜索建议框的事件
|
|
@@ -11439,23 +11524,24 @@
|
|
|
11439
11524
|
/**
|
|
11440
11525
|
* 获取删除按钮的html
|
|
11441
11526
|
*/
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11527
|
+
createItemDeleteIcon(size = 16, fill = "#bababa") {
|
|
11528
|
+
let $svg = popsDOMUtils.parseTextToDOM(/*html*/ `
|
|
11529
|
+
<svg class="pops-${popsType}-delete-icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" fill="${fill}">
|
|
11530
|
+
<path d="M512 883.2A371.2 371.2 0 1 0 140.8 512 371.2 371.2 0 0 0 512 883.2z m0 64a435.2 435.2 0 1 1 435.2-435.2 435.2 435.2 0 0 1-435.2 435.2z"></path>
|
|
11531
|
+
<path d="M557.056 512l122.368 122.368a31.744 31.744 0 1 1-45.056 45.056L512 557.056l-122.368 122.368a31.744 31.744 0 1 1-45.056-45.056L466.944 512 344.576 389.632a31.744 31.744 0 1 1 45.056-45.056L512 466.944l122.368-122.368a31.744 31.744 0 1 1 45.056 45.056z"></path>
|
|
11532
|
+
</svg>
|
|
11533
|
+
`);
|
|
11534
|
+
return $svg;
|
|
11449
11535
|
},
|
|
11450
11536
|
/**
|
|
11451
11537
|
* 设置当前正在搜索中的提示
|
|
11452
11538
|
*/
|
|
11453
11539
|
setPromptsInSearch() {
|
|
11454
|
-
let
|
|
11540
|
+
let $isSearching = popsDOMUtils.createElement("li", {
|
|
11455
11541
|
className: `pops-${popsType}-search-suggestion-hint-searching-item`,
|
|
11456
11542
|
innerHTML: config.searchingTip,
|
|
11457
11543
|
});
|
|
11458
|
-
SearchSuggestion
|
|
11544
|
+
SearchSuggestion.addItem($isSearching);
|
|
11459
11545
|
},
|
|
11460
11546
|
/**
|
|
11461
11547
|
* 移除正在搜索中的提示
|
|
@@ -11465,17 +11551,13 @@
|
|
|
11465
11551
|
.querySelector(`li.pops-${popsType}-search-suggestion-hint-searching-item`)
|
|
11466
11552
|
?.remove();
|
|
11467
11553
|
},
|
|
11468
|
-
/**
|
|
11469
|
-
* 清空所有的搜索结果
|
|
11470
|
-
*/
|
|
11471
|
-
clearAllSearchItemLi() {
|
|
11472
|
-
PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$hintULContainer, "");
|
|
11473
|
-
},
|
|
11474
11554
|
/**
|
|
11475
11555
|
* 更新搜索建议框的位置(top、left)
|
|
11476
11556
|
* 因为目标元素可能是动态隐藏的
|
|
11557
|
+
* @param target 目标元素
|
|
11558
|
+
* @param checkPositonAgain 是否在更新位置信息后检测更新位置信息,默认true
|
|
11477
11559
|
*/
|
|
11478
|
-
changeHintULElementPosition(target = config.target ?? config.inputTarget) {
|
|
11560
|
+
changeHintULElementPosition(target = config.target ?? config.inputTarget, checkPositonAgain = true) {
|
|
11479
11561
|
let targetRect = null;
|
|
11480
11562
|
if (config.followPosition === "inputCursor") {
|
|
11481
11563
|
targetRect = popsDOMUtils.getTextBoundingRect(config.inputTarget, config.inputTarget.selectionStart || 0, config.inputTarget.selectionEnd || 0, false);
|
|
@@ -11499,6 +11581,7 @@
|
|
|
11499
11581
|
// 需目标高度+搜索建议框高度大于文档高度,则显示在上面
|
|
11500
11582
|
let targetBottom = targetRect.bottom;
|
|
11501
11583
|
let searchSuggestionContainerHeight = popsDOMUtils.height(SearchSuggestion.$el.$hintULContainer);
|
|
11584
|
+
console.log(targetBottom, searchSuggestionContainerHeight, targetBottom + searchSuggestionContainerHeight, documentHeight);
|
|
11502
11585
|
if (targetBottom + searchSuggestionContainerHeight > documentHeight) {
|
|
11503
11586
|
// 在上面
|
|
11504
11587
|
position = "top";
|
|
@@ -11539,10 +11622,19 @@
|
|
|
11539
11622
|
left = left + documentWidth - hintUIWidth;
|
|
11540
11623
|
}
|
|
11541
11624
|
SearchSuggestion.$el.root.style.left = left + "px";
|
|
11625
|
+
// 如果更新前在下面的话且高度超出了屏幕
|
|
11626
|
+
// 这时候会有滚动条,会造成位置偏移
|
|
11627
|
+
// 更新后的位置却在上面,这时候的位置信息不对齐
|
|
11628
|
+
// 需重新更新位置
|
|
11629
|
+
// 此情况一般是config.position === "auto"
|
|
11630
|
+
if (checkPositonAgain) {
|
|
11631
|
+
SearchSuggestion.changeHintULElementPosition(target, !checkPositonAgain);
|
|
11632
|
+
}
|
|
11542
11633
|
},
|
|
11543
11634
|
/**
|
|
11544
11635
|
* 更新搜索建议框的width
|
|
11545
11636
|
* 因为目标元素可能是动态隐藏的
|
|
11637
|
+
* @param target 目标元素
|
|
11546
11638
|
*/
|
|
11547
11639
|
changeHintULElementWidth(target = config.target ?? config.inputTarget) {
|
|
11548
11640
|
let targetRect = target.getBoundingClientRect();
|
|
@@ -11557,11 +11649,15 @@
|
|
|
11557
11649
|
* 动态更新CSS
|
|
11558
11650
|
*/
|
|
11559
11651
|
updateDynamicCSS() {
|
|
11560
|
-
let cssText =
|
|
11561
|
-
PopsSafeUtils.setSafeHTML(
|
|
11652
|
+
let cssText = SearchSuggestion.getDynamicCSS();
|
|
11653
|
+
PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$dynamicCSS, cssText);
|
|
11562
11654
|
},
|
|
11563
11655
|
/**
|
|
11564
11656
|
* 数据项的数量改变时调用
|
|
11657
|
+
*
|
|
11658
|
+
* - 更新css
|
|
11659
|
+
* - 更新建议框的宽度
|
|
11660
|
+
* - 更新建议框的位置
|
|
11565
11661
|
*/
|
|
11566
11662
|
updateStyleSheet() {
|
|
11567
11663
|
// 更新z-index
|
|
@@ -11571,29 +11667,38 @@
|
|
|
11571
11667
|
// 更新位置
|
|
11572
11668
|
SearchSuggestion.changeHintULElementPosition();
|
|
11573
11669
|
},
|
|
11670
|
+
/**
|
|
11671
|
+
* 添加搜索结果元素
|
|
11672
|
+
* @param $item 项元素
|
|
11673
|
+
*/
|
|
11674
|
+
addItem($item) {
|
|
11675
|
+
SearchSuggestion.$el.$hintULContainer.appendChild($item);
|
|
11676
|
+
},
|
|
11574
11677
|
/**
|
|
11575
11678
|
* 更新页面显示的搜索结果
|
|
11576
|
-
* @param
|
|
11679
|
+
* @param updateData
|
|
11577
11680
|
*/
|
|
11578
|
-
update(
|
|
11579
|
-
if (!Array.isArray(
|
|
11681
|
+
update(updateData = []) {
|
|
11682
|
+
if (!Array.isArray(updateData)) {
|
|
11580
11683
|
throw new TypeError("传入的数据不是数组");
|
|
11581
11684
|
}
|
|
11582
|
-
|
|
11685
|
+
const data = updateData;
|
|
11583
11686
|
/* 清空已有的搜索结果 */
|
|
11584
|
-
if (
|
|
11687
|
+
if (data.length) {
|
|
11585
11688
|
SearchSuggestion.$data.isEmpty = false;
|
|
11586
11689
|
if (config.toHideWithNotResult) {
|
|
11587
11690
|
SearchSuggestion.show();
|
|
11588
11691
|
}
|
|
11589
|
-
SearchSuggestion.
|
|
11692
|
+
SearchSuggestion.clear(true);
|
|
11590
11693
|
/* 添加进ul中 */
|
|
11591
|
-
|
|
11592
|
-
|
|
11593
|
-
SearchSuggestion.
|
|
11594
|
-
SearchSuggestion.
|
|
11595
|
-
SearchSuggestion
|
|
11694
|
+
let fragment = document.createDocumentFragment();
|
|
11695
|
+
data.forEach((item, index) => {
|
|
11696
|
+
let $item = SearchSuggestion.createSearchItemLiElement(item, index);
|
|
11697
|
+
SearchSuggestion.setSearchItemClickEvent($item);
|
|
11698
|
+
SearchSuggestion.setSearchItemSelectEvent($item);
|
|
11699
|
+
fragment.appendChild($item);
|
|
11596
11700
|
});
|
|
11701
|
+
SearchSuggestion.addItem(fragment);
|
|
11597
11702
|
}
|
|
11598
11703
|
else {
|
|
11599
11704
|
/* 清空 */
|
|
@@ -11602,13 +11707,24 @@
|
|
|
11602
11707
|
},
|
|
11603
11708
|
/**
|
|
11604
11709
|
* 清空当前的搜索结果并显示无结果
|
|
11710
|
+
* @param [onlyClearView=false] 是否仅清空元素,默认false
|
|
11605
11711
|
*/
|
|
11606
|
-
clear() {
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
|
|
11712
|
+
clear(onlyClearView = false) {
|
|
11713
|
+
PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$hintULContainer, "");
|
|
11714
|
+
if (onlyClearView) {
|
|
11715
|
+
return;
|
|
11716
|
+
}
|
|
11717
|
+
SearchSuggestion.$data.isEmpty = true;
|
|
11718
|
+
let $noResult;
|
|
11719
|
+
if (typeof config.toSearhNotResultHTML === "string") {
|
|
11720
|
+
$noResult = popsDOMUtils.parseTextToDOM(config.toSearhNotResultHTML);
|
|
11721
|
+
}
|
|
11722
|
+
else {
|
|
11723
|
+
$noResult = config.toSearhNotResultHTML();
|
|
11724
|
+
}
|
|
11725
|
+
SearchSuggestion.addItem($noResult);
|
|
11610
11726
|
if (config.toHideWithNotResult) {
|
|
11611
|
-
|
|
11727
|
+
SearchSuggestion.hide();
|
|
11612
11728
|
}
|
|
11613
11729
|
},
|
|
11614
11730
|
/**
|
|
@@ -11619,25 +11735,25 @@
|
|
|
11619
11735
|
if (config.useFoldAnimation) {
|
|
11620
11736
|
if (!useAnimationToHide) {
|
|
11621
11737
|
// 去掉动画
|
|
11622
|
-
popsDOMUtils.removeClassName(
|
|
11738
|
+
popsDOMUtils.removeClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation");
|
|
11623
11739
|
}
|
|
11624
|
-
popsDOMUtils.addClassName(
|
|
11625
|
-
popsDOMUtils.addClassName(
|
|
11626
|
-
popsDOMUtils.removeClassName(
|
|
11740
|
+
popsDOMUtils.addClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation");
|
|
11741
|
+
popsDOMUtils.addClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation-hide");
|
|
11742
|
+
popsDOMUtils.removeClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation-show");
|
|
11627
11743
|
}
|
|
11628
11744
|
else {
|
|
11629
|
-
|
|
11745
|
+
SearchSuggestion.$el.root.style.display = "none";
|
|
11630
11746
|
}
|
|
11631
11747
|
},
|
|
11632
11748
|
/**
|
|
11633
11749
|
* 显示搜索建议框
|
|
11634
11750
|
*/
|
|
11635
11751
|
show() {
|
|
11636
|
-
|
|
11752
|
+
SearchSuggestion.$el.root.style.display = "";
|
|
11637
11753
|
if (config.useFoldAnimation) {
|
|
11638
|
-
popsDOMUtils.addClassName(
|
|
11639
|
-
popsDOMUtils.removeClassName(
|
|
11640
|
-
popsDOMUtils.addClassName(
|
|
11754
|
+
popsDOMUtils.addClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation");
|
|
11755
|
+
popsDOMUtils.removeClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation-hide");
|
|
11756
|
+
popsDOMUtils.addClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation-show");
|
|
11641
11757
|
}
|
|
11642
11758
|
},
|
|
11643
11759
|
};
|
|
@@ -11649,7 +11765,7 @@
|
|
|
11649
11765
|
/** 配置 */
|
|
11650
11766
|
config = {
|
|
11651
11767
|
/** 版本号 */
|
|
11652
|
-
version: "2025.
|
|
11768
|
+
version: "2025.9.4",
|
|
11653
11769
|
cssText: PopsCSS,
|
|
11654
11770
|
/** icon图标的svg代码 */
|
|
11655
11771
|
iconSVG: PopsIcon.$data,
|