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