@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.cjs.js
CHANGED
|
@@ -2526,6 +2526,36 @@ class PopsDOMUtils extends PopsDOMUtilsEvent {
|
|
|
2526
2526
|
transformTop: transform_top,
|
|
2527
2527
|
};
|
|
2528
2528
|
}
|
|
2529
|
+
/**
|
|
2530
|
+
* 监input、textarea的输入框值改变的事件
|
|
2531
|
+
*/
|
|
2532
|
+
onInput($el, callback, option) {
|
|
2533
|
+
let isComposite = false;
|
|
2534
|
+
let __callback = async (event) => {
|
|
2535
|
+
if (isComposite)
|
|
2536
|
+
return;
|
|
2537
|
+
await callback(event);
|
|
2538
|
+
};
|
|
2539
|
+
let __composition_start_callback = () => {
|
|
2540
|
+
isComposite = true;
|
|
2541
|
+
};
|
|
2542
|
+
let __composition_end_callback = () => {
|
|
2543
|
+
isComposite = false;
|
|
2544
|
+
this.trigger($el, "input", {
|
|
2545
|
+
isComposite,
|
|
2546
|
+
});
|
|
2547
|
+
};
|
|
2548
|
+
this.on($el, "input", __callback, option);
|
|
2549
|
+
this.on($el, "compositionstart", __composition_start_callback, option);
|
|
2550
|
+
this.on($el, "compositionend", __composition_end_callback, option);
|
|
2551
|
+
return {
|
|
2552
|
+
off: () => {
|
|
2553
|
+
this.off($el, "input", __callback, option);
|
|
2554
|
+
this.off($el, "compositionstart", __composition_start_callback, option);
|
|
2555
|
+
this.off($el, "compositionend", __composition_end_callback, option);
|
|
2556
|
+
},
|
|
2557
|
+
};
|
|
2558
|
+
}
|
|
2529
2559
|
}
|
|
2530
2560
|
const popsDOMUtils = new PopsDOMUtils();
|
|
2531
2561
|
|
|
@@ -10892,6 +10922,22 @@ const searchSuggestionConfig = () => {
|
|
|
10892
10922
|
data.push({
|
|
10893
10923
|
value: `测试${index}`,
|
|
10894
10924
|
text: `测试${index}-html`,
|
|
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 dateItem.text;
|
|
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
|
+
},
|
|
10895
10941
|
});
|
|
10896
10942
|
}
|
|
10897
10943
|
return {
|
|
@@ -10901,14 +10947,6 @@ const searchSuggestionConfig = () => {
|
|
|
10901
10947
|
inputTarget: null,
|
|
10902
10948
|
selfDocument: document,
|
|
10903
10949
|
data: data,
|
|
10904
|
-
deleteIcon: {
|
|
10905
|
-
enable: true,
|
|
10906
|
-
callback(event, liElement, dataItem) {
|
|
10907
|
-
console.log("删除当前项", [event, liElement, dataItem]);
|
|
10908
|
-
data.splice(data.indexOf(dataItem), 1);
|
|
10909
|
-
liElement.remove();
|
|
10910
|
-
},
|
|
10911
|
-
},
|
|
10912
10950
|
useShadowRoot: true,
|
|
10913
10951
|
className: "",
|
|
10914
10952
|
isAbsolute: true,
|
|
@@ -10926,20 +10964,10 @@ const searchSuggestionConfig = () => {
|
|
|
10926
10964
|
toSearhNotResultHTML: '<li data-none="true">暂无其它数据</li>',
|
|
10927
10965
|
toHideWithNotResult: false,
|
|
10928
10966
|
followPosition: "target",
|
|
10929
|
-
|
|
10930
|
-
return item.text ?? item;
|
|
10931
|
-
},
|
|
10932
|
-
async getData(value, data) {
|
|
10967
|
+
async inputTargetChangeRefreshShowDataCallback(value, data) {
|
|
10933
10968
|
console.log("当前输入框的值是:", value);
|
|
10934
10969
|
return data.filter((it) => it.value.includes(value));
|
|
10935
10970
|
},
|
|
10936
|
-
itemClickCallBack(event, liElement, data) {
|
|
10937
|
-
console.log("item项的点击回调", [event, liElement, data]);
|
|
10938
|
-
this.inputTarget.value = data.value;
|
|
10939
|
-
},
|
|
10940
|
-
selectCallBack(event, liElement, data) {
|
|
10941
|
-
console.log("item项的选中回调", [event, liElement, data]);
|
|
10942
|
-
},
|
|
10943
10971
|
style: "",
|
|
10944
10972
|
};
|
|
10945
10973
|
};
|
|
@@ -10999,33 +11027,49 @@ const PopsSearchSuggestion = {
|
|
|
10999
11027
|
/** 动态更新CSS */
|
|
11000
11028
|
$dynamicCSS: null,
|
|
11001
11029
|
},
|
|
11030
|
+
$evt: {
|
|
11031
|
+
offInputChangeEvtHandler: [],
|
|
11032
|
+
},
|
|
11002
11033
|
$data: {
|
|
11003
11034
|
/** 是否结果为空 */
|
|
11004
11035
|
isEmpty: true,
|
|
11005
11036
|
},
|
|
11006
|
-
/** 初始化元素变量 */
|
|
11007
|
-
initEl() {
|
|
11008
|
-
this.$el.root = SearchSuggestion.createSearchSelectElement();
|
|
11009
|
-
this.$el.$dynamicCSS = this.$el.root.querySelector("style[data-dynamic]");
|
|
11010
|
-
this.$el.$hintULContainer = SearchSuggestion.$el.root.querySelector("ul");
|
|
11011
|
-
},
|
|
11012
11037
|
/**
|
|
11013
11038
|
* 初始化
|
|
11039
|
+
* @param parentElement 父元素
|
|
11014
11040
|
*/
|
|
11015
11041
|
init(parentElement = document.body || document.documentElement) {
|
|
11016
|
-
|
|
11017
|
-
SearchSuggestion.update(
|
|
11042
|
+
SearchSuggestion.initEl();
|
|
11043
|
+
SearchSuggestion.update(SearchSuggestion.getData());
|
|
11018
11044
|
SearchSuggestion.updateStyleSheet();
|
|
11019
11045
|
SearchSuggestion.hide();
|
|
11020
11046
|
$shadowRoot.appendChild(SearchSuggestion.$el.root);
|
|
11021
11047
|
parentElement.appendChild($shadowContainer);
|
|
11022
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
|
+
},
|
|
11023
11060
|
/**
|
|
11024
11061
|
* 获取数据
|
|
11025
11062
|
*/
|
|
11026
11063
|
getData() {
|
|
11027
11064
|
return typeof config.data === "function" ? config.data() : config.data;
|
|
11028
11065
|
},
|
|
11066
|
+
/**
|
|
11067
|
+
* 更新数据
|
|
11068
|
+
* @param data 数据
|
|
11069
|
+
*/
|
|
11070
|
+
setData(data) {
|
|
11071
|
+
config.data = data;
|
|
11072
|
+
},
|
|
11029
11073
|
/**
|
|
11030
11074
|
* 获取显示出搜索建议框的html
|
|
11031
11075
|
*/
|
|
@@ -11033,7 +11077,7 @@ const PopsSearchSuggestion = {
|
|
|
11033
11077
|
let $el = popsDOMUtils.createElement("div", {
|
|
11034
11078
|
className: `pops pops-${popsType}-search-suggestion`,
|
|
11035
11079
|
innerHTML: /*html*/ `
|
|
11036
|
-
<style>
|
|
11080
|
+
<style type="text/css">
|
|
11037
11081
|
.pops-${popsType}-animation{
|
|
11038
11082
|
-moz-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11039
11083
|
-webkit-animation: searchSelectFalIn 0.5s 1 linear;
|
|
@@ -11041,7 +11085,7 @@ const PopsSearchSuggestion = {
|
|
|
11041
11085
|
-ms-animation: searchSelectFalIn 0.5s 1 linear;
|
|
11042
11086
|
}
|
|
11043
11087
|
</style>
|
|
11044
|
-
<style>
|
|
11088
|
+
<style type="text/css">
|
|
11045
11089
|
.pops-${popsType}-search-suggestion-arrow{
|
|
11046
11090
|
--suggestion-arrow-box-shadow-left-color: rgba(0, 0, 0, 0.24);
|
|
11047
11091
|
--suggestion-arrow-box-shadow-right-color: rgba(0, 0, 0, 0.12);
|
|
@@ -11107,8 +11151,8 @@ const PopsSearchSuggestion = {
|
|
|
11107
11151
|
content: "";
|
|
11108
11152
|
}
|
|
11109
11153
|
</style>
|
|
11110
|
-
<style data-dynamic="true">
|
|
11111
|
-
${
|
|
11154
|
+
<style type="text/css" data-dynamic="true">
|
|
11155
|
+
${SearchSuggestion.getDynamicCSS()}
|
|
11112
11156
|
</style>
|
|
11113
11157
|
<style>
|
|
11114
11158
|
.el-zoom-in-top-animation{
|
|
@@ -11129,6 +11173,9 @@ const PopsSearchSuggestion = {
|
|
|
11129
11173
|
transform: scaleY(1);
|
|
11130
11174
|
}
|
|
11131
11175
|
</style>
|
|
11176
|
+
<style type="text/css" data-user-css>
|
|
11177
|
+
${config.style || ""}
|
|
11178
|
+
</style>
|
|
11132
11179
|
<ul class="pops-${popsType}-search-suggestion-hint ${PopsCommonCSSClassName.userSelectNone}">${config.toSearhNotResultHTML}</ul>
|
|
11133
11180
|
${config.useArrow ? /*html*/ `<div class="pops-${popsType}-search-suggestion-arrow"></div>` : ""}
|
|
11134
11181
|
`,
|
|
@@ -11147,7 +11194,9 @@ const PopsSearchSuggestion = {
|
|
|
11147
11194
|
}
|
|
11148
11195
|
return $el;
|
|
11149
11196
|
},
|
|
11150
|
-
/**
|
|
11197
|
+
/**
|
|
11198
|
+
* 动态获取CSS
|
|
11199
|
+
*/
|
|
11151
11200
|
getDynamicCSS() {
|
|
11152
11201
|
return /*css*/ `
|
|
11153
11202
|
.pops-${popsType}-search-suggestion{
|
|
@@ -11212,53 +11261,82 @@ const PopsSearchSuggestion = {
|
|
|
11212
11261
|
}
|
|
11213
11262
|
`;
|
|
11214
11263
|
},
|
|
11264
|
+
/**
|
|
11265
|
+
* 获取data-value值
|
|
11266
|
+
* @param data 数据项
|
|
11267
|
+
*/
|
|
11268
|
+
getItemDataValue(data) {
|
|
11269
|
+
return data;
|
|
11270
|
+
},
|
|
11215
11271
|
/**
|
|
11216
11272
|
* 获取显示出搜索建议框的每一项的html
|
|
11217
|
-
* @param
|
|
11218
|
-
* @param
|
|
11273
|
+
* @param dataItem 当前项的值
|
|
11274
|
+
* @param dateItemIndex 当前项的下标
|
|
11219
11275
|
*/
|
|
11220
|
-
createSearchItemLiElement(
|
|
11276
|
+
createSearchItemLiElement(dataItem, dateItemIndex) {
|
|
11277
|
+
const dataValue = SearchSuggestion.getItemDataValue(dataItem);
|
|
11221
11278
|
let $li = popsDOMUtils.createElement("li", {
|
|
11222
11279
|
className: `pops-${popsType}-search-suggestion-hint-item`,
|
|
11223
|
-
"data-index":
|
|
11224
|
-
"data-value":
|
|
11225
|
-
innerHTML: `${config.getItemHTML(data)}${config.deleteIcon.enable ? SearchSuggestion.getDeleteIconHTML() : ""}`,
|
|
11280
|
+
"data-index": dateItemIndex,
|
|
11281
|
+
"data-value": dataValue,
|
|
11226
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
|
+
}
|
|
11227
11299
|
popsDOMUtils.addClassName($li, PopsCommonCSSClassName.flexCenter);
|
|
11228
11300
|
popsDOMUtils.addClassName($li, PopsCommonCSSClassName.flexYCenter);
|
|
11229
11301
|
return $li;
|
|
11230
11302
|
},
|
|
11231
|
-
/**
|
|
11232
|
-
* 获取data-value值
|
|
11233
|
-
* @param data
|
|
11234
|
-
*/
|
|
11235
|
-
getItemDataValue(data) {
|
|
11236
|
-
return data;
|
|
11237
|
-
},
|
|
11238
11303
|
/**
|
|
11239
11304
|
* 设置搜索建议框每一项的点击事件
|
|
11240
|
-
* @param $searchItem
|
|
11305
|
+
* @param $searchItem 当前项的元素
|
|
11241
11306
|
*/
|
|
11242
11307
|
setSearchItemClickEvent($searchItem) {
|
|
11243
|
-
popsDOMUtils.on($searchItem, "click", (event) => {
|
|
11308
|
+
popsDOMUtils.on($searchItem, "click", async (event) => {
|
|
11244
11309
|
popsDOMUtils.preventEvent(event);
|
|
11245
11310
|
let $click = event.target;
|
|
11246
|
-
|
|
11311
|
+
const data = SearchSuggestion.getData();
|
|
11312
|
+
const dataItem = Reflect.get($searchItem, "data-value");
|
|
11247
11313
|
let isDelete = Boolean($click.closest(`.pops-${popsType}-delete-icon`));
|
|
11248
11314
|
if (isDelete) {
|
|
11249
11315
|
// 删除
|
|
11250
|
-
if (typeof
|
|
11251
|
-
|
|
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
|
+
}
|
|
11252
11322
|
}
|
|
11253
|
-
if (!
|
|
11323
|
+
if (!SearchSuggestion.$el.$hintULContainer.children.length) {
|
|
11254
11324
|
/* 全删完了 */
|
|
11255
|
-
|
|
11325
|
+
SearchSuggestion.clear();
|
|
11256
11326
|
}
|
|
11257
11327
|
SearchSuggestion.updateStyleSheet();
|
|
11258
11328
|
}
|
|
11259
11329
|
else {
|
|
11260
11330
|
// 点击选择项
|
|
11261
|
-
|
|
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
|
+
}
|
|
11262
11340
|
}
|
|
11263
11341
|
}, {
|
|
11264
11342
|
capture: true,
|
|
@@ -11297,11 +11375,13 @@ const PopsSearchSuggestion = {
|
|
|
11297
11375
|
/* 禁用输入框自动提示 */
|
|
11298
11376
|
config.inputTarget.setAttribute("autocomplete", "off");
|
|
11299
11377
|
/* 内容改变事件 */
|
|
11300
|
-
popsDOMUtils.
|
|
11301
|
-
|
|
11302
|
-
|
|
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);
|
|
11303
11382
|
SearchSuggestion.updateStyleSheet();
|
|
11304
11383
|
}, option);
|
|
11384
|
+
SearchSuggestion.$evt.offInputChangeEvtHandler.push(listenerHandler.off);
|
|
11305
11385
|
},
|
|
11306
11386
|
/**
|
|
11307
11387
|
* 移除输入框内容改变的监听
|
|
@@ -11309,7 +11389,12 @@ const PopsSearchSuggestion = {
|
|
|
11309
11389
|
removeInputChangeEvent(option = {
|
|
11310
11390
|
capture: true,
|
|
11311
11391
|
}) {
|
|
11312
|
-
|
|
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
|
+
}
|
|
11313
11398
|
},
|
|
11314
11399
|
/**
|
|
11315
11400
|
* 显示搜索建议框的事件
|
|
@@ -11435,23 +11520,24 @@ const PopsSearchSuggestion = {
|
|
|
11435
11520
|
/**
|
|
11436
11521
|
* 获取删除按钮的html
|
|
11437
11522
|
*/
|
|
11438
|
-
|
|
11439
|
-
|
|
11440
|
-
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
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;
|
|
11445
11531
|
},
|
|
11446
11532
|
/**
|
|
11447
11533
|
* 设置当前正在搜索中的提示
|
|
11448
11534
|
*/
|
|
11449
11535
|
setPromptsInSearch() {
|
|
11450
|
-
let
|
|
11536
|
+
let $isSearching = popsDOMUtils.createElement("li", {
|
|
11451
11537
|
className: `pops-${popsType}-search-suggestion-hint-searching-item`,
|
|
11452
11538
|
innerHTML: config.searchingTip,
|
|
11453
11539
|
});
|
|
11454
|
-
SearchSuggestion
|
|
11540
|
+
SearchSuggestion.addItem($isSearching);
|
|
11455
11541
|
},
|
|
11456
11542
|
/**
|
|
11457
11543
|
* 移除正在搜索中的提示
|
|
@@ -11461,17 +11547,13 @@ const PopsSearchSuggestion = {
|
|
|
11461
11547
|
.querySelector(`li.pops-${popsType}-search-suggestion-hint-searching-item`)
|
|
11462
11548
|
?.remove();
|
|
11463
11549
|
},
|
|
11464
|
-
/**
|
|
11465
|
-
* 清空所有的搜索结果
|
|
11466
|
-
*/
|
|
11467
|
-
clearAllSearchItemLi() {
|
|
11468
|
-
PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$hintULContainer, "");
|
|
11469
|
-
},
|
|
11470
11550
|
/**
|
|
11471
11551
|
* 更新搜索建议框的位置(top、left)
|
|
11472
11552
|
* 因为目标元素可能是动态隐藏的
|
|
11553
|
+
* @param target 目标元素
|
|
11554
|
+
* @param checkPositonAgain 是否在更新位置信息后检测更新位置信息,默认true
|
|
11473
11555
|
*/
|
|
11474
|
-
changeHintULElementPosition(target = config.target ?? config.inputTarget) {
|
|
11556
|
+
changeHintULElementPosition(target = config.target ?? config.inputTarget, checkPositonAgain = true) {
|
|
11475
11557
|
let targetRect = null;
|
|
11476
11558
|
if (config.followPosition === "inputCursor") {
|
|
11477
11559
|
targetRect = popsDOMUtils.getTextBoundingRect(config.inputTarget, config.inputTarget.selectionStart || 0, config.inputTarget.selectionEnd || 0, false);
|
|
@@ -11495,6 +11577,7 @@ const PopsSearchSuggestion = {
|
|
|
11495
11577
|
// 需目标高度+搜索建议框高度大于文档高度,则显示在上面
|
|
11496
11578
|
let targetBottom = targetRect.bottom;
|
|
11497
11579
|
let searchSuggestionContainerHeight = popsDOMUtils.height(SearchSuggestion.$el.$hintULContainer);
|
|
11580
|
+
console.log(targetBottom, searchSuggestionContainerHeight, targetBottom + searchSuggestionContainerHeight, documentHeight);
|
|
11498
11581
|
if (targetBottom + searchSuggestionContainerHeight > documentHeight) {
|
|
11499
11582
|
// 在上面
|
|
11500
11583
|
position = "top";
|
|
@@ -11535,10 +11618,19 @@ const PopsSearchSuggestion = {
|
|
|
11535
11618
|
left = left + documentWidth - hintUIWidth;
|
|
11536
11619
|
}
|
|
11537
11620
|
SearchSuggestion.$el.root.style.left = left + "px";
|
|
11621
|
+
// 如果更新前在下面的话且高度超出了屏幕
|
|
11622
|
+
// 这时候会有滚动条,会造成位置偏移
|
|
11623
|
+
// 更新后的位置却在上面,这时候的位置信息不对齐
|
|
11624
|
+
// 需重新更新位置
|
|
11625
|
+
// 此情况一般是config.position === "auto"
|
|
11626
|
+
if (checkPositonAgain) {
|
|
11627
|
+
SearchSuggestion.changeHintULElementPosition(target, !checkPositonAgain);
|
|
11628
|
+
}
|
|
11538
11629
|
},
|
|
11539
11630
|
/**
|
|
11540
11631
|
* 更新搜索建议框的width
|
|
11541
11632
|
* 因为目标元素可能是动态隐藏的
|
|
11633
|
+
* @param target 目标元素
|
|
11542
11634
|
*/
|
|
11543
11635
|
changeHintULElementWidth(target = config.target ?? config.inputTarget) {
|
|
11544
11636
|
let targetRect = target.getBoundingClientRect();
|
|
@@ -11553,11 +11645,15 @@ const PopsSearchSuggestion = {
|
|
|
11553
11645
|
* 动态更新CSS
|
|
11554
11646
|
*/
|
|
11555
11647
|
updateDynamicCSS() {
|
|
11556
|
-
let cssText =
|
|
11557
|
-
PopsSafeUtils.setSafeHTML(
|
|
11648
|
+
let cssText = SearchSuggestion.getDynamicCSS();
|
|
11649
|
+
PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$dynamicCSS, cssText);
|
|
11558
11650
|
},
|
|
11559
11651
|
/**
|
|
11560
11652
|
* 数据项的数量改变时调用
|
|
11653
|
+
*
|
|
11654
|
+
* - 更新css
|
|
11655
|
+
* - 更新建议框的宽度
|
|
11656
|
+
* - 更新建议框的位置
|
|
11561
11657
|
*/
|
|
11562
11658
|
updateStyleSheet() {
|
|
11563
11659
|
// 更新z-index
|
|
@@ -11567,29 +11663,38 @@ const PopsSearchSuggestion = {
|
|
|
11567
11663
|
// 更新位置
|
|
11568
11664
|
SearchSuggestion.changeHintULElementPosition();
|
|
11569
11665
|
},
|
|
11666
|
+
/**
|
|
11667
|
+
* 添加搜索结果元素
|
|
11668
|
+
* @param $item 项元素
|
|
11669
|
+
*/
|
|
11670
|
+
addItem($item) {
|
|
11671
|
+
SearchSuggestion.$el.$hintULContainer.appendChild($item);
|
|
11672
|
+
},
|
|
11570
11673
|
/**
|
|
11571
11674
|
* 更新页面显示的搜索结果
|
|
11572
|
-
* @param
|
|
11675
|
+
* @param updateData
|
|
11573
11676
|
*/
|
|
11574
|
-
update(
|
|
11575
|
-
if (!Array.isArray(
|
|
11677
|
+
update(updateData = []) {
|
|
11678
|
+
if (!Array.isArray(updateData)) {
|
|
11576
11679
|
throw new TypeError("传入的数据不是数组");
|
|
11577
11680
|
}
|
|
11578
|
-
|
|
11681
|
+
const data = updateData;
|
|
11579
11682
|
/* 清空已有的搜索结果 */
|
|
11580
|
-
if (
|
|
11683
|
+
if (data.length) {
|
|
11581
11684
|
SearchSuggestion.$data.isEmpty = false;
|
|
11582
11685
|
if (config.toHideWithNotResult) {
|
|
11583
11686
|
SearchSuggestion.show();
|
|
11584
11687
|
}
|
|
11585
|
-
SearchSuggestion.
|
|
11688
|
+
SearchSuggestion.clear(true);
|
|
11586
11689
|
/* 添加进ul中 */
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
SearchSuggestion.
|
|
11590
|
-
SearchSuggestion.
|
|
11591
|
-
SearchSuggestion
|
|
11690
|
+
let fragment = document.createDocumentFragment();
|
|
11691
|
+
data.forEach((item, index) => {
|
|
11692
|
+
let $item = SearchSuggestion.createSearchItemLiElement(item, index);
|
|
11693
|
+
SearchSuggestion.setSearchItemClickEvent($item);
|
|
11694
|
+
SearchSuggestion.setSearchItemSelectEvent($item);
|
|
11695
|
+
fragment.appendChild($item);
|
|
11592
11696
|
});
|
|
11697
|
+
SearchSuggestion.addItem(fragment);
|
|
11593
11698
|
}
|
|
11594
11699
|
else {
|
|
11595
11700
|
/* 清空 */
|
|
@@ -11598,13 +11703,24 @@ const PopsSearchSuggestion = {
|
|
|
11598
11703
|
},
|
|
11599
11704
|
/**
|
|
11600
11705
|
* 清空当前的搜索结果并显示无结果
|
|
11706
|
+
* @param [onlyClearView=false] 是否仅清空元素,默认false
|
|
11601
11707
|
*/
|
|
11602
|
-
clear() {
|
|
11603
|
-
|
|
11604
|
-
|
|
11605
|
-
|
|
11708
|
+
clear(onlyClearView = false) {
|
|
11709
|
+
PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$hintULContainer, "");
|
|
11710
|
+
if (onlyClearView) {
|
|
11711
|
+
return;
|
|
11712
|
+
}
|
|
11713
|
+
SearchSuggestion.$data.isEmpty = true;
|
|
11714
|
+
let $noResult;
|
|
11715
|
+
if (typeof config.toSearhNotResultHTML === "string") {
|
|
11716
|
+
$noResult = popsDOMUtils.parseTextToDOM(config.toSearhNotResultHTML);
|
|
11717
|
+
}
|
|
11718
|
+
else {
|
|
11719
|
+
$noResult = config.toSearhNotResultHTML();
|
|
11720
|
+
}
|
|
11721
|
+
SearchSuggestion.addItem($noResult);
|
|
11606
11722
|
if (config.toHideWithNotResult) {
|
|
11607
|
-
|
|
11723
|
+
SearchSuggestion.hide();
|
|
11608
11724
|
}
|
|
11609
11725
|
},
|
|
11610
11726
|
/**
|
|
@@ -11615,25 +11731,25 @@ const PopsSearchSuggestion = {
|
|
|
11615
11731
|
if (config.useFoldAnimation) {
|
|
11616
11732
|
if (!useAnimationToHide) {
|
|
11617
11733
|
// 去掉动画
|
|
11618
|
-
popsDOMUtils.removeClassName(
|
|
11734
|
+
popsDOMUtils.removeClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation");
|
|
11619
11735
|
}
|
|
11620
|
-
popsDOMUtils.addClassName(
|
|
11621
|
-
popsDOMUtils.addClassName(
|
|
11622
|
-
popsDOMUtils.removeClassName(
|
|
11736
|
+
popsDOMUtils.addClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation");
|
|
11737
|
+
popsDOMUtils.addClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation-hide");
|
|
11738
|
+
popsDOMUtils.removeClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation-show");
|
|
11623
11739
|
}
|
|
11624
11740
|
else {
|
|
11625
|
-
|
|
11741
|
+
SearchSuggestion.$el.root.style.display = "none";
|
|
11626
11742
|
}
|
|
11627
11743
|
},
|
|
11628
11744
|
/**
|
|
11629
11745
|
* 显示搜索建议框
|
|
11630
11746
|
*/
|
|
11631
11747
|
show() {
|
|
11632
|
-
|
|
11748
|
+
SearchSuggestion.$el.root.style.display = "";
|
|
11633
11749
|
if (config.useFoldAnimation) {
|
|
11634
|
-
popsDOMUtils.addClassName(
|
|
11635
|
-
popsDOMUtils.removeClassName(
|
|
11636
|
-
popsDOMUtils.addClassName(
|
|
11750
|
+
popsDOMUtils.addClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation");
|
|
11751
|
+
popsDOMUtils.removeClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation-hide");
|
|
11752
|
+
popsDOMUtils.addClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation-show");
|
|
11637
11753
|
}
|
|
11638
11754
|
},
|
|
11639
11755
|
};
|
|
@@ -11645,7 +11761,7 @@ class Pops {
|
|
|
11645
11761
|
/** 配置 */
|
|
11646
11762
|
config = {
|
|
11647
11763
|
/** 版本号 */
|
|
11648
|
-
version: "2025.
|
|
11764
|
+
version: "2025.9.4",
|
|
11649
11765
|
cssText: PopsCSS,
|
|
11650
11766
|
/** icon图标的svg代码 */
|
|
11651
11767
|
iconSVG: PopsIcon.$data,
|