@whitesev/pops 2.2.7 → 2.2.9

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 (146) hide show
  1. package/dist/index.amd.js +2842 -3019
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +2842 -3019
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +2842 -3019
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +2842 -3019
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +2842 -3019
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +2842 -3019
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Pops.d.ts +11 -11
  14. package/dist/types/src/PopsIcon.d.ts +2 -2
  15. package/dist/types/src/components/rightClickMenu/index.d.ts +2 -2
  16. package/dist/types/src/components/tooltip/index.d.ts +2 -2
  17. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +256 -259
  18. package/dist/types/src/types/animation.d.ts +19 -19
  19. package/dist/types/src/types/button.d.ts +187 -196
  20. package/dist/types/src/types/components.d.ts +213 -229
  21. package/dist/types/src/types/event.d.ts +63 -63
  22. package/dist/types/src/types/global.d.ts +20 -20
  23. package/dist/types/src/types/icon.d.ts +32 -32
  24. package/dist/types/src/types/inst.d.ts +24 -24
  25. package/dist/types/src/types/main.d.ts +114 -122
  26. package/dist/types/src/types/mask.d.ts +49 -49
  27. package/dist/types/src/types/position.d.ts +60 -60
  28. package/package.json +61 -56
  29. package/LICENSE +0 -674
  30. package/src/Pops.ts +0 -209
  31. package/src/PopsAnimation.ts +0 -32
  32. package/src/PopsCSS.ts +0 -51
  33. package/src/PopsCore.ts +0 -44
  34. package/src/PopsIcon.ts +0 -95
  35. package/src/PopsInst.ts +0 -21
  36. package/src/components/alert/config.ts +0 -62
  37. package/src/components/alert/index.css +0 -0
  38. package/src/components/alert/index.ts +0 -181
  39. package/src/components/alert/types/index.ts +0 -30
  40. package/src/components/confirm/config.ts +0 -90
  41. package/src/components/confirm/index.css +0 -0
  42. package/src/components/confirm/index.ts +0 -192
  43. package/src/components/confirm/types/index.ts +0 -17
  44. package/src/components/drawer/config.ts +0 -89
  45. package/src/components/drawer/index.css +0 -35
  46. package/src/components/drawer/index.ts +0 -260
  47. package/src/components/drawer/types/index.ts +0 -61
  48. package/src/components/folder/config.ts +0 -147
  49. package/src/components/folder/folderIcon.ts +0 -28
  50. package/src/components/folder/index.css +0 -314
  51. package/src/components/folder/index.ts +0 -1050
  52. package/src/components/folder/types/index.ts +0 -101
  53. package/src/components/iframe/config.ts +0 -60
  54. package/src/components/iframe/index.css +0 -75
  55. package/src/components/iframe/index.ts +0 -351
  56. package/src/components/iframe/types/index.ts +0 -146
  57. package/src/components/loading/config.ts +0 -29
  58. package/src/components/loading/index.css +0 -66
  59. package/src/components/loading/index.ts +0 -114
  60. package/src/components/loading/types/index.ts +0 -40
  61. package/src/components/panel/config.ts +0 -532
  62. package/src/components/panel/handlerComponents.ts +0 -3277
  63. package/src/components/panel/index.css +0 -1293
  64. package/src/components/panel/index.ts +0 -213
  65. package/src/components/panel/types/components-button.ts +0 -69
  66. package/src/components/panel/types/components-common.ts +0 -55
  67. package/src/components/panel/types/components-deepMenu.ts +0 -85
  68. package/src/components/panel/types/components-forms.ts +0 -45
  69. package/src/components/panel/types/components-input.ts +0 -82
  70. package/src/components/panel/types/components-own.ts +0 -31
  71. package/src/components/panel/types/components-select.ts +0 -101
  72. package/src/components/panel/types/components-selectMultiple.ts +0 -133
  73. package/src/components/panel/types/components-slider.ts +0 -78
  74. package/src/components/panel/types/components-switch.ts +0 -57
  75. package/src/components/panel/types/components-textarea.ts +0 -69
  76. package/src/components/panel/types/index.ts +0 -177
  77. package/src/components/prompt/config.ts +0 -94
  78. package/src/components/prompt/index.css +0 -34
  79. package/src/components/prompt/index.ts +0 -222
  80. package/src/components/prompt/types/index.ts +0 -55
  81. package/src/components/rightClickMenu/config.ts +0 -130
  82. package/src/components/rightClickMenu/index.css +0 -88
  83. package/src/components/rightClickMenu/index.ts +0 -689
  84. package/src/components/rightClickMenu/types/index.ts +0 -91
  85. package/src/components/searchSuggestion/config.ts +0 -59
  86. package/src/components/searchSuggestion/index.ts +0 -708
  87. package/src/components/searchSuggestion/types/index.ts +0 -147
  88. package/src/components/tooltip/config.ts +0 -34
  89. package/src/components/tooltip/index.css +0 -196
  90. package/src/components/tooltip/index.ts +0 -655
  91. package/src/components/tooltip/types/index.ts +0 -125
  92. package/src/config/CommonCSSClassName.ts +0 -17
  93. package/src/config/GlobalConfig.ts +0 -80
  94. package/src/css/animation.css +0 -2245
  95. package/src/css/button.css +0 -542
  96. package/src/css/common.css +0 -52
  97. package/src/css/index.css +0 -254
  98. package/src/css/ninePalaceGridPosition.css +0 -50
  99. package/src/css/scrollbar.css +0 -22
  100. package/src/handler/PopsElementHandler.ts +0 -325
  101. package/src/handler/PopsHandler.ts +0 -719
  102. package/src/svg/arrowLeft.svg +0 -4
  103. package/src/svg/arrowRight.svg +0 -4
  104. package/src/svg/chromeFilled.svg +0 -14
  105. package/src/svg/circleClose.svg +0 -8
  106. package/src/svg/close.svg +0 -5
  107. package/src/svg/cpu.svg +0 -8
  108. package/src/svg/delete.svg +0 -5
  109. package/src/svg/documentCopy.svg +0 -5
  110. package/src/svg/edit.svg +0 -8
  111. package/src/svg/eleme.svg +0 -5
  112. package/src/svg/elemePlus.svg +0 -5
  113. package/src/svg/headset.svg +0 -5
  114. package/src/svg/hide.svg +0 -8
  115. package/src/svg/keyboard.svg +0 -8
  116. package/src/svg/loading.svg +0 -5
  117. package/src/svg/max.svg +0 -5
  118. package/src/svg/min.svg +0 -5
  119. package/src/svg/mise.svg +0 -5
  120. package/src/svg/monitor.svg +0 -5
  121. package/src/svg/next.svg +0 -5
  122. package/src/svg/picture.svg +0 -8
  123. package/src/svg/prev.svg +0 -5
  124. package/src/svg/search.svg +0 -5
  125. package/src/svg/share.svg +0 -5
  126. package/src/svg/upload.svg +0 -5
  127. package/src/svg/videoPause.svg +0 -5
  128. package/src/svg/videoPlay.svg +0 -5
  129. package/src/svg/view.svg +0 -5
  130. package/src/types/PopsDOMUtilsEventType.d.ts +0 -259
  131. package/src/types/animation.d.ts +0 -19
  132. package/src/types/button.d.ts +0 -196
  133. package/src/types/components.d.ts +0 -229
  134. package/src/types/event.d.ts +0 -63
  135. package/src/types/global.d.ts +0 -20
  136. package/src/types/icon.d.ts +0 -32
  137. package/src/types/inst.d.ts +0 -24
  138. package/src/types/main.d.ts +0 -122
  139. package/src/types/mask.d.ts +0 -49
  140. package/src/types/position.d.ts +0 -60
  141. package/src/utils/PopsDOMUtils.ts +0 -2649
  142. package/src/utils/PopsDOMUtilsEventsConfig.ts +0 -6
  143. package/src/utils/PopsInstanceUtils.ts +0 -801
  144. package/src/utils/PopsMathUtils.ts +0 -77
  145. package/src/utils/PopsSafeUtils.ts +0 -24
  146. package/src/utils/PopsUtils.ts +0 -430
@@ -1,708 +0,0 @@
1
- import { PopsHandler } from "../../handler/PopsHandler";
2
- import { popsDOMUtils } from "../../utils/PopsDOMUtils";
3
- import { popsUtils } from "../../utils/PopsUtils";
4
- import { searchSuggestionConfig as PopsSearchSuggestionConfig } from "./config";
5
- import { GlobalConfig } from "../../config/GlobalConfig";
6
- import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
7
- import type { PopsSearchSuggestionDetails } from "./types/index";
8
- import { PopsCSS } from "../../PopsCSS";
9
- import type { PopsType } from "../../types/main";
10
- import { PopsCommonCSSClassName } from "../../config/CommonCSSClassName";
11
-
12
- export const PopsSearchSuggestion = {
13
- init(details: PopsSearchSuggestionDetails) {
14
- const guid = popsUtils.getRandomGUID();
15
- // 设置当前类型
16
- const popsType: PopsType = "searchSuggestion";
17
-
18
- let config = PopsSearchSuggestionConfig();
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
- config.data = details.data;
30
- }
31
-
32
- const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
33
- PopsHandler.handleInit($shadowRoot, [
34
- {
35
- name: "index",
36
- css: PopsCSS.index,
37
- },
38
- {
39
- name: "anim",
40
- css: PopsCSS.anim,
41
- },
42
- {
43
- name: "common",
44
- css: PopsCSS.common,
45
- },
46
- ]);
47
-
48
- if (config.style != null) {
49
- let cssNode = document.createElement("style");
50
- popsDOMUtils.createElement(
51
- "style",
52
- {
53
- innerHTML: config.style,
54
- },
55
- {
56
- type: "text/css",
57
- }
58
- );
59
- $shadowRoot.appendChild(cssNode);
60
- }
61
-
62
- const SearchSuggestion = {
63
- /**
64
- * 当前的环境,可以是document,可以是shadowroot,默认是document
65
- */
66
- selfDocument: config.selfDocument,
67
- $el: {
68
- /** 根元素 */
69
- root: null as any as HTMLElement,
70
- /** ul元素 */
71
- $hintULContainer: null as any as HTMLUListElement,
72
- /** 动态更新CSS */
73
- $dynamicCSS: null as any as HTMLStyleElement,
74
- },
75
- $data: {
76
- /** 是否结果为空 */
77
- isEmpty: true,
78
- },
79
- /**
80
- * 初始化
81
- */
82
- init(parentElement = document.body || document.documentElement) {
83
- this.initEl();
84
- SearchSuggestion.update(
85
- typeof config.data === "function" ? config.data() : config.data
86
- );
87
- SearchSuggestion.updateDynamicCSS();
88
- SearchSuggestion.changeHintULElementWidth();
89
- SearchSuggestion.changeHintULElementPosition();
90
-
91
- SearchSuggestion.hide();
92
- if (config.isAnimation) {
93
- SearchSuggestion.$el.root.classList.add(`pops-${popsType}-animation`);
94
- }
95
- $shadowRoot.appendChild(SearchSuggestion.$el.root);
96
- parentElement.appendChild($shadowContainer);
97
- },
98
- /** 初始化元素变量 */
99
- initEl() {
100
- this.$el.root = SearchSuggestion.getSearchSelectElement();
101
- this.$el.$dynamicCSS = this.$el.root.querySelector<HTMLStyleElement>(
102
- "style[data-dynamic]"
103
- )!;
104
- this.$el.$hintULContainer =
105
- SearchSuggestion.$el.root.querySelector<HTMLUListElement>("ul")!;
106
- },
107
- /**
108
- * 获取显示出搜索建议框的html
109
- */
110
- getSearchSelectElement() {
111
- let element = popsDOMUtils.createElement(
112
- "div",
113
- {
114
- className: `pops pops-${popsType}-search-suggestion`,
115
- innerHTML: /*html*/ `
116
- <style data-dynamic="true">
117
- ${this.getDynamicCSS()}
118
- </style>
119
- <ul class="pops-${popsType}-search-suggestion-hint">${
120
- config.toSearhNotResultHTML
121
- }</ul>
122
- `,
123
- },
124
- {
125
- "data-guid": guid,
126
- "type-value": popsType,
127
- }
128
- );
129
- if (config.className !== "" && config.className != null) {
130
- popsDOMUtils.addClassName(element, config.className);
131
- }
132
- return element;
133
- },
134
- /** 动态获取CSS */
135
- getDynamicCSS() {
136
- return /*css*/ `
137
- .pops-${popsType}-animation{
138
- -moz-animation: searchSelectFalIn 0.5s 1 linear;
139
- -webkit-animation: searchSelectFalIn 0.5s 1 linear;
140
- -o-animation: searchSelectFalIn 0.5s 1 linear;
141
- -ms-animation: searchSelectFalIn 0.5s 1 linear;
142
- }
143
- .pops-${popsType}-search-suggestion{
144
- --search-suggestion-bg-color: #ffffff;
145
- --search-suggestion-box-shadow-color: rgb(0 0 0 / 20%);
146
- --search-suggestion-item-color: #515a6e;
147
- --search-suggestion-item-none-color: #8e8e8e;
148
- --search-suggestion-item-hover-bg-color: rgba(0, 0, 0, .1);
149
- }
150
- .pops-${popsType}-search-suggestion{
151
- border: initial;
152
- overflow: initial;
153
- }
154
- ul.pops-${popsType}-search-suggestion-hint{
155
- position: ${config.isAbsolute ? "absolute" : "fixed"};
156
- z-index: ${PopsHandler.handleZIndex(config.zIndex)};
157
- width: 0;
158
- left: 0;
159
- max-height: ${config.maxHeight};
160
- overflow-x: hidden;
161
- overflow-y: auto;
162
- padding: 5px 0;
163
- background-color: var(--search-suggestion-bg-color);
164
- box-sizing: border-box;
165
- border-radius: 4px;
166
- box-shadow: 0 1px 6px var(--search-suggestion-box-shadow-color);
167
- }
168
- /* 建议框在上面时 */
169
- ul.pops-${popsType}-search-suggestion-hint[data-top-reverse]{
170
- display: flex;
171
- flex-direction: column-reverse;
172
- }
173
- ul.pops-${popsType}-search-suggestion-hint[data-top-reverse] li{
174
- flex-shrink: 0;
175
- }
176
- ul.pops-${popsType}-search-suggestion-hint li{
177
- padding: 7px;
178
- margin: 0;
179
- clear: both;
180
- color: var(--search-suggestion-item-color);
181
- font-size: 14px;
182
- list-style: none;
183
- cursor: pointer;
184
- transition: background .2s ease-in-out;
185
- overflow: hidden;
186
- text-overflow: ellipsis;
187
- width: 100%;
188
- }
189
- ul.pops-${popsType}-search-suggestion-hint li[data-none]{
190
- text-align: center;
191
- font-size: 12px;
192
- color: var(--search-suggestion-item-none-color);
193
- }
194
- ul.pops-${popsType}-search-suggestion-hint li:hover{
195
- background-color: var(--search-suggestion-item-hover-bg-color);
196
- }
197
-
198
- @media (prefers-color-scheme: dark){
199
- .pops-${popsType}-search-suggestion{
200
- --search-suggestion-bg-color: #1d1e1f;
201
- --search-suggestion-item-color: #cfd3d4;
202
- --search-suggestion-item-hover-bg-color: rgba(175, 175, 175, .1);
203
- }
204
- }
205
- `;
206
- },
207
- /**
208
- * 获取显示出搜索建议框的每一项的html
209
- * @param data 当前项的值
210
- * @param index 当前项的下标
211
- */
212
- getSearchItemLiElement(data: any, index: number) {
213
- let $li = popsDOMUtils.createElement("li", {
214
- className: `pops-${popsType}-search-suggestion-hint-item`,
215
- "data-index": index,
216
- "data-value": SearchSuggestion.getItemDataValue(data),
217
- innerHTML: `${config.getItemHTML(data)}${
218
- config.deleteIcon.enable ? SearchSuggestion.getDeleteIconHTML() : ""
219
- }`,
220
- });
221
- popsDOMUtils.addClassName($li, PopsCommonCSSClassName.flexCenter);
222
- popsDOMUtils.addClassName($li, PopsCommonCSSClassName.flexYCenter);
223
- return $li;
224
- },
225
- /**
226
- * 获取data-value值
227
- * @param data
228
- */
229
- getItemDataValue(data: any) {
230
- return data;
231
- },
232
- /**
233
- * 设置搜索建议框每一项的点击事件
234
- * @param liElement
235
- */
236
- setSearchItemClickEvent(liElement: HTMLLIElement) {
237
- popsDOMUtils.on(
238
- liElement,
239
- "click",
240
- void 0,
241
- (event) => {
242
- popsDOMUtils.preventEvent(event);
243
- let $click = event.target as HTMLLIElement;
244
- if ($click.closest(`.pops-${popsType}-delete-icon`)) {
245
- /* 点击的是删除按钮 */
246
- if (typeof config.deleteIcon.callback === "function") {
247
- config.deleteIcon.callback(
248
- event,
249
- liElement,
250
- (liElement as any)["data-value"]
251
- );
252
- }
253
- if (!this.$el.$hintULContainer.children.length) {
254
- /* 全删完了 */
255
- this.clear();
256
- }
257
- } else {
258
- /* 点击项主体 */
259
- config.itemClickCallBack(
260
- event,
261
- liElement,
262
- (liElement as any)["data-value"]
263
- );
264
- }
265
- },
266
- {
267
- capture: true,
268
- }
269
- );
270
- },
271
- /**
272
- * 设置搜索建议框每一项的选中事件
273
- * @param liElement
274
- */
275
- setSearchItemSelectEvent(liElement: HTMLLIElement) {
276
- // popsDOMUtils.on(
277
- // liElement,
278
- // "keyup",
279
- // void 0,
280
- // (event) => {
281
- // let value = liElement["data-value"];
282
- // config.selectCallBack(event, liElement, value);
283
- // },
284
- // {
285
- // capture: true,
286
- // }
287
- // );
288
- },
289
- /**
290
- * 监听输入框内容改变
291
- */
292
- setInputChangeEvent(
293
- option: AddEventListenerOptions = {
294
- capture: true,
295
- }
296
- ) {
297
- /* 必须是input或者textarea才有input事件 */
298
- if (
299
- !(
300
- config.inputTarget instanceof HTMLInputElement ||
301
- config.inputTarget instanceof HTMLTextAreaElement
302
- )
303
- ) {
304
- return;
305
- }
306
- /* 是input输入框 */
307
- /* 禁用输入框自动提示 */
308
- config.inputTarget.setAttribute("autocomplete", "off");
309
- /* 内容改变事件 */
310
- popsDOMUtils.on(
311
- config.inputTarget,
312
- "input",
313
- void 0,
314
- async (event) => {
315
- let getListResult = await config.getData(
316
- (event.target as any).value
317
- );
318
- SearchSuggestion.update(getListResult);
319
- },
320
- option
321
- );
322
- },
323
- /**
324
- * 移除输入框内容改变的监听
325
- */
326
- removeInputChangeEvent(
327
- option: AddEventListenerOptions = {
328
- capture: true,
329
- }
330
- ) {
331
- popsDOMUtils.off(config.inputTarget, "input", void 0, void 0, option);
332
- },
333
- /**
334
- * 显示搜索建议框的事件
335
- */
336
- showEvent() {
337
- SearchSuggestion.updateDynamicCSS();
338
- SearchSuggestion.changeHintULElementWidth();
339
- SearchSuggestion.changeHintULElementPosition();
340
- if (config.toHideWithNotResult) {
341
- if (SearchSuggestion.$data.isEmpty) {
342
- SearchSuggestion.hide();
343
- } else {
344
- SearchSuggestion.show();
345
- }
346
- } else {
347
- SearchSuggestion.show();
348
- }
349
- },
350
- /**
351
- * 设置显示搜索建议框的事件
352
- */
353
- setShowEvent(
354
- option: AddEventListenerOptions = {
355
- capture: true,
356
- }
357
- ) {
358
- /* 焦点|点击事件*/
359
- if (config.followPosition === "target") {
360
- popsDOMUtils.on(
361
- [config.target],
362
- ["focus", "click"],
363
- void 0,
364
- SearchSuggestion.showEvent,
365
- option
366
- );
367
- } else if (config.followPosition === "input") {
368
- popsDOMUtils.on(
369
- [config.inputTarget],
370
- ["focus", "click"],
371
- void 0,
372
- SearchSuggestion.showEvent,
373
- option
374
- );
375
- } else if (config.followPosition === "inputCursor") {
376
- popsDOMUtils.on(
377
- [config.inputTarget],
378
- ["focus", "click", "input"],
379
- void 0,
380
- SearchSuggestion.showEvent,
381
- option
382
- );
383
- } else {
384
- throw new Error("未知followPosition:" + config.followPosition);
385
- }
386
- },
387
- /**
388
- * 移除显示搜索建议框的事件
389
- */
390
- removeShowEvent(
391
- option: AddEventListenerOptions = {
392
- capture: true,
393
- }
394
- ) {
395
- /* 焦点|点击事件*/
396
- popsDOMUtils.off(
397
- [config.target, config.inputTarget],
398
- ["focus", "click"],
399
- void 0,
400
- SearchSuggestion.showEvent,
401
- option
402
- );
403
- /* 内容改变事件 */
404
- popsDOMUtils.off(
405
- [config.inputTarget],
406
- ["input"],
407
- void 0,
408
- SearchSuggestion.showEvent,
409
- option
410
- );
411
- },
412
- /**
413
- * 隐藏搜索建议框的事件
414
- * @param event
415
- */
416
- hideEvent(event: PointerEvent | MouseEvent) {
417
- if (event.target instanceof Node) {
418
- if ($shadowContainer.contains(event.target)) {
419
- /* 点击在shadow上的 */
420
- return;
421
- }
422
- if (config.target.contains(event.target)) {
423
- /* 点击在目标元素内 */
424
- return;
425
- }
426
- if (config.inputTarget.contains(event.target)) {
427
- /* 点击在目标input内 */
428
- return;
429
- }
430
- SearchSuggestion.hide();
431
- }
432
- },
433
- /**
434
- * 设置隐藏搜索建议框的事件
435
- */
436
- setHideEvent(
437
- option: AddEventListenerOptions = {
438
- capture: true,
439
- }
440
- ) {
441
- /* 全局点击事件 */
442
- /* 全局触摸屏点击事件 */
443
- if (Array.isArray(SearchSuggestion.selfDocument)) {
444
- SearchSuggestion.selfDocument.forEach(($checkParent) => {
445
- popsDOMUtils.on(
446
- $checkParent,
447
- ["click", "touchstart"],
448
- void 0,
449
- SearchSuggestion.hideEvent,
450
- option
451
- );
452
- });
453
- } else {
454
- popsDOMUtils.on(
455
- SearchSuggestion.selfDocument,
456
- ["click", "touchstart"],
457
- void 0,
458
- SearchSuggestion.hideEvent,
459
- option
460
- );
461
- }
462
- },
463
- /**
464
- * 移除隐藏搜索建议框的事件
465
- */
466
- removeHideEvent(
467
- option: AddEventListenerOptions = {
468
- capture: true,
469
- }
470
- ) {
471
- if (Array.isArray(SearchSuggestion.selfDocument)) {
472
- SearchSuggestion.selfDocument.forEach(($checkParent) => {
473
- popsDOMUtils.off(
474
- $checkParent,
475
- ["click", "touchstart"],
476
- void 0,
477
- SearchSuggestion.hideEvent,
478
- option
479
- );
480
- });
481
- } else {
482
- popsDOMUtils.off(
483
- SearchSuggestion.selfDocument,
484
- ["click", "touchstart"],
485
- void 0,
486
- SearchSuggestion.hideEvent,
487
- option
488
- );
489
- }
490
- },
491
- /**
492
- * 设置所有监听
493
- */
494
- setAllEvent(
495
- option: AddEventListenerOptions = {
496
- capture: true,
497
- }
498
- ) {
499
- SearchSuggestion.setInputChangeEvent(option);
500
- SearchSuggestion.setHideEvent(option);
501
- SearchSuggestion.setShowEvent(option);
502
- },
503
- /**
504
- * 移除所有监听
505
- */
506
- removeAllEvent(
507
- option: AddEventListenerOptions = {
508
- capture: true,
509
- }
510
- ) {
511
- SearchSuggestion.removeInputChangeEvent(option);
512
- SearchSuggestion.removeHideEvent(option);
513
- SearchSuggestion.removeShowEvent(option);
514
- },
515
- /**
516
- * 获取删除按钮的html
517
- */
518
- getDeleteIconHTML(size = 16, fill = "#bababa") {
519
- return /*html*/ `
520
- <svg class="pops-${popsType}-delete-icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" fill="${fill}">
521
- <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>
522
- <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>
523
- </svg>
524
- `;
525
- },
526
- /**
527
- * 设置当前正在搜索中的提示
528
- */
529
- setPromptsInSearch() {
530
- let isSearchingElement = popsDOMUtils.createElement("li", {
531
- className: `pops-${popsType}-search-suggestion-hint-searching-item`,
532
- innerHTML: config.searchingTip,
533
- });
534
- SearchSuggestion.$el.$hintULContainer.appendChild(isSearchingElement);
535
- },
536
- /**
537
- * 移除正在搜索中的提示
538
- */
539
- removePromptsInSearch() {
540
- SearchSuggestion.$el.$hintULContainer
541
- .querySelector<HTMLLIElement>(
542
- `li.pops-${popsType}-search-suggestion-hint-searching-item`
543
- )
544
- ?.remove();
545
- },
546
- /**
547
- * 清空所有的搜索结果
548
- */
549
- clearAllSearchItemLi() {
550
- PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$hintULContainer, "");
551
- },
552
- /**
553
- * 更新搜索建议框的位置(top、left)
554
- * 因为目标元素可能是动态隐藏的
555
- */
556
- changeHintULElementPosition(
557
- target = config.target ?? config.inputTarget
558
- ) {
559
- let targetRect: DOMRect | null = null;
560
- if (config.followPosition === "inputCursor") {
561
- targetRect = popsDOMUtils.getTextBoundingRect(
562
- config.inputTarget,
563
- config.inputTarget.selectionStart || 0,
564
- config.inputTarget.selectionEnd || 0,
565
- false
566
- );
567
- } else {
568
- targetRect = config.isAbsolute
569
- ? popsDOMUtils.offset(target)
570
- : target.getBoundingClientRect();
571
- }
572
- if (targetRect == null) {
573
- return;
574
- }
575
- // 文档最大高度
576
- let documentHeight = document.documentElement.clientHeight;
577
- if (config.isAbsolute) {
578
- // 绝对定位
579
- documentHeight = popsDOMUtils.height(document);
580
- }
581
- // 文档最大宽度
582
- let documentWidth = popsDOMUtils.width(document);
583
-
584
- let position = config.position;
585
- if (config.position === "auto") {
586
- // 需目标高度+搜索建议框高度大于文档高度,则显示在上面
587
- let targetBottom = targetRect.bottom;
588
- let searchSuggestionContainerHeight = popsDOMUtils.height(
589
- SearchSuggestion.$el.$hintULContainer
590
- );
591
- if (targetBottom + searchSuggestionContainerHeight > documentHeight) {
592
- // 在上面
593
- position = "top";
594
- } else {
595
- // 在下面
596
- position = "bottom";
597
- SearchSuggestion.$el.$hintULContainer.removeAttribute("data-top");
598
- }
599
- }
600
- if (position === "top") {
601
- if (config.positionTopToReverse) {
602
- SearchSuggestion.$el.$hintULContainer.setAttribute(
603
- "data-top-reverse",
604
- "true"
605
- );
606
- }
607
- // 在上面
608
- SearchSuggestion.$el.$hintULContainer.style.top = "";
609
- SearchSuggestion.$el.$hintULContainer.style.bottom =
610
- documentHeight - targetRect.top + config.topDistance + "px";
611
- } else if (position === "bottom") {
612
- // 在下面
613
- SearchSuggestion.$el.$hintULContainer.removeAttribute(
614
- "data-top-reverse"
615
- );
616
- SearchSuggestion.$el.$hintULContainer.style.bottom = "";
617
- SearchSuggestion.$el.$hintULContainer.style.top =
618
- targetRect.height + targetRect.top + config.topDistance + "px";
619
- }
620
- let hintUIWidth = popsDOMUtils.width(
621
- SearchSuggestion.$el.$hintULContainer
622
- );
623
- SearchSuggestion.$el.$hintULContainer.style.left =
624
- (targetRect.left + hintUIWidth > documentWidth
625
- ? documentWidth - hintUIWidth
626
- : targetRect.left) + "px";
627
- },
628
- /**
629
- * 更新搜索建议框的width
630
- * 因为目标元素可能是动态隐藏的
631
- */
632
- changeHintULElementWidth(target = config.target ?? config.inputTarget) {
633
- let targetRect = target.getBoundingClientRect();
634
- if (config.followTargetWidth) {
635
- SearchSuggestion.$el.$hintULContainer.style.width =
636
- targetRect.width + "px";
637
- } else {
638
- SearchSuggestion.$el.$hintULContainer.style.width = config.width;
639
- }
640
- },
641
- /**
642
- * 动态更新CSS
643
- */
644
- updateDynamicCSS() {
645
- let cssText = this.getDynamicCSS();
646
- PopsSafeUtils.setSafeHTML(this.$el.$dynamicCSS, cssText);
647
- },
648
- /**
649
- * 更新页面显示的搜索结果
650
- * @param data
651
- */
652
- update(data: any[] = []) {
653
- if (!Array.isArray(data)) {
654
- throw new TypeError("传入的数据不是数组");
655
- }
656
- config.data = data;
657
- /* 清空已有的搜索结果 */
658
- if (config.data.length) {
659
- SearchSuggestion.$data.isEmpty = false;
660
-
661
- if (config.toHideWithNotResult) {
662
- SearchSuggestion.show();
663
- }
664
- SearchSuggestion.clearAllSearchItemLi();
665
- /* 添加进ul中 */
666
- config.data.forEach((item, index) => {
667
- let itemElement = SearchSuggestion.getSearchItemLiElement(
668
- item,
669
- index
670
- );
671
- SearchSuggestion.setSearchItemClickEvent(itemElement);
672
- SearchSuggestion.setSearchItemSelectEvent(itemElement);
673
- SearchSuggestion.$el.$hintULContainer.appendChild(itemElement);
674
- });
675
- } else {
676
- /* 清空 */
677
- SearchSuggestion.clear();
678
- }
679
- },
680
- /**
681
- * 清空当前的搜索结果并显示无结果
682
- */
683
- clear() {
684
- this.$data.isEmpty = true;
685
- this.clearAllSearchItemLi();
686
- this.$el.$hintULContainer.appendChild(
687
- popsDOMUtils.parseTextToDOM(config.toSearhNotResultHTML)
688
- );
689
- if (config.toHideWithNotResult) {
690
- this.hide();
691
- }
692
- },
693
- /**
694
- * 隐藏搜索建议框
695
- */
696
- hide() {
697
- this.$el.root.style.display = "none";
698
- },
699
- /**
700
- * 显示搜索建议框
701
- */
702
- show() {
703
- this.$el.root.style.display = "";
704
- },
705
- };
706
- return SearchSuggestion;
707
- },
708
- };