@whitesev/pops 1.6.6 → 1.7.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.
@@ -2910,24 +2910,41 @@ System.register('pops', [], (function (exports) {
2910
2910
  }
2911
2911
  /**
2912
2912
  * 用于显示元素并获取它的高度宽度等其它属性
2913
- * @param element
2913
+ * @param $ele
2914
2914
  * @param parent 父元素
2915
2915
  */
2916
- showElement(element, parent = PopsCore.document.documentElement) {
2916
+ showElement($ele, ownParent) {
2917
2917
  /** 克隆元素 */
2918
- let cloneNode = element.cloneNode(true);
2919
- cloneNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
2920
- parent.appendChild(cloneNode);
2918
+ let $cloneNode = $ele.cloneNode(true);
2919
+ $cloneNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
2920
+ let $parent = PopsCore.document.documentElement;
2921
+ // 这里需要的是先获取元素的父节点,把元素同样添加到父节点中
2922
+ let $root = $ele.getRootNode();
2923
+ if (ownParent == null) {
2924
+ if ($root == $ele) {
2925
+ // 未添加到任意节点中,那么直接添加到页面中去
2926
+ $parent = PopsCore.document.documentElement;
2927
+ }
2928
+ else {
2929
+ // 添加到父节点中
2930
+ $parent = $root;
2931
+ }
2932
+ }
2933
+ else {
2934
+ // 自定义的父节点
2935
+ $parent = ownParent;
2936
+ }
2937
+ $parent.appendChild($cloneNode);
2921
2938
  return {
2922
2939
  /**
2923
2940
  * 强制显示的克隆的元素
2924
2941
  */
2925
- cloneNode: cloneNode,
2942
+ cloneNode: $cloneNode,
2926
2943
  /**
2927
2944
  * 恢复修改的style
2928
2945
  */
2929
2946
  recovery() {
2930
- cloneNode.remove();
2947
+ $cloneNode.remove();
2931
2948
  },
2932
2949
  };
2933
2950
  }
@@ -10062,8 +10079,8 @@ System.register('pops', [], (function (exports) {
10062
10079
  * @param y
10063
10080
  */
10064
10081
  getOffset(menuElement, x, y) {
10065
- let menuElementWidth = popsDOMUtils.width(menuElement, void 0, $shadowRoot);
10066
- let menuElementHeight = popsDOMUtils.height(menuElement, void 0, $shadowRoot);
10082
+ let menuElementWidth = popsDOMUtils.width(menuElement);
10083
+ let menuElementHeight = popsDOMUtils.height(menuElement);
10067
10084
  /* left最大偏移 */
10068
10085
  let maxLeftOffset = popsDOMUtils.width(globalThis) - menuElementWidth - 1;
10069
10086
  /* top最大偏移 */
@@ -10541,6 +10558,7 @@ System.register('pops', [], (function (exports) {
10541
10558
  setInputChangeEvent(option = {
10542
10559
  capture: true,
10543
10560
  }) {
10561
+ /* 必须是input或者textarea才有input事件 */
10544
10562
  if (!(config.inputTarget instanceof HTMLInputElement ||
10545
10563
  config.inputTarget instanceof HTMLTextAreaElement)) {
10546
10564
  return;
@@ -10745,7 +10763,22 @@ System.register('pops', [], (function (exports) {
10745
10763
  }
10746
10764
  // 文档最大宽度
10747
10765
  let documentWidth = popsDOMUtils.width(document);
10748
- if (config.position === "top") {
10766
+ let position = config.position;
10767
+ if (config.position === "auto") {
10768
+ // 需目标高度+搜索建议框高度大于文档高度,则显示在上面
10769
+ let targetBottom = targetRect.bottom;
10770
+ let searchSuggestionContainerHeight = popsDOMUtils.height(SearchSuggestion.$el.$hintULContainer);
10771
+ if (targetBottom + searchSuggestionContainerHeight > documentHeight) {
10772
+ // 在上面
10773
+ position = "top";
10774
+ }
10775
+ else {
10776
+ // 在下面
10777
+ position = "bottom";
10778
+ SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top");
10779
+ }
10780
+ }
10781
+ if (position === "top") {
10749
10782
  if (config.positionTopToReverse) {
10750
10783
  SearchSuggestion.$el.$hintULContainer.setAttribute("data-top-reverse", "true");
10751
10784
  }
@@ -10754,36 +10787,13 @@ System.register('pops', [], (function (exports) {
10754
10787
  SearchSuggestion.$el.$hintULContainer.style.bottom =
10755
10788
  documentHeight - targetRect.top + config.topDistance + "px";
10756
10789
  }
10757
- else if (config.position === "bottom") {
10790
+ else if (position === "bottom") {
10758
10791
  // 在下面
10759
10792
  SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top-reverse");
10760
10793
  SearchSuggestion.$el.$hintULContainer.style.bottom = "";
10761
10794
  SearchSuggestion.$el.$hintULContainer.style.top =
10762
10795
  targetRect.height + targetRect.top + config.topDistance + "px";
10763
10796
  }
10764
- else if (config.position === "auto") {
10765
- // 自动判断
10766
- if (targetRect.bottom +
10767
- popsDOMUtils.height(SearchSuggestion.$el.$hintULContainer) >
10768
- documentHeight) {
10769
- if (config.positionTopToReverse) {
10770
- SearchSuggestion.$el.$hintULContainer.setAttribute("data-top-reverse", "true");
10771
- }
10772
- // 超出浏览器高度了,自动转换为上面去
10773
- SearchSuggestion.$el.$hintULContainer.style.top = "";
10774
- SearchSuggestion.$el.$hintULContainer.style.bottom =
10775
- documentHeight - targetRect.top + config.topDistance + "px";
10776
- }
10777
- else {
10778
- SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top");
10779
- SearchSuggestion.$el.$hintULContainer.style.bottom = "";
10780
- SearchSuggestion.$el.$hintULContainer.style.top =
10781
- targetRect.height + targetRect.top + config.topDistance + "px";
10782
- }
10783
- }
10784
- else {
10785
- throw new TypeError("未知设置的位置" + config.position);
10786
- }
10787
10797
  let hintUIWidth = popsDOMUtils.width(SearchSuggestion.$el.$hintULContainer);
10788
10798
  SearchSuggestion.$el.$hintULContainer.style.left =
10789
10799
  (targetRect.left + hintUIWidth > documentWidth