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