@whitesev/pops 2.6.0 → 3.0.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.
Files changed (184) hide show
  1. package/dist/index.amd.js +1233 -1092
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.amd.min.js +1 -1
  4. package/dist/index.amd.min.js.map +1 -1
  5. package/dist/index.cjs.js +1233 -1092
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/index.cjs.min.js +1 -1
  8. package/dist/index.cjs.min.js.map +1 -1
  9. package/dist/index.esm.js +1233 -1092
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.esm.min.js +1 -1
  12. package/dist/index.esm.min.js.map +1 -1
  13. package/dist/index.iife.js +1233 -1092
  14. package/dist/index.iife.js.map +1 -1
  15. package/dist/index.iife.min.js +1 -1
  16. package/dist/index.iife.min.js.map +1 -1
  17. package/dist/index.system.js +1233 -1092
  18. package/dist/index.system.js.map +1 -1
  19. package/dist/index.system.min.js +1 -1
  20. package/dist/index.system.min.js.map +1 -1
  21. package/dist/index.umd.js +1233 -1092
  22. package/dist/index.umd.js.map +1 -1
  23. package/dist/index.umd.min.js +1 -1
  24. package/dist/index.umd.min.js.map +1 -1
  25. package/dist/types/eslint.config.d.mts +2 -0
  26. package/dist/types/src/Pops.d.ts +98 -103
  27. package/dist/types/src/PopsInst.d.ts +2 -2
  28. package/dist/types/src/components/alert/defaultConfig.d.ts +2 -0
  29. package/dist/types/src/components/alert/index.d.ts +2 -2
  30. package/dist/types/src/components/alert/types/index.d.ts +4 -4
  31. package/dist/types/src/components/confirm/defaultConfig.d.ts +2 -0
  32. package/dist/types/src/components/confirm/index.d.ts +2 -2
  33. package/dist/types/src/components/confirm/types/index.d.ts +2 -2
  34. package/dist/types/src/components/drawer/defaultConfig.d.ts +2 -0
  35. package/dist/types/src/components/drawer/index.d.ts +2 -2
  36. package/dist/types/src/components/drawer/types/index.d.ts +2 -2
  37. package/dist/types/src/components/folder/defaultConfig.d.ts +2 -0
  38. package/dist/types/src/components/folder/index.d.ts +2 -2
  39. package/dist/types/src/components/folder/types/index.d.ts +31 -7
  40. package/dist/types/src/components/iframe/defaultConfig.d.ts +2 -0
  41. package/dist/types/src/components/iframe/index.d.ts +2 -5
  42. package/dist/types/src/components/iframe/types/index.d.ts +13 -42
  43. package/dist/types/src/components/loading/defaultConfig.d.ts +2 -0
  44. package/dist/types/src/components/loading/index.d.ts +2 -2
  45. package/dist/types/src/components/loading/types/index.d.ts +4 -4
  46. package/dist/types/src/components/panel/defaultConfig.d.ts +2 -0
  47. package/dist/types/src/components/panel/handlerComponents.d.ts +47 -43
  48. package/dist/types/src/components/panel/index.d.ts +3 -3
  49. package/dist/types/src/components/panel/types/components-button.d.ts +7 -6
  50. package/dist/types/src/components/panel/types/components-common.d.ts +7 -7
  51. package/dist/types/src/components/panel/types/components-container.d.ts +24 -0
  52. package/dist/types/src/components/panel/types/components-deepMenu.d.ts +13 -13
  53. package/dist/types/src/components/panel/types/components-input.d.ts +6 -6
  54. package/dist/types/src/components/panel/types/components-own.d.ts +2 -2
  55. package/dist/types/src/components/panel/types/components-select.d.ts +9 -9
  56. package/dist/types/src/components/panel/types/components-selectMultiple.d.ts +8 -8
  57. package/dist/types/src/components/panel/types/components-slider.d.ts +7 -7
  58. package/dist/types/src/components/panel/types/components-switch.d.ts +6 -6
  59. package/dist/types/src/components/panel/types/components-textarea.d.ts +6 -6
  60. package/dist/types/src/components/panel/types/index.d.ts +36 -28
  61. package/dist/types/src/components/prompt/defaultConfig.d.ts +2 -0
  62. package/dist/types/src/components/prompt/index.d.ts +2 -2
  63. package/dist/types/src/components/prompt/types/index.d.ts +4 -3
  64. package/dist/types/src/components/rightClickMenu/defaultConfig.d.ts +2 -0
  65. package/dist/types/src/components/rightClickMenu/index.d.ts +29 -27
  66. package/dist/types/src/components/rightClickMenu/types/index.d.ts +32 -11
  67. package/dist/types/src/components/searchSuggestion/defaultConfig.d.ts +2 -0
  68. package/dist/types/src/components/searchSuggestion/index.d.ts +21 -6
  69. package/dist/types/src/components/searchSuggestion/types/index.d.ts +15 -13
  70. package/dist/types/src/components/tooltip/defaultConfig.d.ts +2 -0
  71. package/dist/types/src/components/tooltip/index.d.ts +6 -21
  72. package/dist/types/src/components/tooltip/types/index.d.ts +8 -6
  73. package/dist/types/src/config/GlobalConfig.d.ts +3 -3
  74. package/dist/types/src/handler/PopsElementHandler.d.ts +6 -6
  75. package/dist/types/src/handler/PopsHandler.d.ts +18 -18
  76. package/dist/types/src/types/button.d.ts +4 -97
  77. package/dist/types/src/types/components.d.ts +8 -8
  78. package/dist/types/src/types/event.d.ts +0 -30
  79. package/dist/types/src/types/global.d.ts +2 -0
  80. package/dist/types/src/types/inst.d.ts +5 -5
  81. package/dist/types/src/types/main.d.ts +35 -80
  82. package/dist/types/src/types/mask.d.ts +18 -15
  83. package/dist/types/src/utils/PopsInstanceUtils.d.ts +15 -15
  84. package/dist/types/src/utils/PopsUtils.d.ts +4 -0
  85. package/package.json +10 -10
  86. package/src/Pops.ts +44 -44
  87. package/src/PopsAnimation.ts +1 -1
  88. package/src/PopsInst.ts +2 -2
  89. package/src/components/alert/{config.ts → defaultConfig.ts} +7 -7
  90. package/src/components/alert/index.ts +16 -18
  91. package/src/components/alert/types/index.ts +4 -4
  92. package/src/components/confirm/{config.ts → defaultConfig.ts} +11 -11
  93. package/src/components/confirm/index.ts +11 -13
  94. package/src/components/confirm/types/index.ts +3 -3
  95. package/src/components/drawer/{config.ts → defaultConfig.ts} +10 -10
  96. package/src/components/drawer/index.ts +18 -17
  97. package/src/components/drawer/types/index.ts +3 -3
  98. package/src/components/folder/{config.ts → defaultConfig.ts} +22 -18
  99. package/src/components/folder/index.ts +61 -60
  100. package/src/components/folder/types/index.ts +31 -18
  101. package/src/components/iframe/{config.ts → defaultConfig.ts} +2 -2
  102. package/src/components/iframe/index.ts +24 -29
  103. package/src/components/iframe/types/index.ts +13 -56
  104. package/src/components/loading/{config.ts → defaultConfig.ts} +3 -3
  105. package/src/components/loading/index.ts +13 -11
  106. package/src/components/loading/types/index.ts +5 -5
  107. package/src/components/panel/{config.ts → defaultConfig.ts} +115 -37
  108. package/src/components/panel/handlerComponents.ts +446 -428
  109. package/src/components/panel/index.css +11 -3
  110. package/src/components/panel/index.ts +15 -28
  111. package/src/components/panel/types/components-button.ts +7 -6
  112. package/src/components/panel/types/components-common.ts +7 -7
  113. package/src/components/panel/types/components-container.ts +25 -0
  114. package/src/components/panel/types/components-deepMenu.ts +13 -13
  115. package/src/components/panel/types/components-input.ts +6 -6
  116. package/src/components/panel/types/components-own.ts +2 -2
  117. package/src/components/panel/types/components-select.ts +11 -11
  118. package/src/components/panel/types/components-selectMultiple.ts +8 -9
  119. package/src/components/panel/types/components-slider.ts +7 -7
  120. package/src/components/panel/types/components-switch.ts +6 -6
  121. package/src/components/panel/types/components-textarea.ts +6 -6
  122. package/src/components/panel/types/index.ts +45 -38
  123. package/src/components/prompt/{config.ts → defaultConfig.ts} +10 -10
  124. package/src/components/prompt/index.ts +13 -15
  125. package/src/components/prompt/types/index.ts +4 -3
  126. package/src/components/rightClickMenu/{config.ts → defaultConfig.ts} +20 -19
  127. package/src/components/rightClickMenu/index.ts +125 -108
  128. package/src/components/rightClickMenu/types/index.ts +36 -14
  129. package/src/components/searchSuggestion/{config.ts → defaultConfig.ts} +18 -11
  130. package/src/components/searchSuggestion/index.ts +116 -96
  131. package/src/components/searchSuggestion/types/index.ts +17 -15
  132. package/src/components/tooltip/{config.ts → defaultConfig.ts} +5 -6
  133. package/src/components/tooltip/index.ts +21 -21
  134. package/src/components/tooltip/types/index.ts +9 -7
  135. package/src/config/GlobalConfig.ts +2 -2
  136. package/src/css/common.css +6 -0
  137. package/src/handler/PopsElementHandler.ts +29 -30
  138. package/src/handler/PopsHandler.ts +43 -43
  139. package/src/svg/cpu.svg +7 -7
  140. package/src/svg/delete.svg +4 -4
  141. package/src/svg/documentCopy.svg +4 -4
  142. package/src/svg/edit.svg +7 -7
  143. package/src/svg/eleme.svg +4 -4
  144. package/src/svg/elemePlus.svg +4 -4
  145. package/src/svg/headset.svg +4 -4
  146. package/src/svg/hide.svg +7 -7
  147. package/src/svg/keyboard.svg +7 -7
  148. package/src/svg/loading.svg +4 -4
  149. package/src/svg/max.svg +4 -4
  150. package/src/svg/min.svg +2 -4
  151. package/src/svg/mise.svg +4 -4
  152. package/src/svg/monitor.svg +4 -4
  153. package/src/svg/next.svg +4 -4
  154. package/src/svg/picture.svg +7 -7
  155. package/src/svg/prev.svg +4 -4
  156. package/src/svg/search.svg +4 -4
  157. package/src/svg/share.svg +4 -4
  158. package/src/svg/upload.svg +4 -4
  159. package/src/svg/videoPause.svg +4 -4
  160. package/src/svg/videoPlay.svg +4 -4
  161. package/src/svg/view.svg +4 -4
  162. package/src/types/button.d.ts +4 -97
  163. package/src/types/components.d.ts +8 -8
  164. package/src/types/event.d.ts +0 -30
  165. package/src/types/global.d.ts +2 -0
  166. package/src/types/inst.d.ts +5 -5
  167. package/src/types/main.d.ts +35 -80
  168. package/src/types/mask.d.ts +18 -15
  169. package/src/utils/PopsDOMUtils.ts +34 -34
  170. package/src/utils/PopsInstanceUtils.ts +129 -139
  171. package/src/utils/PopsUtils.ts +60 -45
  172. package/dist/types/src/components/alert/config.d.ts +0 -2
  173. package/dist/types/src/components/confirm/config.d.ts +0 -2
  174. package/dist/types/src/components/drawer/config.d.ts +0 -2
  175. package/dist/types/src/components/folder/config.d.ts +0 -2
  176. package/dist/types/src/components/iframe/config.d.ts +0 -2
  177. package/dist/types/src/components/loading/config.d.ts +0 -2
  178. package/dist/types/src/components/panel/config.d.ts +0 -2
  179. package/dist/types/src/components/panel/types/components-forms.d.ts +0 -23
  180. package/dist/types/src/components/prompt/config.d.ts +0 -2
  181. package/dist/types/src/components/rightClickMenu/config.d.ts +0 -2
  182. package/dist/types/src/components/searchSuggestion/config.d.ts +0 -2
  183. package/dist/types/src/components/tooltip/config.d.ts +0 -2
  184. package/src/components/panel/types/components-forms.ts +0 -24
@@ -1,32 +1,26 @@
1
1
  import { PopsHandler } from "../../handler/PopsHandler";
2
2
  import { popsDOMUtils } from "../../utils/PopsDOMUtils";
3
3
  import { popsUtils } from "../../utils/PopsUtils";
4
- import { searchSuggestionConfig as PopsSearchSuggestionConfig } from "./config";
4
+ import { PopsSearchSuggestionDefaultConfig } from "./defaultConfig";
5
5
  import { GlobalConfig } from "../../config/GlobalConfig";
6
6
  import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
7
- import type { PopsSearchSuggestionData, PopsSearchSuggestionDetails } from "./types/index";
7
+ import type { PopsSearchSuggestionData, PopsSearchSuggestionConfig } from "./types/index";
8
8
  import { PopsCSS } from "../../PopsCSS";
9
9
  import type { PopsType } from "../../types/main";
10
10
  import { PopsCommonCSSClassName } from "../../config/CommonCSSClassName";
11
11
 
12
12
  export const PopsSearchSuggestion = {
13
- init<T>(details: PopsSearchSuggestionDetails<T>) {
13
+ init<T>(__config__: PopsSearchSuggestionConfig<T>) {
14
14
  const guid = popsUtils.getRandomGUID();
15
15
  // 设置当前类型
16
16
  const popsType: PopsType = "searchSuggestion";
17
17
 
18
- let config = PopsSearchSuggestionConfig();
18
+ let config = PopsSearchSuggestionDefaultConfig();
19
19
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
20
- config = popsUtils.assign(config, details);
21
- if (config.target == null) {
22
- throw new Error("config.target 不能为空");
23
- }
24
- /* 做下兼容处理 */
25
- if (config.inputTarget == null) {
26
- config.inputTarget = config.target as HTMLInputElement;
27
- }
28
- if (details.data) {
29
- (<PopsSearchSuggestionDetails<T>["data"]>config.data) = details.data;
20
+ config = popsUtils.assign(config, __config__);
21
+ // 如果$inputTarget为空,则根据$target
22
+ if (config.$inputTarget == null) {
23
+ config.$inputTarget = config.$target as HTMLInputElement;
30
24
  }
31
25
 
32
26
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
@@ -57,12 +51,20 @@ export const PopsSearchSuggestion = {
57
51
  /**
58
52
  * 当前的环境,可以是document,可以是shadowroot,默认是document
59
53
  */
60
- selfDocument: config.selfDocument,
54
+ selfDocument: config.$selfDocument,
61
55
  $el: {
62
56
  /** 根元素 */
63
57
  root: null as any as HTMLElement,
58
+ /**
59
+ * 包裹ul的容器元素
60
+ */
61
+ $dropdownWrapper: null as any as HTMLElement,
64
62
  /** ul元素 */
65
- $hintULContainer: null as any as HTMLUListElement,
63
+ $dropdownContainer: null as any as HTMLUListElement,
64
+ /**
65
+ * 箭头元素
66
+ */
67
+ $arrow: null as any as HTMLDivElement,
66
68
  /** 动态更新CSS */
67
69
  $dynamicCSS: null as any as HTMLStyleElement,
68
70
  },
@@ -72,29 +74,44 @@ export const PopsSearchSuggestion = {
72
74
  $data: {
73
75
  /** 是否结果为空 */
74
76
  isEmpty: true,
77
+ /**
78
+ * 存储在元素上的操作的键名
79
+ */
80
+ storeNodeHandlerKey: "data-SearchSuggestion",
75
81
  },
76
82
  /**
77
83
  * 初始化
78
- * @param parentElement 父元素
84
+ * @param $parent 父元素
85
+ * @example
86
+ * .init();
87
+ * .setAllEvent();
79
88
  */
80
- init(parentElement = document.body || document.documentElement) {
89
+ init($parent = document.body || document.documentElement) {
81
90
  SearchSuggestion.initEl();
82
91
  SearchSuggestion.update(SearchSuggestion.getData());
83
92
  SearchSuggestion.updateStyleSheet();
84
93
 
85
94
  SearchSuggestion.hide();
86
95
  $shadowRoot.appendChild(SearchSuggestion.$el.root);
87
- parentElement.appendChild($shadowContainer);
96
+ $parent.appendChild($shadowContainer);
88
97
  },
89
98
  /**
90
99
  * 初始化元素变量
91
100
  */
92
101
  initEl() {
93
102
  SearchSuggestion.$el.root = SearchSuggestion.createSearchSelectElement();
94
- Reflect.set(SearchSuggestion.$el.root, "data-SearchSuggestion", SearchSuggestion);
103
+ Reflect.set(SearchSuggestion.$el.root, this.$data.storeNodeHandlerKey, SearchSuggestion);
95
104
  SearchSuggestion.$el.$dynamicCSS =
96
105
  SearchSuggestion.$el.root.querySelector<HTMLStyleElement>("style[data-dynamic]")!;
97
- SearchSuggestion.$el.$hintULContainer = SearchSuggestion.$el.root.querySelector<HTMLUListElement>("ul")!;
106
+ SearchSuggestion.$el.$dropdownWrapper = SearchSuggestion.$el.root.querySelector<HTMLElement>(
107
+ `.pops-${popsType}-search-suggestion-dropdown-wrapper`
108
+ )!;
109
+ SearchSuggestion.$el.$dropdownContainer = SearchSuggestion.$el.root.querySelector<HTMLUListElement>(
110
+ `ul.pops-${popsType}-search-suggestion-dropdown-container`
111
+ )!;
112
+ SearchSuggestion.$el.$arrow = SearchSuggestion.$el.root.querySelector<HTMLDivElement>(
113
+ `.pops-${popsType}-search-suggestion-arrow`
114
+ )!;
98
115
  },
99
116
  /**
100
117
  * 获取数据
@@ -107,7 +124,7 @@ export const PopsSearchSuggestion = {
107
124
  * @param data 数据
108
125
  */
109
126
  setData(data: PopsSearchSuggestionData<T>[]) {
110
- (<PopsSearchSuggestionDetails<T>["data"]>config.data) = data;
127
+ (<PopsSearchSuggestionConfig<T>["data"]>config.data) = data;
111
128
  },
112
129
  /**
113
130
  * 获取显示出搜索建议框的html
@@ -217,9 +234,12 @@ export const PopsSearchSuggestion = {
217
234
  <style type="text/css" data-user-css>
218
235
  ${config.style || ""}
219
236
  </style>
220
- <ul class="pops-${popsType}-search-suggestion-hint ${PopsCommonCSSClassName.userSelectNone}">${
221
- config.toSearhNotResultHTML
222
- }</ul>
237
+ <div class="pops-${popsType}-search-suggestion-dropdown-wrapper">
238
+ <ul class="pops-${popsType}-search-suggestion-dropdown-container ${PopsCommonCSSClassName.userSelectNone}">${
239
+ config.toSearhNotResultHTML
240
+ }</ul>
241
+ </div>
242
+ <!-- 箭头 -->
223
243
  ${config.useArrow ? /*html*/ `<div class="pops-${popsType}-search-suggestion-arrow"></div>` : ""}
224
244
  `,
225
245
  },
@@ -258,25 +278,27 @@ export const PopsSearchSuggestion = {
258
278
  position: ${config.isAbsolute ? "absolute" : "fixed"};
259
279
  z-index: ${PopsHandler.handleZIndex(config.zIndex)};
260
280
  }
261
- ul.pops-${popsType}-search-suggestion-hint{
281
+ .pops-${popsType}-search-suggestion-dropdown-wrapper{
262
282
  max-height: ${config.maxHeight};
283
+ border-radius: 4px;
284
+ box-shadow: 0 1px 6px var(--search-suggestion-box-shadow-color);
285
+ background-color: var(--search-suggestion-bg-color);
286
+ padding: 5px 0;
263
287
  overflow-x: hidden;
264
288
  overflow-y: auto;
265
- padding: 5px 0;
266
- background-color: var(--search-suggestion-bg-color);
289
+ }
290
+ .pops-${popsType}-search-suggestion-dropdown-wrapper ul.pops-${popsType}-search-suggestion-dropdown-container{
267
291
  box-sizing: border-box;
268
- border-radius: 4px;
269
- box-shadow: 0 1px 6px var(--search-suggestion-box-shadow-color);
270
292
  }
271
- /* 建议框在上面时 */
272
- .pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-hint{
293
+ // 建议框在上面时
294
+ .pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-dropdown-container{
273
295
  display: flex;
274
296
  flex-direction: column-reverse;
275
297
  }
276
- .pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-hint li{
298
+ .pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-dropdown-container li{
277
299
  flex-shrink: 0;
278
300
  }
279
- ul.pops-${popsType}-search-suggestion-hint li{
301
+ ul.pops-${popsType}-search-suggestion-dropdown-container li{
280
302
  padding: 7px;
281
303
  margin: 0;
282
304
  clear: both;
@@ -289,12 +311,12 @@ export const PopsSearchSuggestion = {
289
311
  text-overflow: ellipsis;
290
312
  width: 100%;
291
313
  }
292
- ul.pops-${popsType}-search-suggestion-hint li[data-none]{
314
+ ul.pops-${popsType}-search-suggestion-dropdown-container li[data-none]{
293
315
  text-align: center;
294
316
  font-size: 12px;
295
317
  color: var(--search-suggestion-item-none-color);
296
318
  }
297
- ul.pops-${popsType}-search-suggestion-hint li:not([data-none]):hover{
319
+ ul.pops-${popsType}-search-suggestion-dropdown-container li:not([data-none]):hover{
298
320
  background-color: var(--search-suggestion-item-is-hover-bg-color);
299
321
  }
300
322
  @media (prefers-color-scheme: dark){
@@ -321,7 +343,7 @@ export const PopsSearchSuggestion = {
321
343
  createSearchItemLiElement(dataItem: PopsSearchSuggestionData<T>, dateItemIndex: number) {
322
344
  const dataValue = SearchSuggestion.getItemDataValue(dataItem);
323
345
  const $li = popsDOMUtils.createElement("li", {
324
- className: `pops-${popsType}-search-suggestion-hint-item`,
346
+ className: `pops-${popsType}-search-suggestion-dropdown-item`,
325
347
  "data-index": dateItemIndex,
326
348
  "data-value": dataValue,
327
349
  });
@@ -367,8 +389,8 @@ export const PopsSearchSuggestion = {
367
389
  $searchItem.remove();
368
390
  }
369
391
  }
370
- if (!SearchSuggestion.$el.$hintULContainer.children.length) {
371
- /* 全删完了 */
392
+ if (!SearchSuggestion.$el.$dropdownContainer.children.length) {
393
+ // 全删完了
372
394
  SearchSuggestion.clear();
373
395
  }
374
396
  SearchSuggestion.updateStyleSheet();
@@ -378,10 +400,10 @@ export const PopsSearchSuggestion = {
378
400
  const result = await dataItem.clickCallback(event, $searchItem, dataItem, config);
379
401
  if (typeof result === "boolean" && result) {
380
402
  if (
381
- config.inputTarget instanceof HTMLInputElement ||
382
- config.inputTarget instanceof HTMLTextAreaElement
403
+ config.$inputTarget instanceof HTMLInputElement ||
404
+ config.$inputTarget instanceof HTMLTextAreaElement
383
405
  ) {
384
- config.inputTarget.value = String(dataItem.value);
406
+ config.$inputTarget.value = String(dataItem.value);
385
407
  }
386
408
  }
387
409
  }
@@ -419,21 +441,21 @@ export const PopsSearchSuggestion = {
419
441
  capture: true,
420
442
  }
421
443
  ) {
422
- /* 必须是input或者textarea才有input事件 */
423
- if (!(config.inputTarget instanceof HTMLInputElement || config.inputTarget instanceof HTMLTextAreaElement)) {
444
+ // 必须是input或者textarea才有input事件
445
+ if (!(config.$inputTarget instanceof HTMLInputElement || config.$inputTarget instanceof HTMLTextAreaElement)) {
424
446
  return;
425
447
  }
426
- /* 是input输入框 */
427
- /* 禁用输入框自动提示 */
428
- config.inputTarget.setAttribute("autocomplete", "off");
429
- /* 内容改变事件 */
448
+ // 是input输入框
449
+ // 禁用输入框自动提示
450
+ config.$inputTarget.setAttribute("autocomplete", "off");
451
+ // 内容改变事件
430
452
  const listenerHandler = popsDOMUtils.onInput(
431
- config.inputTarget,
453
+ config.$inputTarget,
432
454
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
433
455
  async (_event) => {
434
456
  const data = SearchSuggestion.getData();
435
457
  const queryDataResult = await config.inputTargetChangeRefreshShowDataCallback(
436
- config.inputTarget.value,
458
+ config.$inputTarget.value,
437
459
  data,
438
460
  config
439
461
  );
@@ -481,21 +503,16 @@ export const PopsSearchSuggestion = {
481
503
  setShowEvent(
482
504
  option: AddEventListenerOptions = {
483
505
  capture: true,
506
+ passive: true,
484
507
  }
485
508
  ) {
486
509
  /* 焦点|点击事件*/
487
510
  if (config.followPosition === "target") {
488
- popsDOMUtils.on([config.target], ["focus", "click"], void 0, SearchSuggestion.showEvent, option);
511
+ popsDOMUtils.on([config.$target], ["focus", "click"], void 0, SearchSuggestion.showEvent, option);
489
512
  } else if (config.followPosition === "input") {
490
- popsDOMUtils.on([config.inputTarget], ["focus", "click"], void 0, SearchSuggestion.showEvent, option);
513
+ popsDOMUtils.on([config.$inputTarget], ["focus", "click"], void 0, SearchSuggestion.showEvent, option);
491
514
  } else if (config.followPosition === "inputCursor") {
492
- popsDOMUtils.on(
493
- [config.inputTarget],
494
- ["focus", "click", "input"],
495
- void 0,
496
- SearchSuggestion.showEvent,
497
- option
498
- );
515
+ popsDOMUtils.on([config.$inputTarget], ["focus", "click", "input"], SearchSuggestion.showEvent, option);
499
516
  } else {
500
517
  throw new Error("未知followPosition:" + config.followPosition);
501
518
  }
@@ -506,18 +523,19 @@ export const PopsSearchSuggestion = {
506
523
  removeShowEvent(
507
524
  option: AddEventListenerOptions = {
508
525
  capture: true,
526
+ passive: true,
509
527
  }
510
528
  ) {
511
529
  /* 焦点|点击事件*/
512
530
  popsDOMUtils.off(
513
- [config.target, config.inputTarget],
531
+ [config.$target, config.$inputTarget],
514
532
  ["focus", "click"],
515
533
  void 0,
516
534
  SearchSuggestion.showEvent,
517
535
  option
518
536
  );
519
- /* 内容改变事件 */
520
- popsDOMUtils.off([config.inputTarget], ["input"], void 0, SearchSuggestion.showEvent, option);
537
+ // 内容改变事件
538
+ popsDOMUtils.off([config.$inputTarget], ["input"], void 0, SearchSuggestion.showEvent, option);
521
539
  },
522
540
  /**
523
541
  * 隐藏搜索建议框的事件
@@ -526,15 +544,15 @@ export const PopsSearchSuggestion = {
526
544
  hideEvent(event: PointerEvent | MouseEvent) {
527
545
  if (event.target instanceof Node) {
528
546
  if ($shadowContainer.contains(event.target)) {
529
- /* 点击在shadow上的 */
547
+ // 点击在shadow上的
530
548
  return;
531
549
  }
532
- if (config.target.contains(event.target)) {
533
- /* 点击在目标元素内 */
550
+ if (config.$target.contains(event.target)) {
551
+ // 点击在目标元素内
534
552
  return;
535
553
  }
536
- if (config.inputTarget.contains(event.target)) {
537
- /* 点击在目标input内 */
554
+ if (config.$inputTarget.contains(event.target)) {
555
+ // 点击在目标input内
538
556
  return;
539
557
  }
540
558
  SearchSuggestion.hide(true);
@@ -546,22 +564,17 @@ export const PopsSearchSuggestion = {
546
564
  setHideEvent(
547
565
  option: AddEventListenerOptions = {
548
566
  capture: true,
567
+ passive: true,
549
568
  }
550
569
  ) {
551
- /* 全局点击事件 */
552
- /* 全局触摸屏点击事件 */
570
+ // 全局点击事件
571
+ // 全局触摸屏点击事件
553
572
  if (Array.isArray(SearchSuggestion.selfDocument)) {
554
573
  SearchSuggestion.selfDocument.forEach(($checkParent) => {
555
574
  popsDOMUtils.on($checkParent, ["click", "touchstart"], void 0, SearchSuggestion.hideEvent, option);
556
575
  });
557
576
  } else {
558
- popsDOMUtils.on(
559
- SearchSuggestion.selfDocument,
560
- ["click", "touchstart"],
561
- void 0,
562
- SearchSuggestion.hideEvent,
563
- option
564
- );
577
+ popsDOMUtils.on(SearchSuggestion.selfDocument, ["click", "touchstart"], SearchSuggestion.hideEvent, option);
565
578
  }
566
579
  },
567
580
  /**
@@ -570,6 +583,7 @@ export const PopsSearchSuggestion = {
570
583
  removeHideEvent(
571
584
  option: AddEventListenerOptions = {
572
585
  capture: true,
586
+ passive: true,
573
587
  }
574
588
  ) {
575
589
  if (Array.isArray(SearchSuggestion.selfDocument)) {
@@ -587,11 +601,12 @@ export const PopsSearchSuggestion = {
587
601
  }
588
602
  },
589
603
  /**
590
- * 设置所有监听
604
+ * 设置所有监听,包括(input值改变、全局点击判断显示/隐藏建议框)
591
605
  */
592
606
  setAllEvent(
593
607
  option: AddEventListenerOptions = {
594
608
  capture: true,
609
+ passive: true,
595
610
  }
596
611
  ) {
597
612
  SearchSuggestion.setInputChangeEvent(option);
@@ -604,6 +619,7 @@ export const PopsSearchSuggestion = {
604
619
  removeAllEvent(
605
620
  option: AddEventListenerOptions = {
606
621
  capture: true,
622
+ passive: true,
607
623
  }
608
624
  ) {
609
625
  SearchSuggestion.removeInputChangeEvent(option);
@@ -627,7 +643,7 @@ export const PopsSearchSuggestion = {
627
643
  */
628
644
  setPromptsInSearch() {
629
645
  const $isSearching = popsDOMUtils.createElement("li", {
630
- className: `pops-${popsType}-search-suggestion-hint-searching-item`,
646
+ className: `pops-${popsType}-search-suggestion-dropdown-searching-item`,
631
647
  innerHTML: config.searchingTip,
632
648
  });
633
649
  SearchSuggestion.addItem($isSearching);
@@ -636,8 +652,8 @@ export const PopsSearchSuggestion = {
636
652
  * 移除正在搜索中的提示
637
653
  */
638
654
  removePromptsInSearch() {
639
- SearchSuggestion.$el.$hintULContainer
640
- .querySelector<HTMLLIElement>(`li.pops-${popsType}-search-suggestion-hint-searching-item`)
655
+ SearchSuggestion.$el.$dropdownContainer
656
+ .querySelector<HTMLLIElement>(`li.pops-${popsType}-search-suggestion-dropdown-searching-item`)
641
657
  ?.remove();
642
658
  },
643
659
  /**
@@ -646,13 +662,13 @@ export const PopsSearchSuggestion = {
646
662
  * @param target 目标元素
647
663
  * @param checkPositonAgain 是否在更新位置信息后检测更新位置信息,默认true
648
664
  */
649
- changeHintULElementPosition(target = config.target ?? config.inputTarget, checkPositonAgain: boolean = true) {
665
+ changeHintULElementPosition(target = config.$target ?? config.$inputTarget, checkPositonAgain: boolean = true) {
650
666
  let targetRect: DOMRect | null = null;
651
667
  if (config.followPosition === "inputCursor") {
652
668
  targetRect = popsDOMUtils.getTextBoundingRect(
653
- config.inputTarget,
654
- config.inputTarget.selectionStart || 0,
655
- config.inputTarget.selectionEnd || 0,
669
+ config.$inputTarget,
670
+ config.$inputTarget.selectionStart || 0,
671
+ config.$inputTarget.selectionEnd || 0,
656
672
  false
657
673
  );
658
674
  } else {
@@ -669,12 +685,16 @@ export const PopsSearchSuggestion = {
669
685
  }
670
686
  // 文档最大宽度
671
687
  const documentWidth = popsDOMUtils.width(document);
688
+ // 箭头
689
+ const arrowHeight = config.useArrow ? popsDOMUtils.height(SearchSuggestion.$el.$arrow) : 0;
672
690
 
673
691
  let position = config.position;
674
692
  if (config.position === "auto") {
675
693
  // 需目标高度+搜索建议框高度大于文档高度,则显示在上面
676
694
  const targetBottom = targetRect.bottom;
677
- const searchSuggestionContainerHeight = popsDOMUtils.height(SearchSuggestion.$el.$hintULContainer);
695
+ // 容器整体的高度
696
+ const searchSuggestionContainerHeight =
697
+ popsDOMUtils.height(SearchSuggestion.$el.$dropdownWrapper) + arrowHeight;
678
698
  if (targetBottom + searchSuggestionContainerHeight > documentHeight) {
679
699
  // 在上面
680
700
  position = "top";
@@ -693,7 +713,7 @@ export const PopsSearchSuggestion = {
693
713
  // 翻转折叠
694
714
  SearchSuggestion.$el.root.setAttribute("data-popper-placement", "top");
695
715
  }
696
- const bottom = documentHeight - targetRect.top + config.topDistance;
716
+ const bottom = documentHeight - targetRect.top + config.topDistance + arrowHeight;
697
717
  SearchSuggestion.$el.root.style.top = "";
698
718
  SearchSuggestion.$el.root.style.bottom = bottom + "px";
699
719
  } else if (position === "bottom") {
@@ -701,13 +721,13 @@ export const PopsSearchSuggestion = {
701
721
  if (config.useFoldAnimation) {
702
722
  SearchSuggestion.$el.root.setAttribute("data-popper-placement", "bottom-center");
703
723
  }
704
- const top = targetRect.height + targetRect.top + config.topDistance;
724
+ const top = targetRect.height + targetRect.top + config.topDistance + arrowHeight;
705
725
  SearchSuggestion.$el.root.removeAttribute("data-top-reverse");
706
726
  SearchSuggestion.$el.root.style.bottom = "";
707
727
  SearchSuggestion.$el.root.style.top = top + "px";
708
728
  }
709
729
  let left = targetRect.left;
710
- const hintUIWidth = popsDOMUtils.width(SearchSuggestion.$el.$hintULContainer);
730
+ const hintUIWidth = popsDOMUtils.width(SearchSuggestion.$el.$dropdownWrapper);
711
731
  if (hintUIWidth > documentWidth) {
712
732
  // 超出宽度
713
733
  left = left + documentWidth - hintUIWidth;
@@ -728,12 +748,12 @@ export const PopsSearchSuggestion = {
728
748
  * 因为目标元素可能是动态隐藏的
729
749
  * @param target 目标元素
730
750
  */
731
- changeHintULElementWidth(target = config.target ?? config.inputTarget) {
751
+ changeHintULElementWidth(target = config.$target ?? config.$inputTarget) {
732
752
  const targetRect = target.getBoundingClientRect();
733
753
  if (config.followTargetWidth) {
734
- SearchSuggestion.$el.$hintULContainer.style.width = targetRect.width + "px";
754
+ SearchSuggestion.$el.$dropdownWrapper.style.width = targetRect.width + "px";
735
755
  } else {
736
- SearchSuggestion.$el.$hintULContainer.style.width = config.width;
756
+ SearchSuggestion.$el.$dropdownWrapper.style.width = config.width;
737
757
  }
738
758
  },
739
759
  /**
@@ -763,7 +783,7 @@ export const PopsSearchSuggestion = {
763
783
  * @param $item 项元素
764
784
  */
765
785
  addItem($item: HTMLElement | DocumentFragment) {
766
- SearchSuggestion.$el.$hintULContainer.appendChild($item);
786
+ SearchSuggestion.$el.$dropdownContainer.appendChild($item);
767
787
  },
768
788
  /**
769
789
  * 更新页面显示的搜索结果
@@ -774,14 +794,14 @@ export const PopsSearchSuggestion = {
774
794
  throw new TypeError("传入的数据不是数组");
775
795
  }
776
796
  const data = updateData;
777
- /* 清空已有的搜索结果 */
797
+ // 清空已有的搜索结果
778
798
  if (data.length) {
779
799
  SearchSuggestion.$data.isEmpty = false;
780
800
  if (config.toHideWithNotResult) {
781
801
  SearchSuggestion.show();
782
802
  }
783
803
  SearchSuggestion.clear(true);
784
- /* 添加进ul中 */
804
+ // 添加进ul中
785
805
  const fragment = document.createDocumentFragment();
786
806
  data.forEach((item, index) => {
787
807
  const $item = SearchSuggestion.createSearchItemLiElement(item, index);
@@ -791,7 +811,7 @@ export const PopsSearchSuggestion = {
791
811
  });
792
812
  SearchSuggestion.addItem(fragment);
793
813
  } else {
794
- /* 清空 */
814
+ // 清空
795
815
  SearchSuggestion.clear();
796
816
  }
797
817
  },
@@ -800,7 +820,7 @@ export const PopsSearchSuggestion = {
800
820
  * @param [onlyClearView=false] 是否仅清空元素,默认false
801
821
  */
802
822
  clear(onlyClearView: boolean = false) {
803
- PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$hintULContainer, "");
823
+ PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$dropdownContainer, "");
804
824
  if (onlyClearView) {
805
825
  return;
806
826
  }
@@ -1,7 +1,7 @@
1
- import type { PopsCommonConfig } from "../../../types/components";
2
- import type { PopsPanelCommonDetails } from "../../panel/types/components-common";
1
+ import type { PopsGeneralConfig } from "../../../types/components";
2
+ import type { PopsPanelGeneralConfig } from "../../panel/types/components-common";
3
3
 
4
- export type PopsSearchSuggestionData<T = any> = {
4
+ export type PopsSearchSuggestionData<T> = {
5
5
  /**
6
6
  * 值
7
7
  */
@@ -33,7 +33,7 @@ export type PopsSearchSuggestionData<T = any> = {
33
33
  /**
34
34
  * 当前配置
35
35
  */
36
- config: PopsSearchSuggestionDetails<T>
36
+ config: PopsSearchSuggestionConfig<T>
37
37
  ) => void | boolean | Promise<void | boolean>;
38
38
  /**
39
39
  * 获取每一项的html,在显示的时候会调用该函数
@@ -52,7 +52,7 @@ export type PopsSearchSuggestionData<T = any> = {
52
52
  /**
53
53
  * 当前配置
54
54
  */
55
- config: PopsSearchSuggestionDetails<T>
55
+ config: PopsSearchSuggestionConfig<T>
56
56
  ) => HTMLElement | string;
57
57
  /**
58
58
  * 每一项的点击回调
@@ -76,8 +76,8 @@ export type PopsSearchSuggestionData<T = any> = {
76
76
  /**
77
77
  * 当前配置
78
78
  */
79
- config: PopsSearchSuggestionDetails<T>
80
- ) => void | boolean | Promise<void | boolean>;
79
+ config: PopsSearchSuggestionConfig<T>
80
+ ) => IPromise<void | boolean>;
81
81
  /**
82
82
  * 键盘的上下键选择的回调
83
83
  */
@@ -97,31 +97,33 @@ export type PopsSearchSuggestionData<T = any> = {
97
97
  /**
98
98
  * 当前配置
99
99
  */
100
- config: PopsSearchSuggestionDetails<T>
100
+ config: PopsSearchSuggestionConfig<T>
101
101
  ) => void;
102
102
  };
103
103
  /**
104
104
  * 搜索建议悬浮窗
105
105
  * pops.searchSuggestion
106
106
  */
107
- export interface PopsSearchSuggestionDetails<T = any>
108
- extends Pick<PopsCommonConfig, "useShadowRoot" | "zIndex" | "style"> {
107
+ export interface PopsSearchSuggestionConfig<T = any>
108
+ extends Pick<PopsGeneralConfig, "useShadowRoot" | "zIndex" | "style"> {
109
109
  /**
110
110
  * 当前的环境,可以是document,可以是shadowroot,默认是document
111
+ *
112
+ * 用于检测监听全局点击事件
111
113
  * @default document
112
114
  */
113
- selfDocument?: Document | ShadowRoot | (Document | ShadowRoot)[];
115
+ $selfDocument?: Document | ShadowRoot | (Document | ShadowRoot)[];
114
116
  /**
115
117
  * 目标元素,一般是跟随它的位置变化,监听它的focus/click
116
118
  */
117
- target: HTMLElement;
119
+ $target: HTMLElement;
118
120
  /**
119
121
  * 目标input元素,监听它的focus/click/input事件
120
122
  *
121
123
  * 如果未填,那么自动使用target的值
122
124
  * @default config.target
123
125
  */
124
- inputTarget?: HTMLInputElement | HTMLTextAreaElement;
126
+ $inputTarget?: HTMLInputElement | HTMLTextAreaElement;
125
127
  /**
126
128
  * 数据
127
129
  */
@@ -130,7 +132,7 @@ export interface PopsSearchSuggestionDetails<T = any>
130
132
  * (可选)元素的className,值为空的话就不设置
131
133
  * @default ""
132
134
  */
133
- className?: PopsPanelCommonDetails<any>["className"];
135
+ className?: PopsPanelGeneralConfig<any>["className"];
134
136
  /**
135
137
  * 建议框的position位置
136
138
  *
@@ -235,6 +237,6 @@ export interface PopsSearchSuggestionDetails<T = any>
235
237
  /**
236
238
  * 当前配置
237
239
  */
238
- config: PopsSearchSuggestionDetails<T>
240
+ config: PopsSearchSuggestionConfig<T>
239
241
  ) => Promise<PopsSearchSuggestionData<T>[]> | PopsSearchSuggestionData<T>[];
240
242
  }
@@ -1,10 +1,9 @@
1
- import type { PopsToolTipDetails } from "./types/index";
1
+ import type { PopsToolTipConfig } from "./types/index";
2
2
 
3
- export const PopsTooltipConfig = (): DeepRequired<PopsToolTipDetails> => {
4
- // @ts-ignore
3
+ export const PopsTooltipDefaultConfig = (): DeepRequired<PopsToolTipConfig> => {
5
4
  return {
6
5
  useShadowRoot: true,
7
- target: null as any,
6
+ $target: null as any,
8
7
  content: "默认文字",
9
8
  isDiffContent: false,
10
9
  position: "top",
@@ -16,9 +15,9 @@ export const PopsTooltipConfig = (): DeepRequired<PopsToolTipDetails> => {
16
15
  zIndex: 10000,
17
16
  only: false,
18
17
  eventOption: {
18
+ once: false,
19
19
  passive: false,
20
20
  capture: true,
21
- once: false,
22
21
  },
23
22
  showBeforeCallBack() {},
24
23
  showAfterCallBack() {},
@@ -30,5 +29,5 @@ export const PopsTooltipConfig = (): DeepRequired<PopsToolTipDetails> => {
30
29
  otherDistance: 0,
31
30
  style: "",
32
31
  beforeAppendToPageCallBack() {},
33
- } as Required<PopsToolTipDetails>;
32
+ };
34
33
  };