@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.
@@ -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
- getItemHTML(item) {
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
- this.initEl();
11020
- SearchSuggestion.update(this.getData());
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
  */
@@ -11036,7 +11080,7 @@ System.register('pops', [], (function (exports) {
11036
11080
  let $el = popsDOMUtils.createElement("div", {
11037
11081
  className: `pops pops-${popsType}-search-suggestion`,
11038
11082
  innerHTML: /*html*/ `
11039
- <style>
11083
+ <style type="text/css">
11040
11084
  .pops-${popsType}-animation{
11041
11085
  -moz-animation: searchSelectFalIn 0.5s 1 linear;
11042
11086
  -webkit-animation: searchSelectFalIn 0.5s 1 linear;
@@ -11044,7 +11088,7 @@ System.register('pops', [], (function (exports) {
11044
11088
  -ms-animation: searchSelectFalIn 0.5s 1 linear;
11045
11089
  }
11046
11090
  </style>
11047
- <style>
11091
+ <style type="text/css">
11048
11092
  .pops-${popsType}-search-suggestion-arrow{
11049
11093
  --suggestion-arrow-box-shadow-left-color: rgba(0, 0, 0, 0.24);
11050
11094
  --suggestion-arrow-box-shadow-right-color: rgba(0, 0, 0, 0.12);
@@ -11110,8 +11154,8 @@ System.register('pops', [], (function (exports) {
11110
11154
  content: "";
11111
11155
  }
11112
11156
  </style>
11113
- <style data-dynamic="true">
11114
- ${this.getDynamicCSS()}
11157
+ <style type="text/css" data-dynamic="true">
11158
+ ${SearchSuggestion.getDynamicCSS()}
11115
11159
  </style>
11116
11160
  <style>
11117
11161
  .el-zoom-in-top-animation{
@@ -11132,6 +11176,9 @@ System.register('pops', [], (function (exports) {
11132
11176
  transform: scaleY(1);
11133
11177
  }
11134
11178
  </style>
11179
+ <style type="text/css" data-user-css>
11180
+ ${config.style || ""}
11181
+ </style>
11135
11182
  <ul class="pops-${popsType}-search-suggestion-hint ${PopsCommonCSSClassName.userSelectNone}">${config.toSearhNotResultHTML}</ul>
11136
11183
  ${config.useArrow ? /*html*/ `<div class="pops-${popsType}-search-suggestion-arrow"></div>` : ""}
11137
11184
  `,
@@ -11150,7 +11197,9 @@ System.register('pops', [], (function (exports) {
11150
11197
  }
11151
11198
  return $el;
11152
11199
  },
11153
- /** 动态获取CSS */
11200
+ /**
11201
+ * 动态获取CSS
11202
+ */
11154
11203
  getDynamicCSS() {
11155
11204
  return /*css*/ `
11156
11205
  .pops-${popsType}-search-suggestion{
@@ -11215,53 +11264,82 @@ System.register('pops', [], (function (exports) {
11215
11264
  }
11216
11265
  `;
11217
11266
  },
11267
+ /**
11268
+ * 获取data-value值
11269
+ * @param data 数据项
11270
+ */
11271
+ getItemDataValue(data) {
11272
+ return data;
11273
+ },
11218
11274
  /**
11219
11275
  * 获取显示出搜索建议框的每一项的html
11220
- * @param data 当前项的值
11221
- * @param index 当前项的下标
11276
+ * @param dataItem 当前项的值
11277
+ * @param dateItemIndex 当前项的下标
11222
11278
  */
11223
- createSearchItemLiElement(data, index) {
11279
+ createSearchItemLiElement(dataItem, dateItemIndex) {
11280
+ const dataValue = SearchSuggestion.getItemDataValue(dataItem);
11224
11281
  let $li = popsDOMUtils.createElement("li", {
11225
11282
  className: `pops-${popsType}-search-suggestion-hint-item`,
11226
- "data-index": index,
11227
- "data-value": SearchSuggestion.getItemDataValue(data),
11228
- innerHTML: `${config.getItemHTML(data)}${config.deleteIcon.enable ? SearchSuggestion.getDeleteIconHTML() : ""}`,
11283
+ "data-index": dateItemIndex,
11284
+ "data-value": dataValue,
11229
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
+ }
11230
11302
  popsDOMUtils.addClassName($li, PopsCommonCSSClassName.flexCenter);
11231
11303
  popsDOMUtils.addClassName($li, PopsCommonCSSClassName.flexYCenter);
11232
11304
  return $li;
11233
11305
  },
11234
- /**
11235
- * 获取data-value值
11236
- * @param data
11237
- */
11238
- getItemDataValue(data) {
11239
- return data;
11240
- },
11241
11306
  /**
11242
11307
  * 设置搜索建议框每一项的点击事件
11243
- * @param $searchItem
11308
+ * @param $searchItem 当前项的元素
11244
11309
  */
11245
11310
  setSearchItemClickEvent($searchItem) {
11246
- popsDOMUtils.on($searchItem, "click", (event) => {
11311
+ popsDOMUtils.on($searchItem, "click", async (event) => {
11247
11312
  popsDOMUtils.preventEvent(event);
11248
11313
  let $click = event.target;
11249
- let dataValue = Reflect.get($searchItem, "data-value");
11314
+ const data = SearchSuggestion.getData();
11315
+ const dataItem = Reflect.get($searchItem, "data-value");
11250
11316
  let isDelete = Boolean($click.closest(`.pops-${popsType}-delete-icon`));
11251
11317
  if (isDelete) {
11252
11318
  // 删除
11253
- if (typeof config.deleteIcon.callback === "function") {
11254
- config.deleteIcon.callback(event, $searchItem, dataValue);
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
+ }
11255
11325
  }
11256
- if (!this.$el.$hintULContainer.children.length) {
11326
+ if (!SearchSuggestion.$el.$hintULContainer.children.length) {
11257
11327
  /* 全删完了 */
11258
- this.clear();
11328
+ SearchSuggestion.clear();
11259
11329
  }
11260
11330
  SearchSuggestion.updateStyleSheet();
11261
11331
  }
11262
11332
  else {
11263
11333
  // 点击选择项
11264
- config.itemClickCallBack(event, $searchItem, dataValue);
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
+ }
11265
11343
  }
11266
11344
  }, {
11267
11345
  capture: true,
@@ -11300,11 +11378,13 @@ System.register('pops', [], (function (exports) {
11300
11378
  /* 禁用输入框自动提示 */
11301
11379
  config.inputTarget.setAttribute("autocomplete", "off");
11302
11380
  /* 内容改变事件 */
11303
- popsDOMUtils.on(config.inputTarget, "input", void 0, async (event) => {
11304
- let getListResult = await config.getData(config.inputTarget.value, this.getData());
11305
- SearchSuggestion.update(getListResult);
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);
11306
11385
  SearchSuggestion.updateStyleSheet();
11307
11386
  }, option);
11387
+ SearchSuggestion.$evt.offInputChangeEvtHandler.push(listenerHandler.off);
11308
11388
  },
11309
11389
  /**
11310
11390
  * 移除输入框内容改变的监听
@@ -11312,7 +11392,12 @@ System.register('pops', [], (function (exports) {
11312
11392
  removeInputChangeEvent(option = {
11313
11393
  capture: true,
11314
11394
  }) {
11315
- popsDOMUtils.off(config.inputTarget, "input", void 0, void 0, option);
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
+ }
11316
11401
  },
11317
11402
  /**
11318
11403
  * 显示搜索建议框的事件
@@ -11438,23 +11523,24 @@ System.register('pops', [], (function (exports) {
11438
11523
  /**
11439
11524
  * 获取删除按钮的html
11440
11525
  */
11441
- getDeleteIconHTML(size = 16, fill = "#bababa") {
11442
- return /*html*/ `
11443
- <svg class="pops-${popsType}-delete-icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" fill="${fill}">
11444
- <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>
11445
- <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>
11446
- </svg>
11447
- `;
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;
11448
11534
  },
11449
11535
  /**
11450
11536
  * 设置当前正在搜索中的提示
11451
11537
  */
11452
11538
  setPromptsInSearch() {
11453
- let isSearchingElement = popsDOMUtils.createElement("li", {
11539
+ let $isSearching = popsDOMUtils.createElement("li", {
11454
11540
  className: `pops-${popsType}-search-suggestion-hint-searching-item`,
11455
11541
  innerHTML: config.searchingTip,
11456
11542
  });
11457
- SearchSuggestion.$el.$hintULContainer.appendChild(isSearchingElement);
11543
+ SearchSuggestion.addItem($isSearching);
11458
11544
  },
11459
11545
  /**
11460
11546
  * 移除正在搜索中的提示
@@ -11464,17 +11550,13 @@ System.register('pops', [], (function (exports) {
11464
11550
  .querySelector(`li.pops-${popsType}-search-suggestion-hint-searching-item`)
11465
11551
  ?.remove();
11466
11552
  },
11467
- /**
11468
- * 清空所有的搜索结果
11469
- */
11470
- clearAllSearchItemLi() {
11471
- PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$hintULContainer, "");
11472
- },
11473
11553
  /**
11474
11554
  * 更新搜索建议框的位置(top、left)
11475
11555
  * 因为目标元素可能是动态隐藏的
11556
+ * @param target 目标元素
11557
+ * @param checkPositonAgain 是否在更新位置信息后检测更新位置信息,默认true
11476
11558
  */
11477
- changeHintULElementPosition(target = config.target ?? config.inputTarget) {
11559
+ changeHintULElementPosition(target = config.target ?? config.inputTarget, checkPositonAgain = true) {
11478
11560
  let targetRect = null;
11479
11561
  if (config.followPosition === "inputCursor") {
11480
11562
  targetRect = popsDOMUtils.getTextBoundingRect(config.inputTarget, config.inputTarget.selectionStart || 0, config.inputTarget.selectionEnd || 0, false);
@@ -11498,6 +11580,7 @@ System.register('pops', [], (function (exports) {
11498
11580
  // 需目标高度+搜索建议框高度大于文档高度,则显示在上面
11499
11581
  let targetBottom = targetRect.bottom;
11500
11582
  let searchSuggestionContainerHeight = popsDOMUtils.height(SearchSuggestion.$el.$hintULContainer);
11583
+ console.log(targetBottom, searchSuggestionContainerHeight, targetBottom + searchSuggestionContainerHeight, documentHeight);
11501
11584
  if (targetBottom + searchSuggestionContainerHeight > documentHeight) {
11502
11585
  // 在上面
11503
11586
  position = "top";
@@ -11538,10 +11621,19 @@ System.register('pops', [], (function (exports) {
11538
11621
  left = left + documentWidth - hintUIWidth;
11539
11622
  }
11540
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
+ }
11541
11632
  },
11542
11633
  /**
11543
11634
  * 更新搜索建议框的width
11544
11635
  * 因为目标元素可能是动态隐藏的
11636
+ * @param target 目标元素
11545
11637
  */
11546
11638
  changeHintULElementWidth(target = config.target ?? config.inputTarget) {
11547
11639
  let targetRect = target.getBoundingClientRect();
@@ -11556,11 +11648,15 @@ System.register('pops', [], (function (exports) {
11556
11648
  * 动态更新CSS
11557
11649
  */
11558
11650
  updateDynamicCSS() {
11559
- let cssText = this.getDynamicCSS();
11560
- PopsSafeUtils.setSafeHTML(this.$el.$dynamicCSS, cssText);
11651
+ let cssText = SearchSuggestion.getDynamicCSS();
11652
+ PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$dynamicCSS, cssText);
11561
11653
  },
11562
11654
  /**
11563
11655
  * 数据项的数量改变时调用
11656
+ *
11657
+ * - 更新css
11658
+ * - 更新建议框的宽度
11659
+ * - 更新建议框的位置
11564
11660
  */
11565
11661
  updateStyleSheet() {
11566
11662
  // 更新z-index
@@ -11570,29 +11666,38 @@ System.register('pops', [], (function (exports) {
11570
11666
  // 更新位置
11571
11667
  SearchSuggestion.changeHintULElementPosition();
11572
11668
  },
11669
+ /**
11670
+ * 添加搜索结果元素
11671
+ * @param $item 项元素
11672
+ */
11673
+ addItem($item) {
11674
+ SearchSuggestion.$el.$hintULContainer.appendChild($item);
11675
+ },
11573
11676
  /**
11574
11677
  * 更新页面显示的搜索结果
11575
- * @param data
11678
+ * @param updateData
11576
11679
  */
11577
- update(data = []) {
11578
- if (!Array.isArray(data)) {
11680
+ update(updateData = []) {
11681
+ if (!Array.isArray(updateData)) {
11579
11682
  throw new TypeError("传入的数据不是数组");
11580
11683
  }
11581
- config.data = data;
11684
+ const data = updateData;
11582
11685
  /* 清空已有的搜索结果 */
11583
- if (config.data.length) {
11686
+ if (data.length) {
11584
11687
  SearchSuggestion.$data.isEmpty = false;
11585
11688
  if (config.toHideWithNotResult) {
11586
11689
  SearchSuggestion.show();
11587
11690
  }
11588
- SearchSuggestion.clearAllSearchItemLi();
11691
+ SearchSuggestion.clear(true);
11589
11692
  /* 添加进ul中 */
11590
- config.data.forEach((item, index) => {
11591
- let itemElement = SearchSuggestion.createSearchItemLiElement(item, index);
11592
- SearchSuggestion.setSearchItemClickEvent(itemElement);
11593
- SearchSuggestion.setSearchItemSelectEvent(itemElement);
11594
- SearchSuggestion.$el.$hintULContainer.appendChild(itemElement);
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);
11595
11699
  });
11700
+ SearchSuggestion.addItem(fragment);
11596
11701
  }
11597
11702
  else {
11598
11703
  /* 清空 */
@@ -11601,13 +11706,24 @@ System.register('pops', [], (function (exports) {
11601
11706
  },
11602
11707
  /**
11603
11708
  * 清空当前的搜索结果并显示无结果
11709
+ * @param [onlyClearView=false] 是否仅清空元素,默认false
11604
11710
  */
11605
- clear() {
11606
- this.$data.isEmpty = true;
11607
- this.clearAllSearchItemLi();
11608
- this.$el.$hintULContainer.appendChild(popsDOMUtils.parseTextToDOM(config.toSearhNotResultHTML));
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);
11609
11725
  if (config.toHideWithNotResult) {
11610
- this.hide();
11726
+ SearchSuggestion.hide();
11611
11727
  }
11612
11728
  },
11613
11729
  /**
@@ -11618,25 +11734,25 @@ System.register('pops', [], (function (exports) {
11618
11734
  if (config.useFoldAnimation) {
11619
11735
  if (!useAnimationToHide) {
11620
11736
  // 去掉动画
11621
- popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation");
11737
+ popsDOMUtils.removeClassName(SearchSuggestion.$el.root, "el-zoom-in-top-animation");
11622
11738
  }
11623
- popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation");
11624
- popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation-hide");
11625
- popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation-show");
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");
11626
11742
  }
11627
11743
  else {
11628
- this.$el.root.style.display = "none";
11744
+ SearchSuggestion.$el.root.style.display = "none";
11629
11745
  }
11630
11746
  },
11631
11747
  /**
11632
11748
  * 显示搜索建议框
11633
11749
  */
11634
11750
  show() {
11635
- this.$el.root.style.display = "";
11751
+ SearchSuggestion.$el.root.style.display = "";
11636
11752
  if (config.useFoldAnimation) {
11637
- popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation");
11638
- popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation-hide");
11639
- popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation-show");
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");
11640
11756
  }
11641
11757
  },
11642
11758
  };
@@ -11648,7 +11764,7 @@ System.register('pops', [], (function (exports) {
11648
11764
  /** 配置 */
11649
11765
  config = {
11650
11766
  /** 版本号 */
11651
- version: "2025.8.30",
11767
+ version: "2025.9.4",
11652
11768
  cssText: PopsCSS,
11653
11769
  /** icon图标的svg代码 */
11654
11770
  iconSVG: PopsIcon.$data,