@whitesev/pops 2.3.3 → 2.3.5

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.umd.js CHANGED
@@ -1819,11 +1819,11 @@
1819
1819
  }
1820
1820
  /**
1821
1821
  * 添加className
1822
- * @param element 目标元素
1822
+ * @param $el 目标元素
1823
1823
  * @param className className属性
1824
1824
  */
1825
- addClassName(element, className) {
1826
- if (element == null) {
1825
+ addClassName($el, className) {
1826
+ if ($el == null) {
1827
1827
  return;
1828
1828
  }
1829
1829
  if (typeof className !== "string") {
@@ -1832,15 +1832,16 @@
1832
1832
  if (className.trim() === "") {
1833
1833
  return;
1834
1834
  }
1835
- element.classList.add(className);
1835
+ const classNameList = className.split(" ").filter((item) => item.trim() !== "");
1836
+ $el.classList.add(...classNameList);
1836
1837
  }
1837
1838
  /**
1838
1839
  * 删除className
1839
- * @param element 目标元素
1840
+ * @param $el 目标元素
1840
1841
  * @param className className属性
1841
1842
  */
1842
- removeClassName(element, className) {
1843
- if (element == null) {
1843
+ removeClassName($el, className) {
1844
+ if ($el == null) {
1844
1845
  return;
1845
1846
  }
1846
1847
  if (typeof className !== "string") {
@@ -1849,15 +1850,16 @@
1849
1850
  if (className.trim() === "") {
1850
1851
  return;
1851
1852
  }
1852
- element.classList.remove(className);
1853
+ const classNameList = className.split(" ").filter((item) => item.trim() !== "");
1854
+ $el.classList.remove(...classNameList);
1853
1855
  }
1854
1856
  /**
1855
1857
  * 判断元素是否包含某个className
1856
- * @param element 目标元素
1858
+ * @param $el 目标元素
1857
1859
  * @param className className属性
1858
1860
  */
1859
- containsClassName(element, className) {
1860
- if (element == null) {
1861
+ containsClassName($el, className) {
1862
+ if ($el == null) {
1861
1863
  return false;
1862
1864
  }
1863
1865
  if (typeof className !== "string") {
@@ -1866,7 +1868,7 @@
1866
1868
  if (className.trim() === "") {
1867
1869
  return false;
1868
1870
  }
1869
- return element.classList.contains(className);
1871
+ return $el.classList.contains(className);
1870
1872
  }
1871
1873
  css(element, property, value) {
1872
1874
  /**
@@ -2489,6 +2491,24 @@
2489
2491
  }
2490
2492
  return useChangeColor();
2491
2493
  }
2494
+ /**
2495
+ * 获取移动元素的transform偏移
2496
+ * @param element 元素
2497
+ */
2498
+ getTransform(element) {
2499
+ let transform_left = 0;
2500
+ let transform_top = 0;
2501
+ let elementTransform = PopsCore.globalThis.getComputedStyle(element).transform;
2502
+ if (elementTransform !== "none" && elementTransform != null && elementTransform !== "") {
2503
+ let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
2504
+ transform_left = Math.abs(parseInt(elementTransformSplit[4]));
2505
+ transform_top = Math.abs(parseInt(elementTransformSplit[5]));
2506
+ }
2507
+ return {
2508
+ transformLeft: transform_left,
2509
+ transformTop: transform_top,
2510
+ };
2511
+ }
2492
2512
  }
2493
2513
  const popsDOMUtils = new PopsDOMUtils();
2494
2514
 
@@ -3288,23 +3308,6 @@
3288
3308
  popsDOMUtils.css(options.dragElement, {
3289
3309
  cursor: "move",
3290
3310
  });
3291
- /**
3292
- * 获取移动元素的transform偏移
3293
- */
3294
- function getTransform(element) {
3295
- let transform_left = 0;
3296
- let transform_top = 0;
3297
- let elementTransform = PopsCore.globalThis.getComputedStyle(element).transform;
3298
- if (elementTransform !== "none" && elementTransform != null && elementTransform !== "") {
3299
- let elementTransformSplit = elementTransform.match(/\((.+)\)/)?.[1].split(",");
3300
- transform_left = Math.abs(parseInt(elementTransformSplit[4]));
3301
- transform_top = Math.abs(parseInt(elementTransformSplit[5]));
3302
- }
3303
- return {
3304
- transformLeft: transform_left,
3305
- transformTop: transform_top,
3306
- };
3307
- }
3308
3311
  /**
3309
3312
  * 修改移动的元素的style
3310
3313
  */
@@ -3346,9 +3349,8 @@
3346
3349
  };
3347
3350
  }
3348
3351
  }
3349
- let transformInfo = getTransform(moveElement);
3350
- let transformLeft = transformInfo.transformLeft;
3351
- let transformTop = transformInfo.transformTop;
3352
+ // 获取transform偏移
3353
+ let transformInfo = popsDOMUtils.getTransform(moveElement);
3352
3354
  let resumeMoveElementStyle = null;
3353
3355
  anyTouchElement.on("pan", function (event) {
3354
3356
  if (!isMove) {
@@ -3356,9 +3358,7 @@
3356
3358
  let rect = options.dragElement.getBoundingClientRect();
3357
3359
  clickElementLeftOffset = event.x - rect.left;
3358
3360
  clickElementTopOffset = event.y - rect.top;
3359
- transformInfo = getTransform(moveElement);
3360
- transformLeft = transformInfo.transformLeft;
3361
- transformTop = transformInfo.transformTop;
3361
+ transformInfo = popsDOMUtils.getTransform(moveElement);
3362
3362
  //if (event.nativeEvent.offsetX) {
3363
3363
  // clickElementLeftOffset = parseInt(event.nativeEvent.offsetX);
3364
3364
  //} else {
@@ -3372,9 +3372,9 @@
3372
3372
  resumeMoveElementStyle = changeMoveElementStyle(moveElement);
3373
3373
  }
3374
3374
  /** 当前移动的left偏移 */
3375
- let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformLeft;
3375
+ let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformInfo.transformLeft;
3376
3376
  /** 当前移动的top偏移 */
3377
- let currentMoveTopOffset = event.y - clickElementTopOffset + transformTop;
3377
+ let currentMoveTopOffset = event.y - clickElementTopOffset + transformInfo.transformTop;
3378
3378
  /* 拖拽移动 */
3379
3379
  if (event.phase === "move") {
3380
3380
  if (options.limit) {
@@ -3382,12 +3382,12 @@
3382
3382
  /* left偏移最大值 */
3383
3383
  let maxLeftOffset = getContainerWidthOrHeight(options.container).width -
3384
3384
  popsDOMUtils.width(moveElement) +
3385
- transformLeft;
3385
+ transformInfo.transformLeft;
3386
3386
  let { left: minLeftOffset, top: minTopOffset } = getContainerTopOrLeft(options.container);
3387
3387
  /* top偏移的最大值 */
3388
3388
  let maxTopOffset = getContainerWidthOrHeight(options.container).height -
3389
3389
  popsDOMUtils.height(moveElement) +
3390
- transformTop;
3390
+ transformInfo.transformTop;
3391
3391
  if (currentMoveLeftOffset > maxLeftOffset) {
3392
3392
  /* 不允许超过容器的最大宽度 */
3393
3393
  currentMoveLeftOffset = maxLeftOffset;
@@ -3396,9 +3396,10 @@
3396
3396
  /* 不允许超过容器的最大高度 */
3397
3397
  currentMoveTopOffset = maxTopOffset;
3398
3398
  }
3399
- if (currentMoveLeftOffset - options.extraDistance * 2 < minLeftOffset + transformLeft) {
3399
+ if (currentMoveLeftOffset - options.extraDistance * 2 <
3400
+ minLeftOffset + transformInfo.transformLeft) {
3400
3401
  /* 不允许left偏移小于容器最小值 */
3401
- currentMoveLeftOffset = minLeftOffset + transformLeft;
3402
+ currentMoveLeftOffset = minLeftOffset + transformInfo.transformLeft;
3402
3403
  /* 最左边 +额外距离 */
3403
3404
  currentMoveLeftOffset += options.extraDistance;
3404
3405
  }
@@ -3406,9 +3407,9 @@
3406
3407
  /* 最右边 -额外距离 */
3407
3408
  currentMoveLeftOffset -= options.extraDistance;
3408
3409
  }
3409
- if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformTop) {
3410
+ if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformInfo.transformTop) {
3410
3411
  /* 不允许top偏移小于容器最小值 */
3411
- currentMoveTopOffset = minTopOffset + transformTop;
3412
+ currentMoveTopOffset = minTopOffset + transformInfo.transformTop;
3412
3413
  /* 最上面 +额外距离 */
3413
3414
  currentMoveTopOffset += options.extraDistance;
3414
3415
  }
@@ -10747,28 +10748,42 @@
10747
10748
  popsDOMUtils.addClassName(menuLiElement, `pops-${popsType}-item`);
10748
10749
  }
10749
10750
  /* 鼠标|触摸 移入事件 */
10750
- function liElementHoverEvent() {
10751
+ // 在移动端会先触发touchstart再然后mouseenter
10752
+ let isTriggerTouchEvent = false;
10753
+ /**
10754
+ * 鼠标|触摸 移入事件
10755
+ */
10756
+ function liElementHoverEvent(event) {
10757
+ if (event.type === "touchstart") {
10758
+ isTriggerTouchEvent = true;
10759
+ }
10760
+ if (isTriggerTouchEvent && event.type === "mouseenter") {
10761
+ return;
10762
+ }
10751
10763
  Array.from(menuULElement.children).forEach((liElement) => {
10752
10764
  popsDOMUtils.removeClassName(liElement, `pops-${popsType}-is-visited`);
10753
- if (!liElement.__menuData__) {
10765
+ let li_menuData = Reflect.get(liElement, "__menuData__");
10766
+ if (!li_menuData) {
10754
10767
  return;
10755
10768
  }
10756
10769
  function removeElement(element) {
10757
- element.querySelectorAll("ul li").forEach((ele) => {
10758
- if (ele?.__menuData__?.child) {
10759
- removeElement(ele.__menuData__.child);
10770
+ element.querySelectorAll("ul li").forEach(($ele) => {
10771
+ let menuData = Reflect.get($ele, "__menuData__");
10772
+ if (menuData?.child) {
10773
+ removeElement(menuData.child);
10760
10774
  }
10761
10775
  });
10762
10776
  element.remove();
10763
10777
  }
10764
10778
  /* 遍历根元素的上的__menuData__.child,判断 */
10765
- removeElement(liElement.__menuData__.child);
10779
+ removeElement(li_menuData.child);
10766
10780
  });
10767
10781
  /* 清理根元素上的children不存在于页面中的元素 */
10768
- for (let index = 0; index < rootElement.__menuData__.child.length; index++) {
10769
- let element = rootElement.__menuData__.child[index];
10782
+ let root_menuData = Reflect.get(rootElement, "__menuData__");
10783
+ for (let index = 0; index < root_menuData.child.length; index++) {
10784
+ let element = root_menuData.child[index];
10770
10785
  if (!$shadowRoot.contains(element)) {
10771
- rootElement.__menuData__.child.splice(index, 1);
10786
+ root_menuData.child.splice(index, 1);
10772
10787
  index--;
10773
10788
  }
10774
10789
  }
@@ -10781,14 +10796,13 @@
10781
10796
  clientX: rect.left + popsDOMUtils.outerWidth(menuLiElement),
10782
10797
  clientY: rect.top,
10783
10798
  }, item.item, rootElement, menuLiElement, menuListenerRootNode);
10784
- menuLiElement.__menuData__ = {
10799
+ Reflect.set(menuLiElement, "__menuData__", {
10785
10800
  child: childMenu,
10786
- };
10801
+ });
10787
10802
  }
10788
10803
  /**
10789
10804
  * 点击事件
10790
10805
  * @param clickEvent
10791
- * @returns
10792
10806
  */
10793
10807
  async function liElementClickEvent(clickEvent) {
10794
10808
  if (typeof item.callback === "function") {
@@ -10811,9 +10825,9 @@
10811
10825
  });
10812
10826
  PopsContextMenu.closeAllMenu(rootElement);
10813
10827
  }
10814
- popsDOMUtils.on(menuLiElement, "mouseenter touchstart", void 0, liElementHoverEvent);
10828
+ popsDOMUtils.on(menuLiElement, "mouseenter touchstart", liElementHoverEvent);
10815
10829
  /* 项-点击事件 */
10816
- popsDOMUtils.on(menuLiElement, "click", void 0, liElementClickEvent);
10830
+ popsDOMUtils.on(menuLiElement, "click", liElementClickEvent);
10817
10831
  menuULElement.appendChild(menuLiElement);
10818
10832
  });
10819
10833
  },
@@ -10834,33 +10848,34 @@
10834
10848
  };
10835
10849
 
10836
10850
  const searchSuggestionConfig = () => {
10851
+ const data = [];
10852
+ for (let index = 0; index < 10; index++) {
10853
+ data.push({
10854
+ value: `测试${index}`,
10855
+ text: `测试${index}-html`,
10856
+ });
10857
+ }
10837
10858
  return {
10838
10859
  // @ts-ignore
10839
10860
  target: null,
10840
10861
  // @ts-ignore
10841
10862
  inputTarget: null,
10842
10863
  selfDocument: document,
10843
- data: [
10844
- {
10845
- value: "数据1",
10846
- text: "数据1-html",
10847
- },
10848
- {
10849
- value: "数据2",
10850
- text: "数据2-html",
10851
- },
10852
- ],
10864
+ data: data,
10853
10865
  deleteIcon: {
10854
10866
  enable: true,
10855
- callback(event, liElement, data) {
10856
- console.log("删除当前项", [event, liElement, data]);
10867
+ callback(event, liElement, dataItem) {
10868
+ console.log("删除当前项", [event, liElement, dataItem]);
10869
+ data.splice(data.indexOf(dataItem), 1);
10857
10870
  liElement.remove();
10858
10871
  },
10859
10872
  },
10860
10873
  useShadowRoot: true,
10861
10874
  className: "",
10862
10875
  isAbsolute: true,
10863
- isAnimation: true,
10876
+ isAnimation: false,
10877
+ useFoldAnimation: true,
10878
+ useArrow: false,
10864
10879
  width: "250px",
10865
10880
  maxHeight: "300px",
10866
10881
  followTargetWidth: true,
@@ -10875,9 +10890,9 @@
10875
10890
  getItemHTML(item) {
10876
10891
  return item.text ?? item;
10877
10892
  },
10878
- async getData(value) {
10893
+ async getData(value, data) {
10879
10894
  console.log("当前输入框的值是:", value);
10880
- return [];
10895
+ return data.filter((it) => it.value.includes(value));
10881
10896
  },
10882
10897
  itemClickCallBack(event, liElement, data) {
10883
10898
  console.log("item项的点击回调", [event, liElement, data]);
@@ -10949,74 +10964,168 @@
10949
10964
  /** 是否结果为空 */
10950
10965
  isEmpty: true,
10951
10966
  },
10967
+ /** 初始化元素变量 */
10968
+ initEl() {
10969
+ this.$el.root = SearchSuggestion.createSearchSelectElement();
10970
+ this.$el.$dynamicCSS = this.$el.root.querySelector("style[data-dynamic]");
10971
+ this.$el.$hintULContainer = SearchSuggestion.$el.root.querySelector("ul");
10972
+ },
10952
10973
  /**
10953
10974
  * 初始化
10954
10975
  */
10955
10976
  init(parentElement = document.body || document.documentElement) {
10956
10977
  this.initEl();
10957
- SearchSuggestion.update(typeof config.data === "function" ? config.data() : config.data);
10958
- SearchSuggestion.updateDynamicCSS();
10959
- SearchSuggestion.changeHintULElementWidth();
10960
- SearchSuggestion.changeHintULElementPosition();
10978
+ SearchSuggestion.update(this.getData());
10979
+ SearchSuggestion.updateStyleSheet();
10961
10980
  SearchSuggestion.hide();
10962
- if (config.isAnimation) {
10963
- SearchSuggestion.$el.root.classList.add(`pops-${popsType}-animation`);
10964
- }
10965
10981
  $shadowRoot.appendChild(SearchSuggestion.$el.root);
10966
10982
  parentElement.appendChild($shadowContainer);
10967
10983
  },
10968
- /** 初始化元素变量 */
10969
- initEl() {
10970
- this.$el.root = SearchSuggestion.getSearchSelectElement();
10971
- this.$el.$dynamicCSS = this.$el.root.querySelector("style[data-dynamic]");
10972
- this.$el.$hintULContainer = SearchSuggestion.$el.root.querySelector("ul");
10984
+ /**
10985
+ * 获取数据
10986
+ */
10987
+ getData() {
10988
+ return typeof config.data === "function" ? config.data() : config.data;
10973
10989
  },
10974
10990
  /**
10975
10991
  * 获取显示出搜索建议框的html
10976
10992
  */
10977
- getSearchSelectElement() {
10978
- let element = popsDOMUtils.createElement("div", {
10993
+ createSearchSelectElement() {
10994
+ let $el = popsDOMUtils.createElement("div", {
10979
10995
  className: `pops pops-${popsType}-search-suggestion`,
10980
10996
  innerHTML: /*html*/ `
10997
+ <style>
10998
+ .pops-${popsType}-animation{
10999
+ -moz-animation: searchSelectFalIn 0.5s 1 linear;
11000
+ -webkit-animation: searchSelectFalIn 0.5s 1 linear;
11001
+ -o-animation: searchSelectFalIn 0.5s 1 linear;
11002
+ -ms-animation: searchSelectFalIn 0.5s 1 linear;
11003
+ }
11004
+ </style>
11005
+ <style>
11006
+ .pops-${popsType}-search-suggestion-arrow{
11007
+ --suggestion-arrow-box-shadow-left-color: rgba(0, 0, 0, 0.24);
11008
+ --suggestion-arrow-box-shadow-right-color: rgba(0, 0, 0, 0.12);
11009
+ --suggestion-arrow--after-color: rgb(78, 78, 78);
11010
+ --suggestion-arrow--after-bg-color: rgb(255, 255, 255, var(--pops-bg-opacity));
11011
+ --suggestion-arrow--after-width: 10px;
11012
+ --suggestion-arrow--after-height: 10px;
11013
+ }
11014
+ .pops-${popsType}-search-suggestion-arrow{
11015
+ position: absolute;
11016
+ top: 100%;
11017
+ left: 50%;
11018
+ overflow: hidden;
11019
+ width: 100%;
11020
+ height: 12.5px;
11021
+ transform: translateX(-50%);
11022
+ }
11023
+ .pops-${popsType}-search-suggestion-arrow::after{
11024
+ position: absolute;
11025
+ top: 0;
11026
+ left: 50%;
11027
+ width: var(--suggestion-arrow--after-width);
11028
+ height: var(--suggestion-arrow--after-height);
11029
+ background: var(--suggestion-arrow--after-bg-color);
11030
+ color: var(--suggestion-arrow--after-color);
11031
+ box-shadow:
11032
+ 0 1px 7px var(--suggestion-arrow-box-shadow-left-color),
11033
+ 0 1px 7px var(--suggestion-arrow-box-shadow-right-color);
11034
+ content: "";
11035
+ transform: translateX(-50%) translateY(-50%) rotate(45deg);
11036
+ }
11037
+ .pops-${popsType}-search-suggestion[data-popper-placement^="top"] .pops-${popsType}-search-suggestion-arrow{
11038
+ position: absolute;
11039
+ top: 100%;
11040
+ left: 50%;
11041
+ overflow: hidden;
11042
+ width: 100%;
11043
+ height: 12.5px;
11044
+ transform: translateX(-50%);
11045
+ }
11046
+ .pops-${popsType}-search-suggestion[data-popper-placement^="top"] .pops-${popsType}-search-suggestion-arrow::after{
11047
+ position: absolute;
11048
+ top: 0;
11049
+ left: 50%;
11050
+ width: var(--suggestion-arrow--after-width);
11051
+ height: var(--suggestion-arrow--after-height);
11052
+ background: var(--suggestion-arrow--after-bg-color);
11053
+ box-shadow:
11054
+ 0 1px 7px var(--suggestion-arrow-box-shadow-left-color),
11055
+ 0 1px 7px var(--suggestion-arrow-box-shadow-right-color);
11056
+ content: "";
11057
+ transform: translateX(-50%) translateY(-50%) rotate(45deg);
11058
+ }
11059
+ .pops-${popsType}-search-suggestion[data-popper-placement^="bottom"] .pops-${popsType}-search-suggestion-arrow{
11060
+ top: -12.5px;
11061
+ left: 50%;
11062
+ transform: translateX(-50%);
11063
+ }
11064
+ .pops-${popsType}-search-suggestion[data-popper-placement^="bottom"] .pops-${popsType}-search-suggestion-arrow::after{
11065
+ position: absolute;
11066
+ top: 100%;
11067
+ left: 50%;
11068
+ content: "";
11069
+ }
11070
+ </style>
10981
11071
  <style data-dynamic="true">
10982
11072
  ${this.getDynamicCSS()}
10983
11073
  </style>
10984
- <ul class="pops-${popsType}-search-suggestion-hint">${config.toSearhNotResultHTML}</ul>
11074
+ <style>
11075
+ .el-zoom-in-top-animation{
11076
+ --el-transition-md-fade: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1),
11077
+ opacity 0.3s cubic-bezier(0.23, 1, 0.32, 1);
11078
+ transition: var(--el-transition-md-fade);
11079
+ transform-origin: center top;
11080
+ }
11081
+ .el-zoom-in-top-animation[data-popper-placement^="top"] {
11082
+ transform-origin: center bottom;
11083
+ }
11084
+ .el-zoom-in-top-animation-hide{
11085
+ opacity: 0;
11086
+ transform: scaleY(0);
11087
+ }
11088
+ .el-zoom-in-top-animation-show{
11089
+ opacity: 1;
11090
+ transform: scaleY(1);
11091
+ }
11092
+ </style>
11093
+ <ul class="pops-${popsType}-search-suggestion-hint ${PopsCommonCSSClassName.userSelectNone}">${config.toSearhNotResultHTML}</ul>
11094
+ ${config.useArrow ? /*html*/ `<div class="pops-${popsType}-search-suggestion-arrow"></div>` : ""}
10985
11095
  `,
10986
11096
  }, {
10987
11097
  "data-guid": guid,
10988
11098
  "type-value": popsType,
10989
11099
  });
10990
11100
  if (config.className !== "" && config.className != null) {
10991
- popsDOMUtils.addClassName(element, config.className);
11101
+ popsDOMUtils.addClassName($el, config.className);
11102
+ }
11103
+ if (config.isAnimation) {
11104
+ popsDOMUtils.addClassName($el, `pops-${popsType}-animation`);
11105
+ }
11106
+ if (config.useFoldAnimation) {
11107
+ popsDOMUtils.addClassName($el, "el-zoom-in-top-animation");
10992
11108
  }
10993
- return element;
11109
+ return $el;
10994
11110
  },
10995
11111
  /** 动态获取CSS */
10996
11112
  getDynamicCSS() {
10997
11113
  return /*css*/ `
10998
- .pops-${popsType}-animation{
10999
- -moz-animation: searchSelectFalIn 0.5s 1 linear;
11000
- -webkit-animation: searchSelectFalIn 0.5s 1 linear;
11001
- -o-animation: searchSelectFalIn 0.5s 1 linear;
11002
- -ms-animation: searchSelectFalIn 0.5s 1 linear;
11003
- }
11004
11114
  .pops-${popsType}-search-suggestion{
11005
11115
  --search-suggestion-bg-color: #ffffff;
11006
11116
  --search-suggestion-box-shadow-color: rgb(0 0 0 / 20%);
11007
11117
  --search-suggestion-item-color: #515a6e;
11008
11118
  --search-suggestion-item-none-color: #8e8e8e;
11009
- --search-suggestion-item-hover-bg-color: rgba(0, 0, 0, .1);
11119
+ --search-suggestion-item-is-hover-bg-color: #f5f7fa;
11120
+ --search-suggestion-item-is-select-bg-color: #409eff;
11010
11121
  }
11011
11122
  .pops-${popsType}-search-suggestion{
11012
11123
  border: initial;
11013
11124
  overflow: initial;
11014
- }
11015
- ul.pops-${popsType}-search-suggestion-hint{
11016
11125
  position: ${config.isAbsolute ? "absolute" : "fixed"};
11017
11126
  z-index: ${PopsHandler.handleZIndex(config.zIndex)};
11018
- width: 0;
11019
- left: 0;
11127
+ }
11128
+ ul.pops-${popsType}-search-suggestion-hint{
11020
11129
  max-height: ${config.maxHeight};
11021
11130
  overflow-x: hidden;
11022
11131
  overflow-y: auto;
@@ -11027,11 +11136,11 @@
11027
11136
  box-shadow: 0 1px 6px var(--search-suggestion-box-shadow-color);
11028
11137
  }
11029
11138
  /* 建议框在上面时 */
11030
- ul.pops-${popsType}-search-suggestion-hint[data-top-reverse]{
11139
+ .pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-hint{
11031
11140
  display: flex;
11032
11141
  flex-direction: column-reverse;
11033
11142
  }
11034
- ul.pops-${popsType}-search-suggestion-hint[data-top-reverse] li{
11143
+ .pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-hint li{
11035
11144
  flex-shrink: 0;
11036
11145
  }
11037
11146
  ul.pops-${popsType}-search-suggestion-hint li{
@@ -11053,14 +11162,13 @@
11053
11162
  color: var(--search-suggestion-item-none-color);
11054
11163
  }
11055
11164
  ul.pops-${popsType}-search-suggestion-hint li:not([data-none]):hover{
11056
- background-color: var(--search-suggestion-item-hover-bg-color);
11165
+ background-color: var(--search-suggestion-item-is-hover-bg-color);
11057
11166
  }
11058
-
11059
11167
  @media (prefers-color-scheme: dark){
11060
11168
  .pops-${popsType}-search-suggestion{
11061
11169
  --search-suggestion-bg-color: #1d1e1f;
11062
11170
  --search-suggestion-item-color: #cfd3d4;
11063
- --search-suggestion-item-hover-bg-color: rgba(175, 175, 175, .1);
11171
+ --search-suggestion-item-is-hover-bg-color: rgba(175, 175, 175, .1);
11064
11172
  }
11065
11173
  }
11066
11174
  `;
@@ -11070,7 +11178,7 @@
11070
11178
  * @param data 当前项的值
11071
11179
  * @param index 当前项的下标
11072
11180
  */
11073
- getSearchItemLiElement(data, index) {
11181
+ createSearchItemLiElement(data, index) {
11074
11182
  let $li = popsDOMUtils.createElement("li", {
11075
11183
  className: `pops-${popsType}-search-suggestion-hint-item`,
11076
11184
  "data-index": index,
@@ -11090,25 +11198,28 @@
11090
11198
  },
11091
11199
  /**
11092
11200
  * 设置搜索建议框每一项的点击事件
11093
- * @param liElement
11201
+ * @param $searchItem
11094
11202
  */
11095
- setSearchItemClickEvent(liElement) {
11096
- popsDOMUtils.on(liElement, "click", void 0, (event) => {
11203
+ setSearchItemClickEvent($searchItem) {
11204
+ popsDOMUtils.on($searchItem, "click", (event) => {
11097
11205
  popsDOMUtils.preventEvent(event);
11098
11206
  let $click = event.target;
11099
- if ($click.closest(`.pops-${popsType}-delete-icon`)) {
11100
- /* 点击的是删除按钮 */
11207
+ let dataValue = Reflect.get($searchItem, "data-value");
11208
+ let isDelete = Boolean($click.closest(`.pops-${popsType}-delete-icon`));
11209
+ if (isDelete) {
11210
+ // 删除
11101
11211
  if (typeof config.deleteIcon.callback === "function") {
11102
- config.deleteIcon.callback(event, liElement, liElement["data-value"]);
11212
+ config.deleteIcon.callback(event, $searchItem, dataValue);
11103
11213
  }
11104
11214
  if (!this.$el.$hintULContainer.children.length) {
11105
11215
  /* 全删完了 */
11106
11216
  this.clear();
11107
11217
  }
11218
+ SearchSuggestion.updateStyleSheet();
11108
11219
  }
11109
11220
  else {
11110
- /* 点击项主体 */
11111
- config.itemClickCallBack(event, liElement, liElement["data-value"]);
11221
+ // 点击选择项
11222
+ config.itemClickCallBack(event, $searchItem, dataValue);
11112
11223
  }
11113
11224
  }, {
11114
11225
  capture: true,
@@ -11148,8 +11259,9 @@
11148
11259
  config.inputTarget.setAttribute("autocomplete", "off");
11149
11260
  /* 内容改变事件 */
11150
11261
  popsDOMUtils.on(config.inputTarget, "input", void 0, async (event) => {
11151
- let getListResult = await config.getData(event.target.value);
11262
+ let getListResult = await config.getData(config.inputTarget.value, this.getData());
11152
11263
  SearchSuggestion.update(getListResult);
11264
+ SearchSuggestion.updateStyleSheet();
11153
11265
  }, option);
11154
11266
  },
11155
11267
  /**
@@ -11164,12 +11276,10 @@
11164
11276
  * 显示搜索建议框的事件
11165
11277
  */
11166
11278
  showEvent() {
11167
- SearchSuggestion.updateDynamicCSS();
11168
- SearchSuggestion.changeHintULElementWidth();
11169
- SearchSuggestion.changeHintULElementPosition();
11279
+ SearchSuggestion.updateStyleSheet();
11170
11280
  if (config.toHideWithNotResult) {
11171
11281
  if (SearchSuggestion.$data.isEmpty) {
11172
- SearchSuggestion.hide();
11282
+ SearchSuggestion.hide(true);
11173
11283
  }
11174
11284
  else {
11175
11285
  SearchSuggestion.show();
@@ -11228,7 +11338,7 @@
11228
11338
  /* 点击在目标input内 */
11229
11339
  return;
11230
11340
  }
11231
- SearchSuggestion.hide();
11341
+ SearchSuggestion.hide(true);
11232
11342
  }
11233
11343
  },
11234
11344
  /**
@@ -11353,29 +11463,39 @@
11353
11463
  else {
11354
11464
  // 在下面
11355
11465
  position = "bottom";
11356
- SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top");
11357
11466
  }
11358
11467
  }
11359
11468
  if (position === "top") {
11469
+ // 在上面
11360
11470
  if (config.positionTopToReverse) {
11361
- SearchSuggestion.$el.$hintULContainer.setAttribute("data-top-reverse", "true");
11471
+ // 自动翻转
11472
+ SearchSuggestion.$el.root.setAttribute("data-top-reverse", "true");
11362
11473
  }
11363
- // 在上面
11364
- SearchSuggestion.$el.$hintULContainer.style.top = "";
11365
- SearchSuggestion.$el.$hintULContainer.style.bottom =
11366
- documentHeight - targetRect.top + config.topDistance + "px";
11474
+ if (config.useFoldAnimation) {
11475
+ // 翻转折叠
11476
+ SearchSuggestion.$el.root.setAttribute("data-popper-placement", "top");
11477
+ }
11478
+ let bottom = documentHeight - targetRect.top + config.topDistance;
11479
+ SearchSuggestion.$el.root.style.top = "";
11480
+ SearchSuggestion.$el.root.style.bottom = bottom + "px";
11367
11481
  }
11368
11482
  else if (position === "bottom") {
11369
11483
  // 在下面
11370
- SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top-reverse");
11371
- SearchSuggestion.$el.$hintULContainer.style.bottom = "";
11372
- SearchSuggestion.$el.$hintULContainer.style.top =
11373
- targetRect.height + targetRect.top + config.topDistance + "px";
11484
+ if (config.useFoldAnimation) {
11485
+ SearchSuggestion.$el.root.setAttribute("data-popper-placement", "bottom-center");
11486
+ }
11487
+ let top = targetRect.height + targetRect.top + config.topDistance;
11488
+ SearchSuggestion.$el.root.removeAttribute("data-top-reverse");
11489
+ SearchSuggestion.$el.root.style.bottom = "";
11490
+ SearchSuggestion.$el.root.style.top = top + "px";
11374
11491
  }
11492
+ let left = targetRect.left;
11375
11493
  let hintUIWidth = popsDOMUtils.width(SearchSuggestion.$el.$hintULContainer);
11376
- SearchSuggestion.$el.$hintULContainer.style.left =
11377
- (targetRect.left + hintUIWidth > documentWidth ? documentWidth - hintUIWidth : targetRect.left) +
11378
- "px";
11494
+ if (hintUIWidth > documentWidth) {
11495
+ // 超出宽度
11496
+ left = left + documentWidth - hintUIWidth;
11497
+ }
11498
+ SearchSuggestion.$el.root.style.left = left + "px";
11379
11499
  },
11380
11500
  /**
11381
11501
  * 更新搜索建议框的width
@@ -11397,6 +11517,17 @@
11397
11517
  let cssText = this.getDynamicCSS();
11398
11518
  PopsSafeUtils.setSafeHTML(this.$el.$dynamicCSS, cssText);
11399
11519
  },
11520
+ /**
11521
+ * 数据项的数量改变时调用
11522
+ */
11523
+ updateStyleSheet() {
11524
+ // 更新z-index
11525
+ SearchSuggestion.updateDynamicCSS();
11526
+ // 更新宽度
11527
+ SearchSuggestion.changeHintULElementWidth();
11528
+ // 更新位置
11529
+ SearchSuggestion.changeHintULElementPosition();
11530
+ },
11400
11531
  /**
11401
11532
  * 更新页面显示的搜索结果
11402
11533
  * @param data
@@ -11415,7 +11546,7 @@
11415
11546
  SearchSuggestion.clearAllSearchItemLi();
11416
11547
  /* 添加进ul中 */
11417
11548
  config.data.forEach((item, index) => {
11418
- let itemElement = SearchSuggestion.getSearchItemLiElement(item, index);
11549
+ let itemElement = SearchSuggestion.createSearchItemLiElement(item, index);
11419
11550
  SearchSuggestion.setSearchItemClickEvent(itemElement);
11420
11551
  SearchSuggestion.setSearchItemSelectEvent(itemElement);
11421
11552
  SearchSuggestion.$el.$hintULContainer.appendChild(itemElement);
@@ -11439,15 +11570,32 @@
11439
11570
  },
11440
11571
  /**
11441
11572
  * 隐藏搜索建议框
11573
+ * @param useAnimationToHide 是否使用动画隐藏
11442
11574
  */
11443
- hide() {
11444
- this.$el.root.style.display = "none";
11575
+ hide(useAnimationToHide = false) {
11576
+ if (config.useFoldAnimation) {
11577
+ if (!useAnimationToHide) {
11578
+ // 去掉动画
11579
+ popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation");
11580
+ }
11581
+ popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation");
11582
+ popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation-hide");
11583
+ popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation-show");
11584
+ }
11585
+ else {
11586
+ this.$el.root.style.display = "none";
11587
+ }
11445
11588
  },
11446
11589
  /**
11447
11590
  * 显示搜索建议框
11448
11591
  */
11449
11592
  show() {
11450
11593
  this.$el.root.style.display = "";
11594
+ if (config.useFoldAnimation) {
11595
+ popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation");
11596
+ popsDOMUtils.removeClassName(this.$el.root, "el-zoom-in-top-animation-hide");
11597
+ popsDOMUtils.addClassName(this.$el.root, "el-zoom-in-top-animation-show");
11598
+ }
11451
11599
  },
11452
11600
  };
11453
11601
  return SearchSuggestion;