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