@whitesev/pops 1.6.0 → 1.6.1

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 (62) hide show
  1. package/dist/index.amd.js +3666 -3125
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +3666 -3125
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +3666 -3125
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +3666 -3125
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +3666 -3125
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +3666 -3125
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Pops.d.ts +56 -7
  14. package/dist/types/src/components/alert/config.d.ts +2 -0
  15. package/dist/types/src/components/confirm/config.d.ts +2 -0
  16. package/dist/types/src/components/drawer/config.d.ts +2 -0
  17. package/dist/types/src/components/folder/config.d.ts +2 -0
  18. package/dist/types/src/components/iframe/config.d.ts +2 -0
  19. package/dist/types/src/components/loading/config.d.ts +2 -0
  20. package/dist/types/src/components/panel/PanelHandleContentDetails.d.ts +149 -0
  21. package/dist/types/src/components/panel/config.d.ts +2 -0
  22. package/dist/types/src/components/panel/selectMultipleType.d.ts +49 -24
  23. package/dist/types/src/components/prompt/config.d.ts +2 -0
  24. package/dist/types/src/components/rightClickMenu/config.d.ts +2 -0
  25. package/dist/types/src/components/searchSuggestion/config.d.ts +2 -0
  26. package/dist/types/src/components/searchSuggestion/indexType.d.ts +56 -32
  27. package/dist/types/src/components/tooltip/config.d.ts +2 -0
  28. package/dist/types/src/utils/PopsDOMUtils.d.ts +42 -13
  29. package/dist/types/src/utils/PopsInstanceUtils.d.ts +22 -0
  30. package/package.json +4 -1
  31. package/src/Pops.ts +8 -2
  32. package/src/components/alert/config.ts +59 -0
  33. package/src/components/alert/index.ts +2 -57
  34. package/src/components/confirm/config.ts +94 -0
  35. package/src/components/confirm/index.ts +4 -94
  36. package/src/components/drawer/config.ts +90 -0
  37. package/src/components/drawer/index.ts +2 -88
  38. package/src/components/folder/config.ts +130 -0
  39. package/src/components/folder/index.ts +3 -129
  40. package/src/components/iframe/config.ts +58 -0
  41. package/src/components/iframe/index.ts +2 -56
  42. package/src/components/loading/config.ts +27 -0
  43. package/src/components/loading/index.ts +2 -25
  44. package/src/components/panel/PanelHandleContentDetails.ts +2612 -0
  45. package/src/components/panel/config.ts +348 -0
  46. package/src/components/panel/index.css +191 -5
  47. package/src/components/panel/index.ts +10 -2521
  48. package/src/components/panel/selectMultipleType.ts +52 -25
  49. package/src/components/prompt/config.ts +102 -0
  50. package/src/components/prompt/index.ts +2 -100
  51. package/src/components/rightClickMenu/config.ts +122 -0
  52. package/src/components/rightClickMenu/index.css +78 -0
  53. package/src/components/rightClickMenu/index.ts +26 -202
  54. package/src/components/searchSuggestion/config.ts +55 -0
  55. package/src/components/searchSuggestion/index.ts +228 -205
  56. package/src/components/searchSuggestion/indexType.ts +56 -32
  57. package/src/components/tooltip/config.ts +29 -0
  58. package/src/components/tooltip/index.ts +2 -27
  59. package/src/css/animation.css +22 -0
  60. package/src/utils/PopsDOMUtils.ts +108 -29
  61. package/src/utils/PopsInstanceUtils.ts +80 -0
  62. package/src/components/searchSuggestion/index.css +0 -0
@@ -3,6 +3,7 @@ import { pops } from "../../Pops";
3
3
  import { popsDOMUtils } from "../../utils/PopsDOMUtils";
4
4
  import { popsUtils } from "../../utils/PopsUtils";
5
5
  import type { PopsSearchSuggestionDetails } from "./indexType";
6
+ import { searchSuggestionConfig as PopsSearchSuggestionConfig } from "./config";
6
7
 
7
8
  export class PopsSearchSuggestion {
8
9
  constructor(details: PopsSearchSuggestionDetails) {
@@ -13,59 +14,8 @@ export class PopsSearchSuggestion {
13
14
  pops.config.cssText.common,
14
15
  ]);
15
16
 
16
- let config: Required<PopsSearchSuggestionDetails> = {
17
- // @ts-ignore
18
- target: null,
19
- // @ts-ignore
20
- inputTarget: null,
21
- selfDocument: document,
22
- data: [
23
- {
24
- value: "数据1",
25
- text: "数据1-html",
26
- },
27
- {
28
- value: "数据2",
29
- text: "数据2-html",
30
- },
31
- ],
32
- deleteIcon: {
33
- enable: true,
34
- callback(event, liElement, data) {
35
- console.log("删除当前项", [event, liElement, data]);
36
- liElement.remove();
37
- },
38
- },
39
- className: "",
40
- isAbsolute: true,
41
- isAnimation: true,
42
- width: "250px",
43
- maxHeight: "300px",
44
- followTargetWidth: true,
45
- topDistance: 0,
46
- position: "auto",
47
- positionTopToReverse: true,
48
- zIndex: 10000,
49
- searchingTip: "正在搜索中...",
50
- toSearhNotResultHTML: '<li data-none="true">暂无其它数据</li>',
51
- toHideWithNotResult: false,
52
- followPosition: "target",
53
- getItemHTML(item) {
54
- return item.text ?? item;
55
- },
56
- async getData(value) {
57
- console.log("当前输入框的值是:", value);
58
- return [];
59
- },
60
- itemClickCallBack(event, liElement, data) {
61
- console.log("item项的点击回调", [event, liElement, data]);
62
- this.inputTarget.value = data.value;
63
- },
64
- selectCallBack(event, liElement, data) {
65
- console.log("item项的选中回调", [event, liElement, data]);
66
- },
67
- style: "",
68
- };
17
+ let config: Required<PopsSearchSuggestionDetails> =
18
+ PopsSearchSuggestionConfig;
69
19
  config = popsUtils.assign(config, details);
70
20
  if (config.target == null) {
71
21
  throw new TypeError("config.target 不能为空");
@@ -92,14 +42,14 @@ export class PopsSearchSuggestion {
92
42
  * 当前的环境,可以是document,可以是shadowroot,默认是document
93
43
  */
94
44
  selfDocument: config.selfDocument,
95
- /**
96
- * 根元素
97
- */
98
- root: null as any as HTMLElement,
99
- /**
100
- * ul元素
101
- */
102
- hintULElement: null as any as HTMLUListElement,
45
+ $el: {
46
+ /** 根元素 */
47
+ root: null as any as HTMLElement,
48
+ /** ul元素 */
49
+ $hintULContainer: null as any as HTMLUListElement,
50
+ /** 动态更新CSS */
51
+ $dynamicCSS: null as any as HTMLStyleElement,
52
+ },
103
53
  $data: {
104
54
  /** 是否结果为空 */
105
55
  isEmpty: true,
@@ -108,20 +58,30 @@ export class PopsSearchSuggestion {
108
58
  * 初始化
109
59
  */
110
60
  init(parentElement = document.body || document.documentElement) {
111
- SearchSuggestion.root = SearchSuggestion.getSearchSelectElement();
112
- SearchSuggestion.hintULElement =
113
- SearchSuggestion.root.querySelector<HTMLUListElement>("ul")!;
114
- SearchSuggestion.update(config.data);
61
+ this.initEl();
62
+ SearchSuggestion.update(
63
+ typeof config.data === "function" ? config.data() : config.data
64
+ );
65
+ SearchSuggestion.updateDynamicCSS();
115
66
  SearchSuggestion.changeHintULElementWidth();
116
67
  SearchSuggestion.changeHintULElementPosition();
117
68
 
118
69
  SearchSuggestion.hide();
119
70
  if (config.isAnimation) {
120
- SearchSuggestion.root.classList.add(`pops-${PopsType}-animation`);
71
+ SearchSuggestion.$el.root.classList.add(`pops-${PopsType}-animation`);
121
72
  }
122
- $shadowRoot.appendChild(SearchSuggestion.root);
73
+ $shadowRoot.appendChild(SearchSuggestion.$el.root);
123
74
  parentElement.appendChild($shadowContainer);
124
75
  },
76
+ /** 初始化元素变量 */
77
+ initEl() {
78
+ this.$el.root = SearchSuggestion.getSearchSelectElement();
79
+ this.$el.$dynamicCSS = this.$el.root.querySelector<HTMLStyleElement>(
80
+ "style[data-dynamic]"
81
+ )!;
82
+ this.$el.$hintULContainer =
83
+ SearchSuggestion.$el.root.querySelector<HTMLUListElement>("ul")!;
84
+ },
125
85
  /**
126
86
  * 获取显示出搜索建议框的html
127
87
  */
@@ -130,61 +90,9 @@ export class PopsSearchSuggestion {
130
90
  "div",
131
91
  {
132
92
  className: `pops pops-${PopsType}-search-suggestion`,
133
- innerHTML: `
134
- <style>
135
- .pops-${PopsType}-animation{
136
- -moz-animation: searchSelectFalIn 0.5s 1 linear;
137
- -webkit-animation: searchSelectFalIn 0.5s 1 linear;
138
- -o-animation: searchSelectFalIn 0.5s 1 linear;
139
- -ms-animation: searchSelectFalIn 0.5s 1 linear;
140
- }
141
- .pops-${PopsType}-search-suggestion{
142
- border: initial;
143
- overflow: initial;
144
- }
145
- ul.pops-${PopsType}-search-suggestion-hint{
146
- position: ${config.isAbsolute ? "absolute" : "fixed"};
147
- z-index: ${PopsHandler.handleZIndex(config.zIndex)};
148
- width: 0;
149
- left: 0;
150
- max-height: ${config.maxHeight};
151
- overflow-x: hidden;
152
- overflow-y: auto;
153
- padding: 5px 0;
154
- background-color: #fff;
155
- box-sizing: border-box;
156
- border-radius: 4px;
157
- box-shadow: 0 1px 6px rgb(0 0 0 / 20%);
158
- }
159
- /* 建议框在上面时 */
160
- ul.pops-${PopsType}-search-suggestion-hint[data-top-reverse]{
161
- display: flex;
162
- flex-direction: column-reverse;
163
- }
164
- ul.pops-${PopsType}-search-suggestion-hint[data-top-reverse] li{
165
- flex-shrink: 0;
166
- }
167
- ul.pops-${PopsType}-search-suggestion-hint li{
168
- padding: 7px;
169
- margin: 0;
170
- clear: both;
171
- color: #515a6e;
172
- font-size: 14px;
173
- list-style: none;
174
- cursor: pointer;
175
- transition: background .2s ease-in-out;
176
- overflow: hidden;
177
- text-overflow: ellipsis;
178
- width: 100%;
179
- }
180
- ul.pops-${PopsType}-search-suggestion-hint li[data-none]{
181
- text-align: center;
182
- font-size: 12px;
183
- color: #8e8e8e;
184
- }
185
- ul.pops-${PopsType}-search-suggestion-hint li:hover{
186
- background-color: rgba(0, 0, 0, .1);
187
- }
93
+ innerHTML: /*html*/ `
94
+ <style data-dynamic="true">
95
+ ${this.getDynamicCSS()}
188
96
  </style>
189
97
  <ul class="pops-${PopsType}-search-suggestion-hint">
190
98
  ${config.toSearhNotResultHTML}
@@ -201,6 +109,64 @@ export class PopsSearchSuggestion {
201
109
  }
202
110
  return element;
203
111
  },
112
+ /** 动态获取CSS */
113
+ getDynamicCSS() {
114
+ return /*css*/ `
115
+ .pops-${PopsType}-animation{
116
+ -moz-animation: searchSelectFalIn 0.5s 1 linear;
117
+ -webkit-animation: searchSelectFalIn 0.5s 1 linear;
118
+ -o-animation: searchSelectFalIn 0.5s 1 linear;
119
+ -ms-animation: searchSelectFalIn 0.5s 1 linear;
120
+ }
121
+ .pops-${PopsType}-search-suggestion{
122
+ border: initial;
123
+ overflow: initial;
124
+ }
125
+ ul.pops-${PopsType}-search-suggestion-hint{
126
+ position: ${config.isAbsolute ? "absolute" : "fixed"};
127
+ z-index: ${PopsHandler.handleZIndex(config.zIndex)};
128
+ width: 0;
129
+ left: 0;
130
+ max-height: ${config.maxHeight};
131
+ overflow-x: hidden;
132
+ overflow-y: auto;
133
+ padding: 5px 0;
134
+ background-color: #fff;
135
+ box-sizing: border-box;
136
+ border-radius: 4px;
137
+ box-shadow: 0 1px 6px rgb(0 0 0 / 20%);
138
+ }
139
+ /* 建议框在上面时 */
140
+ ul.pops-${PopsType}-search-suggestion-hint[data-top-reverse]{
141
+ display: flex;
142
+ flex-direction: column-reverse;
143
+ }
144
+ ul.pops-${PopsType}-search-suggestion-hint[data-top-reverse] li{
145
+ flex-shrink: 0;
146
+ }
147
+ ul.pops-${PopsType}-search-suggestion-hint li{
148
+ padding: 7px;
149
+ margin: 0;
150
+ clear: both;
151
+ color: #515a6e;
152
+ font-size: 14px;
153
+ list-style: none;
154
+ cursor: pointer;
155
+ transition: background .2s ease-in-out;
156
+ overflow: hidden;
157
+ text-overflow: ellipsis;
158
+ width: 100%;
159
+ }
160
+ ul.pops-${PopsType}-search-suggestion-hint li[data-none]{
161
+ text-align: center;
162
+ font-size: 12px;
163
+ color: #8e8e8e;
164
+ }
165
+ ul.pops-${PopsType}-search-suggestion-hint li:hover{
166
+ background-color: rgba(0, 0, 0, .1);
167
+ }
168
+ `;
169
+ },
204
170
  /**
205
171
  * 获取显示出搜索建议框的每一项的html
206
172
  * @param data 当前项的值
@@ -249,7 +215,7 @@ export class PopsSearchSuggestion {
249
215
  (liElement as any)["data-value"]
250
216
  );
251
217
  }
252
- if (!this.hintULElement.children.length) {
218
+ if (!this.$el.$hintULContainer.children.length) {
253
219
  /* 全删完了 */
254
220
  this.clear();
255
221
  }
@@ -288,7 +254,19 @@ export class PopsSearchSuggestion {
288
254
  /**
289
255
  * 监听输入框内容改变
290
256
  */
291
- setInputChangeEvent() {
257
+ setInputChangeEvent(
258
+ option: AddEventListenerOptions = {
259
+ capture: true,
260
+ }
261
+ ) {
262
+ if (
263
+ !(
264
+ config.inputTarget instanceof HTMLInputElement ||
265
+ config.inputTarget instanceof HTMLTextAreaElement
266
+ )
267
+ ) {
268
+ return;
269
+ }
292
270
  /* 是input输入框 */
293
271
  /* 禁用输入框自动提示 */
294
272
  config.inputTarget.setAttribute("autocomplete", "off");
@@ -303,25 +281,26 @@ export class PopsSearchSuggestion {
303
281
  );
304
282
  SearchSuggestion.update(getListResult);
305
283
  },
306
- {
307
- capture: true,
308
- }
284
+ option
309
285
  );
310
286
  },
311
287
  /**
312
288
  * 移除输入框内容改变的监听
313
289
  */
314
- removeInputChangeEvent() {
315
- popsDOMUtils.off(config.inputTarget, "input", void 0, void 0, {
290
+ removeInputChangeEvent(
291
+ option: AddEventListenerOptions = {
316
292
  capture: true,
317
- });
293
+ }
294
+ ) {
295
+ popsDOMUtils.off(config.inputTarget, "input", void 0, void 0, option);
318
296
  },
319
297
  /**
320
298
  * 显示搜索建议框的事件
321
299
  */
322
300
  showEvent() {
323
- SearchSuggestion.changeHintULElementPosition();
301
+ SearchSuggestion.updateDynamicCSS();
324
302
  SearchSuggestion.changeHintULElementWidth();
303
+ SearchSuggestion.changeHintULElementPosition();
325
304
  if (config.toHideWithNotResult) {
326
305
  if (SearchSuggestion.$data.isEmpty) {
327
306
  SearchSuggestion.hide();
@@ -335,7 +314,11 @@ export class PopsSearchSuggestion {
335
314
  /**
336
315
  * 设置显示搜索建议框的事件
337
316
  */
338
- setShowEvent() {
317
+ setShowEvent(
318
+ option: AddEventListenerOptions = {
319
+ capture: true,
320
+ }
321
+ ) {
339
322
  /* 焦点|点击事件*/
340
323
  if (config.followPosition === "target") {
341
324
  popsDOMUtils.on(
@@ -343,9 +326,7 @@ export class PopsSearchSuggestion {
343
326
  ["focus", "click"],
344
327
  void 0,
345
328
  SearchSuggestion.showEvent,
346
- {
347
- capture: true,
348
- }
329
+ option
349
330
  );
350
331
  } else if (config.followPosition === "input") {
351
332
  popsDOMUtils.on(
@@ -353,9 +334,7 @@ export class PopsSearchSuggestion {
353
334
  ["focus", "click"],
354
335
  void 0,
355
336
  SearchSuggestion.showEvent,
356
- {
357
- capture: true,
358
- }
337
+ option
359
338
  );
360
339
  } else if (config.followPosition === "inputCursor") {
361
340
  popsDOMUtils.on(
@@ -363,9 +342,7 @@ export class PopsSearchSuggestion {
363
342
  ["focus", "click", "input"],
364
343
  void 0,
365
344
  SearchSuggestion.showEvent,
366
- {
367
- capture: true,
368
- }
345
+ option
369
346
  );
370
347
  } else {
371
348
  throw new TypeError("未知followPosition:" + config.followPosition);
@@ -374,16 +351,18 @@ export class PopsSearchSuggestion {
374
351
  /**
375
352
  * 移除显示搜索建议框的事件
376
353
  */
377
- removeShowEvent() {
354
+ removeShowEvent(
355
+ option: AddEventListenerOptions = {
356
+ capture: true,
357
+ }
358
+ ) {
378
359
  /* 焦点|点击事件*/
379
360
  popsDOMUtils.off(
380
361
  [config.target, config.inputTarget],
381
362
  ["focus", "click"],
382
363
  void 0,
383
364
  SearchSuggestion.showEvent,
384
- {
385
- capture: true,
386
- }
365
+ option
387
366
  );
388
367
  /* 内容改变事件 */
389
368
  popsDOMUtils.off(
@@ -391,9 +370,7 @@ export class PopsSearchSuggestion {
391
370
  ["input"],
392
371
  void 0,
393
372
  SearchSuggestion.showEvent,
394
- {
395
- capture: true,
396
- }
373
+ option
397
374
  );
398
375
  },
399
376
  /**
@@ -420,54 +397,90 @@ export class PopsSearchSuggestion {
420
397
  /**
421
398
  * 设置隐藏搜索建议框的事件
422
399
  */
423
- setHideEvent() {
400
+ setHideEvent(
401
+ option: AddEventListenerOptions = {
402
+ capture: true,
403
+ }
404
+ ) {
424
405
  /* 全局点击事件 */
425
406
  /* 全局触摸屏点击事件 */
426
- popsDOMUtils.on(
427
- SearchSuggestion.selfDocument,
428
- ["click", "touchstart"],
429
- void 0,
430
- SearchSuggestion.hideEvent,
431
- {
432
- capture: true,
433
- }
434
- );
407
+ if (Array.isArray(SearchSuggestion.selfDocument)) {
408
+ SearchSuggestion.selfDocument.forEach(($checkParent) => {
409
+ popsDOMUtils.on(
410
+ $checkParent,
411
+ ["click", "touchstart"],
412
+ void 0,
413
+ SearchSuggestion.hideEvent,
414
+ option
415
+ );
416
+ });
417
+ } else {
418
+ popsDOMUtils.on(
419
+ SearchSuggestion.selfDocument,
420
+ ["click", "touchstart"],
421
+ void 0,
422
+ SearchSuggestion.hideEvent,
423
+ option
424
+ );
425
+ }
435
426
  },
436
427
  /**
437
428
  * 移除隐藏搜索建议框的事件
438
429
  */
439
- removeHideEvent() {
440
- popsDOMUtils.off(
441
- SearchSuggestion.selfDocument,
442
- ["click", "touchstart"],
443
- void 0,
444
- SearchSuggestion.hideEvent,
445
- {
446
- capture: true,
447
- }
448
- );
430
+ removeHideEvent(
431
+ option: AddEventListenerOptions = {
432
+ capture: true,
433
+ }
434
+ ) {
435
+ if (Array.isArray(SearchSuggestion.selfDocument)) {
436
+ SearchSuggestion.selfDocument.forEach(($checkParent) => {
437
+ popsDOMUtils.off(
438
+ $checkParent,
439
+ ["click", "touchstart"],
440
+ void 0,
441
+ SearchSuggestion.hideEvent,
442
+ option
443
+ );
444
+ });
445
+ } else {
446
+ popsDOMUtils.off(
447
+ SearchSuggestion.selfDocument,
448
+ ["click", "touchstart"],
449
+ void 0,
450
+ SearchSuggestion.hideEvent,
451
+ option
452
+ );
453
+ }
449
454
  },
450
455
  /**
451
456
  * 设置所有监听
452
457
  */
453
- setAllEvent() {
454
- SearchSuggestion.setInputChangeEvent();
455
- SearchSuggestion.setHideEvent();
456
- SearchSuggestion.setShowEvent();
458
+ setAllEvent(
459
+ option: AddEventListenerOptions = {
460
+ capture: true,
461
+ }
462
+ ) {
463
+ SearchSuggestion.setInputChangeEvent(option);
464
+ SearchSuggestion.setHideEvent(option);
465
+ SearchSuggestion.setShowEvent(option);
457
466
  },
458
467
  /**
459
468
  * 移除所有监听
460
469
  */
461
- removeAllEvent() {
462
- SearchSuggestion.removeInputChangeEvent();
463
- SearchSuggestion.removeHideEvent();
464
- SearchSuggestion.removeShowEvent();
470
+ removeAllEvent(
471
+ option: AddEventListenerOptions = {
472
+ capture: true,
473
+ }
474
+ ) {
475
+ SearchSuggestion.removeInputChangeEvent(option);
476
+ SearchSuggestion.removeHideEvent(option);
477
+ SearchSuggestion.removeShowEvent(option);
465
478
  },
466
479
  /**
467
480
  * 获取删除按钮的html
468
481
  */
469
482
  getDeleteIconHTML(size = 16, fill = "#bababa") {
470
- return `
483
+ return /*html*/ `
471
484
  <svg class="pops-${PopsType}-delete-icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" fill="${fill}">
472
485
  <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>
473
486
  <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>
@@ -482,13 +495,13 @@ export class PopsSearchSuggestion {
482
495
  className: `pops-${PopsType}-search-suggestion-hint-searching-item`,
483
496
  innerHTML: config.searchingTip,
484
497
  });
485
- SearchSuggestion.hintULElement.appendChild(isSearchingElement);
498
+ SearchSuggestion.$el.$hintULContainer.appendChild(isSearchingElement);
486
499
  },
487
500
  /**
488
501
  * 移除正在搜索中的提示
489
502
  */
490
503
  removePromptsInSearch() {
491
- SearchSuggestion.hintULElement
504
+ SearchSuggestion.$el.$hintULContainer
492
505
  .querySelector(
493
506
  `li.pops-${PopsType}-search-suggestion-hint-searching-item`
494
507
  )
@@ -498,17 +511,16 @@ export class PopsSearchSuggestion {
498
511
  * 清空所有的搜索结果
499
512
  */
500
513
  clearAllSearchItemLi() {
501
- SearchSuggestion.hintULElement.innerHTML = "";
514
+ SearchSuggestion.$el.$hintULContainer.innerHTML = "";
502
515
  },
503
516
  /**
504
- * 修改搜索建议框的位置(top、left)
517
+ * 更新搜索建议框的位置(top、left)
505
518
  * 因为目标元素可能是动态隐藏的
506
519
  */
507
520
  changeHintULElementPosition(
508
521
  target = config.target ?? config.inputTarget
509
522
  ) {
510
- /** @type {DOMRect|null} */
511
- let targetRect = null;
523
+ let targetRect: DOMRect | null = null;
512
524
  if (config.followPosition === "inputCursor") {
513
525
  targetRect = popsDOMUtils.getTextBoundingRect(
514
526
  config.inputTarget,
@@ -534,65 +546,76 @@ export class PopsSearchSuggestion {
534
546
  let documentWidth = popsDOMUtils.width(document);
535
547
  if (config.position === "top") {
536
548
  if (config.positionTopToReverse) {
537
- SearchSuggestion.hintULElement.setAttribute(
549
+ SearchSuggestion.$el.$hintULContainer.setAttribute(
538
550
  "data-top-reverse",
539
551
  "true"
540
552
  );
541
553
  }
542
554
  // 在上面
543
- SearchSuggestion.hintULElement.style.top = "";
544
- SearchSuggestion.hintULElement.style.bottom =
555
+ SearchSuggestion.$el.$hintULContainer.style.top = "";
556
+ SearchSuggestion.$el.$hintULContainer.style.bottom =
545
557
  documentHeight - targetRect.top + config.topDistance + "px";
546
558
  } else if (config.position === "bottom") {
547
559
  // 在下面
548
- SearchSuggestion.hintULElement.removeAttribute("data-top-reverse");
549
- SearchSuggestion.hintULElement.style.bottom = "";
550
- SearchSuggestion.hintULElement.style.top =
560
+ SearchSuggestion.$el.$hintULContainer.removeAttribute(
561
+ "data-top-reverse"
562
+ );
563
+ SearchSuggestion.$el.$hintULContainer.style.bottom = "";
564
+ SearchSuggestion.$el.$hintULContainer.style.top =
551
565
  targetRect.height + targetRect.top + config.topDistance + "px";
552
566
  } else if (config.position === "auto") {
553
567
  // 自动判断
554
568
  if (
555
569
  targetRect.bottom +
556
- popsDOMUtils.height(SearchSuggestion.hintULElement) >
570
+ popsDOMUtils.height(SearchSuggestion.$el.$hintULContainer) >
557
571
  documentHeight
558
572
  ) {
559
573
  if (config.positionTopToReverse) {
560
- SearchSuggestion.hintULElement.setAttribute(
574
+ SearchSuggestion.$el.$hintULContainer.setAttribute(
561
575
  "data-top-reverse",
562
576
  "true"
563
577
  );
564
578
  }
565
579
  // 超出浏览器高度了,自动转换为上面去
566
- SearchSuggestion.hintULElement.style.top = "";
567
- SearchSuggestion.hintULElement.style.bottom =
580
+ SearchSuggestion.$el.$hintULContainer.style.top = "";
581
+ SearchSuggestion.$el.$hintULContainer.style.bottom =
568
582
  documentHeight - targetRect.top + config.topDistance + "px";
569
583
  } else {
570
- SearchSuggestion.hintULElement.removeAttribute("data-top");
571
- SearchSuggestion.hintULElement.style.bottom = "";
572
- SearchSuggestion.hintULElement.style.top =
584
+ SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top");
585
+ SearchSuggestion.$el.$hintULContainer.style.bottom = "";
586
+ SearchSuggestion.$el.$hintULContainer.style.top =
573
587
  targetRect.height + targetRect.top + config.topDistance + "px";
574
588
  }
575
589
  } else {
576
590
  throw new TypeError("未知设置的位置" + config.position);
577
591
  }
578
- let hintUIWidth = popsDOMUtils.width(SearchSuggestion.hintULElement);
579
- SearchSuggestion.hintULElement.style.left =
592
+ let hintUIWidth = popsDOMUtils.width(
593
+ SearchSuggestion.$el.$hintULContainer
594
+ );
595
+ SearchSuggestion.$el.$hintULContainer.style.left =
580
596
  (targetRect.left + hintUIWidth > documentWidth
581
597
  ? documentWidth - hintUIWidth
582
598
  : targetRect.left) + "px";
583
599
  },
584
600
  /**
585
- * 修改搜索建议框的width
601
+ * 更新搜索建议框的width
586
602
  * 因为目标元素可能是动态隐藏的
587
603
  */
588
604
  changeHintULElementWidth(target = config.target ?? config.inputTarget) {
589
605
  let targetRect = target.getBoundingClientRect();
590
606
  if (config.followTargetWidth) {
591
- SearchSuggestion.hintULElement.style.width = targetRect.width + "px";
607
+ SearchSuggestion.$el.$hintULContainer.style.width =
608
+ targetRect.width + "px";
592
609
  } else {
593
- SearchSuggestion.hintULElement.style.width = config.width;
610
+ SearchSuggestion.$el.$hintULContainer.style.width = config.width;
594
611
  }
595
612
  },
613
+ /**
614
+ * 动态更新CSS
615
+ */
616
+ updateDynamicCSS() {
617
+ this.$el.$dynamicCSS.innerHTML = this.getDynamicCSS();
618
+ },
596
619
  /**
597
620
  * 更新页面显示的搜索结果
598
621
  * @param data
@@ -618,7 +641,7 @@ export class PopsSearchSuggestion {
618
641
  );
619
642
  SearchSuggestion.setSearchItemClickEvent(itemElement);
620
643
  SearchSuggestion.setSearchItemSelectEvent(itemElement);
621
- SearchSuggestion.hintULElement.appendChild(itemElement);
644
+ SearchSuggestion.$el.$hintULContainer.appendChild(itemElement);
622
645
  });
623
646
  } else {
624
647
  /* 清空 */
@@ -631,7 +654,7 @@ export class PopsSearchSuggestion {
631
654
  clear() {
632
655
  this.$data.isEmpty = true;
633
656
  this.clearAllSearchItemLi();
634
- this.hintULElement.appendChild(
657
+ this.$el.$hintULContainer.appendChild(
635
658
  popsUtils.parseTextToDOM(config.toSearhNotResultHTML)
636
659
  );
637
660
  if (config.toHideWithNotResult) {
@@ -642,13 +665,13 @@ export class PopsSearchSuggestion {
642
665
  * 隐藏搜索建议框
643
666
  */
644
667
  hide() {
645
- this.root.style.display = "none";
668
+ this.$el.root.style.display = "none";
646
669
  },
647
670
  /**
648
671
  * 显示搜索建议框
649
672
  */
650
673
  show() {
651
- this.root.style.display = "";
674
+ this.$el.root.style.display = "";
652
675
  },
653
676
  };
654
677
  return SearchSuggestion;