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