@whitesev/pops 2.6.1 → 3.0.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.
- package/dist/index.amd.js +2513 -1534
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +2513 -1534
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +2513 -1534
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +2513 -1534
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +2513 -1534
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +2513 -1534
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/eslint.config.d.mts +2 -0
- package/dist/types/src/Pops.d.ts +449 -103
- package/dist/types/src/PopsCSS.d.ts +3 -1
- package/dist/types/src/PopsIcon.d.ts +1 -1
- package/dist/types/src/PopsInst.d.ts +2 -2
- package/dist/types/src/components/alert/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/alert/index.d.ts +2 -2
- package/dist/types/src/components/alert/types/index.d.ts +4 -4
- package/dist/types/src/components/confirm/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/confirm/index.d.ts +2 -2
- package/dist/types/src/components/confirm/types/index.d.ts +2 -2
- package/dist/types/src/components/drawer/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/drawer/index.d.ts +2 -2
- package/dist/types/src/components/drawer/types/index.d.ts +2 -2
- package/dist/types/src/components/folder/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/folder/index.d.ts +2 -2
- package/dist/types/src/components/folder/types/index.d.ts +31 -7
- package/dist/types/src/components/iframe/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/iframe/index.d.ts +2 -5
- package/dist/types/src/components/iframe/types/index.d.ts +13 -42
- package/dist/types/src/components/loading/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/loading/index.d.ts +2 -2
- package/dist/types/src/components/loading/types/index.d.ts +4 -4
- package/dist/types/src/components/panel/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/panel/handlerComponents.d.ts +988 -49
- package/dist/types/src/components/panel/index.d.ts +2 -2
- package/dist/types/src/components/panel/types/components-button.d.ts +7 -6
- package/dist/types/src/components/panel/types/components-common.d.ts +7 -7
- package/dist/types/src/components/panel/types/components-container.d.ts +24 -0
- package/dist/types/src/components/panel/types/components-deepMenu.d.ts +14 -14
- package/dist/types/src/components/panel/types/components-input.d.ts +46 -21
- package/dist/types/src/components/panel/types/components-own.d.ts +5 -5
- package/dist/types/src/components/panel/types/components-select.d.ts +95 -36
- package/dist/types/src/components/panel/types/components-selectMultiple.d.ts +15 -20
- package/dist/types/src/components/panel/types/components-slider.d.ts +7 -8
- package/dist/types/src/components/panel/types/components-switch.d.ts +6 -6
- package/dist/types/src/components/panel/types/components-textarea.d.ts +6 -6
- package/dist/types/src/components/panel/types/index.d.ts +36 -28
- package/dist/types/src/components/prompt/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/prompt/index.d.ts +2 -2
- package/dist/types/src/components/prompt/types/index.d.ts +4 -3
- package/dist/types/src/components/rightClickMenu/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/rightClickMenu/index.d.ts +29 -27
- package/dist/types/src/components/rightClickMenu/types/index.d.ts +32 -11
- package/dist/types/src/components/searchSuggestion/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/searchSuggestion/index.d.ts +24 -9
- package/dist/types/src/components/searchSuggestion/types/index.d.ts +15 -13
- package/dist/types/src/components/tooltip/defaultConfig.d.ts +2 -0
- package/dist/types/src/components/tooltip/index.d.ts +6 -21
- package/dist/types/src/components/tooltip/types/index.d.ts +8 -6
- package/dist/types/src/config/GlobalConfig.d.ts +3 -3
- package/dist/types/src/handler/PopsElementHandler.d.ts +6 -6
- package/dist/types/src/handler/PopsHandler.d.ts +18 -18
- package/dist/types/src/types/button.d.ts +4 -97
- package/dist/types/src/types/components.d.ts +8 -8
- package/dist/types/src/types/event.d.ts +0 -30
- package/dist/types/src/types/global.d.ts +4 -0
- package/dist/types/src/types/inst.d.ts +5 -5
- package/dist/types/src/types/main.d.ts +35 -80
- package/dist/types/src/types/mask.d.ts +18 -15
- package/dist/types/src/utils/PopsInstanceUtils.d.ts +15 -15
- package/dist/types/src/utils/PopsUtils.d.ts +4 -0
- package/package.json +12 -12
- package/src/Pops.ts +44 -44
- package/src/PopsAnimation.ts +1 -1
- package/src/PopsCSS.ts +4 -1
- package/src/PopsInst.ts +2 -2
- package/src/components/alert/{config.ts → defaultConfig.ts} +7 -7
- package/src/components/alert/index.ts +16 -18
- package/src/components/alert/types/index.ts +4 -4
- package/src/components/confirm/{config.ts → defaultConfig.ts} +11 -11
- package/src/components/confirm/index.ts +11 -13
- package/src/components/confirm/types/index.ts +3 -3
- package/src/components/drawer/{config.ts → defaultConfig.ts} +10 -10
- package/src/components/drawer/index.ts +18 -17
- package/src/components/drawer/types/index.ts +3 -3
- package/src/components/folder/{config.ts → defaultConfig.ts} +22 -18
- package/src/components/folder/index.ts +61 -60
- package/src/components/folder/types/index.ts +31 -18
- package/src/components/iframe/{config.ts → defaultConfig.ts} +2 -2
- package/src/components/iframe/index.ts +24 -29
- package/src/components/iframe/types/index.ts +13 -56
- package/src/components/loading/{config.ts → defaultConfig.ts} +3 -3
- package/src/components/loading/index.ts +13 -11
- package/src/components/loading/types/index.ts +5 -5
- package/src/components/panel/css/components-select.css +84 -0
- package/src/components/panel/defaultConfig.ts +818 -0
- package/src/components/panel/handlerComponents.ts +1431 -762
- package/src/components/panel/index.css +90 -6
- package/src/components/panel/index.ts +15 -28
- package/src/components/panel/types/components-button.ts +7 -6
- package/src/components/panel/types/components-common.ts +7 -7
- package/src/components/panel/types/components-container.ts +25 -0
- package/src/components/panel/types/components-deepMenu.ts +14 -14
- package/src/components/panel/types/components-input.ts +56 -21
- package/src/components/panel/types/components-own.ts +5 -5
- package/src/components/panel/types/components-select.ts +100 -38
- package/src/components/panel/types/components-selectMultiple.ts +16 -22
- package/src/components/panel/types/components-slider.ts +7 -8
- package/src/components/panel/types/components-switch.ts +6 -6
- package/src/components/panel/types/components-textarea.ts +6 -6
- package/src/components/panel/types/index.ts +45 -38
- package/src/components/prompt/{config.ts → defaultConfig.ts} +10 -10
- package/src/components/prompt/index.ts +13 -15
- package/src/components/prompt/types/index.ts +4 -3
- package/src/components/rightClickMenu/{config.ts → defaultConfig.ts} +20 -19
- package/src/components/rightClickMenu/index.ts +125 -108
- package/src/components/rightClickMenu/types/index.ts +36 -14
- package/src/components/searchSuggestion/{config.ts → defaultConfig.ts} +18 -11
- package/src/components/searchSuggestion/index.ts +130 -155
- package/src/components/searchSuggestion/types/index.ts +17 -15
- package/src/components/tooltip/{config.ts → defaultConfig.ts} +5 -6
- package/src/components/tooltip/index.ts +21 -21
- package/src/components/tooltip/types/index.ts +9 -7
- package/src/config/GlobalConfig.ts +2 -2
- package/src/handler/PopsElementHandler.ts +29 -30
- package/src/handler/PopsHandler.ts +43 -43
- package/src/types/button.d.ts +4 -97
- package/src/types/components.d.ts +8 -8
- package/src/types/event.d.ts +0 -30
- package/src/types/global.d.ts +4 -0
- package/src/types/inst.d.ts +5 -5
- package/src/types/main.d.ts +35 -80
- package/src/types/mask.d.ts +18 -15
- package/src/utils/PopsDOMUtils.ts +34 -34
- package/src/utils/PopsInstanceUtils.ts +129 -139
- package/src/utils/PopsUtils.ts +60 -45
- package/dist/types/src/components/alert/config.d.ts +0 -2
- package/dist/types/src/components/confirm/config.d.ts +0 -2
- package/dist/types/src/components/drawer/config.d.ts +0 -2
- package/dist/types/src/components/folder/config.d.ts +0 -2
- package/dist/types/src/components/iframe/config.d.ts +0 -2
- package/dist/types/src/components/loading/config.d.ts +0 -2
- package/dist/types/src/components/panel/config.d.ts +0 -2
- package/dist/types/src/components/panel/types/components-forms.d.ts +0 -23
- package/dist/types/src/components/prompt/config.d.ts +0 -2
- package/dist/types/src/components/rightClickMenu/config.d.ts +0 -2
- package/dist/types/src/components/searchSuggestion/config.d.ts +0 -2
- package/dist/types/src/components/tooltip/config.d.ts +0 -2
- package/src/components/panel/config.ts +0 -530
- 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 {
|
|
4
|
+
import { PopsSearchSuggestionDefaultConfig } from "./defaultConfig";
|
|
5
5
|
import { GlobalConfig } from "../../config/GlobalConfig";
|
|
6
6
|
import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
|
|
7
|
-
import type { PopsSearchSuggestionData,
|
|
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>(
|
|
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 =
|
|
18
|
+
let config = PopsSearchSuggestionDefaultConfig();
|
|
19
19
|
config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
|
|
20
|
-
config = popsUtils.assign(config,
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
@@ -52,17 +46,31 @@ export const PopsSearchSuggestion = {
|
|
|
52
46
|
});
|
|
53
47
|
$shadowRoot.appendChild($css);
|
|
54
48
|
}
|
|
55
|
-
|
|
49
|
+
/**
|
|
50
|
+
* 监听器的默认配置
|
|
51
|
+
*/
|
|
52
|
+
const defaultListenerOption: AddEventListenerOptions = {
|
|
53
|
+
capture: true,
|
|
54
|
+
passive: true,
|
|
55
|
+
};
|
|
56
56
|
const SearchSuggestion = {
|
|
57
57
|
/**
|
|
58
58
|
* 当前的环境,可以是document,可以是shadowroot,默认是document
|
|
59
59
|
*/
|
|
60
|
-
selfDocument: config
|
|
60
|
+
selfDocument: config.$selfDocument,
|
|
61
61
|
$el: {
|
|
62
62
|
/** 根元素 */
|
|
63
63
|
root: null as any as HTMLElement,
|
|
64
|
+
/**
|
|
65
|
+
* 包裹ul的容器元素
|
|
66
|
+
*/
|
|
67
|
+
$dropdownWrapper: null as any as HTMLElement,
|
|
64
68
|
/** ul元素 */
|
|
65
|
-
$
|
|
69
|
+
$dropdownContainer: null as any as HTMLUListElement,
|
|
70
|
+
/**
|
|
71
|
+
* 箭头元素
|
|
72
|
+
*/
|
|
73
|
+
$arrow: null as any as HTMLDivElement,
|
|
66
74
|
/** 动态更新CSS */
|
|
67
75
|
$dynamicCSS: null as any as HTMLStyleElement,
|
|
68
76
|
},
|
|
@@ -72,29 +80,44 @@ export const PopsSearchSuggestion = {
|
|
|
72
80
|
$data: {
|
|
73
81
|
/** 是否结果为空 */
|
|
74
82
|
isEmpty: true,
|
|
83
|
+
/**
|
|
84
|
+
* 存储在元素上的操作的键名
|
|
85
|
+
*/
|
|
86
|
+
storeNodeHandlerKey: "data-SearchSuggestion",
|
|
75
87
|
},
|
|
76
88
|
/**
|
|
77
89
|
* 初始化
|
|
78
|
-
* @param
|
|
90
|
+
* @param $parent 父元素
|
|
91
|
+
* @example
|
|
92
|
+
* .init();
|
|
93
|
+
* .setAllEvent();
|
|
79
94
|
*/
|
|
80
|
-
init(
|
|
95
|
+
init($parent = document.body || document.documentElement) {
|
|
81
96
|
SearchSuggestion.initEl();
|
|
82
97
|
SearchSuggestion.update(SearchSuggestion.getData());
|
|
83
98
|
SearchSuggestion.updateStyleSheet();
|
|
84
99
|
|
|
85
100
|
SearchSuggestion.hide();
|
|
86
101
|
$shadowRoot.appendChild(SearchSuggestion.$el.root);
|
|
87
|
-
|
|
102
|
+
$parent.appendChild($shadowContainer);
|
|
88
103
|
},
|
|
89
104
|
/**
|
|
90
105
|
* 初始化元素变量
|
|
91
106
|
*/
|
|
92
107
|
initEl() {
|
|
93
108
|
SearchSuggestion.$el.root = SearchSuggestion.createSearchSelectElement();
|
|
94
|
-
Reflect.set(SearchSuggestion.$el.root,
|
|
109
|
+
Reflect.set(SearchSuggestion.$el.root, this.$data.storeNodeHandlerKey, SearchSuggestion);
|
|
95
110
|
SearchSuggestion.$el.$dynamicCSS =
|
|
96
111
|
SearchSuggestion.$el.root.querySelector<HTMLStyleElement>("style[data-dynamic]")!;
|
|
97
|
-
SearchSuggestion.$el.$
|
|
112
|
+
SearchSuggestion.$el.$dropdownWrapper = SearchSuggestion.$el.root.querySelector<HTMLElement>(
|
|
113
|
+
`.pops-${popsType}-search-suggestion-dropdown-wrapper`
|
|
114
|
+
)!;
|
|
115
|
+
SearchSuggestion.$el.$dropdownContainer = SearchSuggestion.$el.root.querySelector<HTMLUListElement>(
|
|
116
|
+
`ul.pops-${popsType}-search-suggestion-dropdown-container`
|
|
117
|
+
)!;
|
|
118
|
+
SearchSuggestion.$el.$arrow = SearchSuggestion.$el.root.querySelector<HTMLDivElement>(
|
|
119
|
+
`.pops-${popsType}-search-suggestion-arrow`
|
|
120
|
+
)!;
|
|
98
121
|
},
|
|
99
122
|
/**
|
|
100
123
|
* 获取数据
|
|
@@ -107,7 +130,7 @@ export const PopsSearchSuggestion = {
|
|
|
107
130
|
* @param data 数据
|
|
108
131
|
*/
|
|
109
132
|
setData(data: PopsSearchSuggestionData<T>[]) {
|
|
110
|
-
(<
|
|
133
|
+
(<PopsSearchSuggestionConfig<T>["data"]>config.data) = data;
|
|
111
134
|
},
|
|
112
135
|
/**
|
|
113
136
|
* 获取显示出搜索建议框的html
|
|
@@ -217,9 +240,12 @@ export const PopsSearchSuggestion = {
|
|
|
217
240
|
<style type="text/css" data-user-css>
|
|
218
241
|
${config.style || ""}
|
|
219
242
|
</style>
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
243
|
+
<div class="pops-${popsType}-search-suggestion-dropdown-wrapper">
|
|
244
|
+
<ul class="pops-${popsType}-search-suggestion-dropdown-container ${PopsCommonCSSClassName.userSelectNone}">${
|
|
245
|
+
config.toSearhNotResultHTML
|
|
246
|
+
}</ul>
|
|
247
|
+
</div>
|
|
248
|
+
<!-- 箭头 -->
|
|
223
249
|
${config.useArrow ? /*html*/ `<div class="pops-${popsType}-search-suggestion-arrow"></div>` : ""}
|
|
224
250
|
`,
|
|
225
251
|
},
|
|
@@ -258,25 +284,27 @@ export const PopsSearchSuggestion = {
|
|
|
258
284
|
position: ${config.isAbsolute ? "absolute" : "fixed"};
|
|
259
285
|
z-index: ${PopsHandler.handleZIndex(config.zIndex)};
|
|
260
286
|
}
|
|
261
|
-
|
|
287
|
+
.pops-${popsType}-search-suggestion-dropdown-wrapper{
|
|
262
288
|
max-height: ${config.maxHeight};
|
|
289
|
+
border-radius: 4px;
|
|
290
|
+
box-shadow: 0 1px 6px var(--search-suggestion-box-shadow-color);
|
|
291
|
+
background-color: var(--search-suggestion-bg-color);
|
|
292
|
+
padding: 5px 0;
|
|
263
293
|
overflow-x: hidden;
|
|
264
294
|
overflow-y: auto;
|
|
265
|
-
|
|
266
|
-
|
|
295
|
+
}
|
|
296
|
+
.pops-${popsType}-search-suggestion-dropdown-wrapper ul.pops-${popsType}-search-suggestion-dropdown-container{
|
|
267
297
|
box-sizing: border-box;
|
|
268
|
-
border-radius: 4px;
|
|
269
|
-
box-shadow: 0 1px 6px var(--search-suggestion-box-shadow-color);
|
|
270
298
|
}
|
|
271
|
-
|
|
272
|
-
.pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-
|
|
299
|
+
// 建议框在上面时
|
|
300
|
+
.pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-dropdown-container{
|
|
273
301
|
display: flex;
|
|
274
302
|
flex-direction: column-reverse;
|
|
275
303
|
}
|
|
276
|
-
.pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-
|
|
304
|
+
.pops-${popsType}-search-suggestion[data-top-reverse] ul.pops-${popsType}-search-suggestion-dropdown-container li{
|
|
277
305
|
flex-shrink: 0;
|
|
278
306
|
}
|
|
279
|
-
ul.pops-${popsType}-search-suggestion-
|
|
307
|
+
ul.pops-${popsType}-search-suggestion-dropdown-container li{
|
|
280
308
|
padding: 7px;
|
|
281
309
|
margin: 0;
|
|
282
310
|
clear: both;
|
|
@@ -289,12 +317,12 @@ export const PopsSearchSuggestion = {
|
|
|
289
317
|
text-overflow: ellipsis;
|
|
290
318
|
width: 100%;
|
|
291
319
|
}
|
|
292
|
-
ul.pops-${popsType}-search-suggestion-
|
|
320
|
+
ul.pops-${popsType}-search-suggestion-dropdown-container li[data-none]{
|
|
293
321
|
text-align: center;
|
|
294
322
|
font-size: 12px;
|
|
295
323
|
color: var(--search-suggestion-item-none-color);
|
|
296
324
|
}
|
|
297
|
-
ul.pops-${popsType}-search-suggestion-
|
|
325
|
+
ul.pops-${popsType}-search-suggestion-dropdown-container li:not([data-none]):hover{
|
|
298
326
|
background-color: var(--search-suggestion-item-is-hover-bg-color);
|
|
299
327
|
}
|
|
300
328
|
@media (prefers-color-scheme: dark){
|
|
@@ -321,7 +349,7 @@ export const PopsSearchSuggestion = {
|
|
|
321
349
|
createSearchItemLiElement(dataItem: PopsSearchSuggestionData<T>, dateItemIndex: number) {
|
|
322
350
|
const dataValue = SearchSuggestion.getItemDataValue(dataItem);
|
|
323
351
|
const $li = popsDOMUtils.createElement("li", {
|
|
324
|
-
className: `pops-${popsType}-search-suggestion-
|
|
352
|
+
className: `pops-${popsType}-search-suggestion-dropdown-item`,
|
|
325
353
|
"data-index": dateItemIndex,
|
|
326
354
|
"data-value": dataValue,
|
|
327
355
|
});
|
|
@@ -367,8 +395,8 @@ export const PopsSearchSuggestion = {
|
|
|
367
395
|
$searchItem.remove();
|
|
368
396
|
}
|
|
369
397
|
}
|
|
370
|
-
if (!SearchSuggestion.$el.$
|
|
371
|
-
|
|
398
|
+
if (!SearchSuggestion.$el.$dropdownContainer.children.length) {
|
|
399
|
+
// 全删完了
|
|
372
400
|
SearchSuggestion.clear();
|
|
373
401
|
}
|
|
374
402
|
SearchSuggestion.updateStyleSheet();
|
|
@@ -378,10 +406,10 @@ export const PopsSearchSuggestion = {
|
|
|
378
406
|
const result = await dataItem.clickCallback(event, $searchItem, dataItem, config);
|
|
379
407
|
if (typeof result === "boolean" && result) {
|
|
380
408
|
if (
|
|
381
|
-
config
|
|
382
|
-
config
|
|
409
|
+
config.$inputTarget instanceof HTMLInputElement ||
|
|
410
|
+
config.$inputTarget instanceof HTMLTextAreaElement
|
|
383
411
|
) {
|
|
384
|
-
config
|
|
412
|
+
config.$inputTarget.value = String(dataItem.value);
|
|
385
413
|
}
|
|
386
414
|
}
|
|
387
415
|
}
|
|
@@ -394,46 +422,30 @@ export const PopsSearchSuggestion = {
|
|
|
394
422
|
},
|
|
395
423
|
/**
|
|
396
424
|
* 设置搜索建议框每一项的选中事件
|
|
397
|
-
* @param
|
|
425
|
+
* @param $li 每一项元素
|
|
398
426
|
*/
|
|
399
427
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
400
|
-
setSearchItemSelectEvent(
|
|
401
|
-
//
|
|
402
|
-
// liElement,
|
|
403
|
-
// "keyup",
|
|
404
|
-
// void 0,
|
|
405
|
-
// (event) => {
|
|
406
|
-
// let value = liElement["data-value"];
|
|
407
|
-
// config.selectCallBack(event, liElement, value);
|
|
408
|
-
// },
|
|
409
|
-
// {
|
|
410
|
-
// capture: true,
|
|
411
|
-
// }
|
|
412
|
-
// );
|
|
428
|
+
setSearchItemSelectEvent($li: HTMLLIElement) {
|
|
429
|
+
// TODO
|
|
413
430
|
},
|
|
414
431
|
/**
|
|
415
432
|
* 监听输入框内容改变
|
|
416
433
|
*/
|
|
417
|
-
setInputChangeEvent(
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
) {
|
|
422
|
-
/* 必须是input或者textarea才有input事件 */
|
|
423
|
-
if (!(config.inputTarget instanceof HTMLInputElement || config.inputTarget instanceof HTMLTextAreaElement)) {
|
|
434
|
+
setInputChangeEvent(option: AddEventListenerOptions = defaultListenerOption) {
|
|
435
|
+
// 必须是input或者textarea才有input事件
|
|
436
|
+
if (!(config.$inputTarget instanceof HTMLInputElement || config.$inputTarget instanceof HTMLTextAreaElement)) {
|
|
424
437
|
return;
|
|
425
438
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
config
|
|
429
|
-
|
|
439
|
+
// 是input输入框
|
|
440
|
+
// 禁用输入框自动提示
|
|
441
|
+
config.$inputTarget.setAttribute("autocomplete", "off");
|
|
442
|
+
// 内容改变事件
|
|
430
443
|
const listenerHandler = popsDOMUtils.onInput(
|
|
431
|
-
config
|
|
432
|
-
|
|
433
|
-
async (_event) => {
|
|
444
|
+
config.$inputTarget,
|
|
445
|
+
async () => {
|
|
434
446
|
const data = SearchSuggestion.getData();
|
|
435
447
|
const queryDataResult = await config.inputTargetChangeRefreshShowDataCallback(
|
|
436
|
-
config
|
|
448
|
+
config.$inputTarget.value,
|
|
437
449
|
data,
|
|
438
450
|
config
|
|
439
451
|
);
|
|
@@ -447,12 +459,7 @@ export const PopsSearchSuggestion = {
|
|
|
447
459
|
/**
|
|
448
460
|
* 移除输入框内容改变的监听
|
|
449
461
|
*/
|
|
450
|
-
removeInputChangeEvent(
|
|
451
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
452
|
-
option: AddEventListenerOptions = {
|
|
453
|
-
capture: true,
|
|
454
|
-
}
|
|
455
|
-
) {
|
|
462
|
+
removeInputChangeEvent() {
|
|
456
463
|
for (let index = 0; index < SearchSuggestion.$evt.offInputChangeEvtHandler.length; index++) {
|
|
457
464
|
const handler = SearchSuggestion.$evt.offInputChangeEvtHandler[index];
|
|
458
465
|
handler();
|
|
@@ -478,24 +485,14 @@ export const PopsSearchSuggestion = {
|
|
|
478
485
|
/**
|
|
479
486
|
* 设置显示搜索建议框的事件
|
|
480
487
|
*/
|
|
481
|
-
setShowEvent(
|
|
482
|
-
option: AddEventListenerOptions = {
|
|
483
|
-
capture: true,
|
|
484
|
-
}
|
|
485
|
-
) {
|
|
488
|
+
setShowEvent(option: AddEventListenerOptions = defaultListenerOption) {
|
|
486
489
|
/* 焦点|点击事件*/
|
|
487
490
|
if (config.followPosition === "target") {
|
|
488
|
-
popsDOMUtils.on([config
|
|
491
|
+
popsDOMUtils.on([config.$target], ["focus", "click"], void 0, SearchSuggestion.showEvent, option);
|
|
489
492
|
} else if (config.followPosition === "input") {
|
|
490
|
-
popsDOMUtils.on([config
|
|
493
|
+
popsDOMUtils.on([config.$inputTarget], ["focus", "click"], void 0, SearchSuggestion.showEvent, option);
|
|
491
494
|
} else if (config.followPosition === "inputCursor") {
|
|
492
|
-
popsDOMUtils.on(
|
|
493
|
-
[config.inputTarget],
|
|
494
|
-
["focus", "click", "input"],
|
|
495
|
-
void 0,
|
|
496
|
-
SearchSuggestion.showEvent,
|
|
497
|
-
option
|
|
498
|
-
);
|
|
495
|
+
popsDOMUtils.on([config.$inputTarget], ["focus", "click", "input"], SearchSuggestion.showEvent, option);
|
|
499
496
|
} else {
|
|
500
497
|
throw new Error("未知followPosition:" + config.followPosition);
|
|
501
498
|
}
|
|
@@ -503,21 +500,17 @@ export const PopsSearchSuggestion = {
|
|
|
503
500
|
/**
|
|
504
501
|
* 移除显示搜索建议框的事件
|
|
505
502
|
*/
|
|
506
|
-
removeShowEvent(
|
|
507
|
-
option: AddEventListenerOptions = {
|
|
508
|
-
capture: true,
|
|
509
|
-
}
|
|
510
|
-
) {
|
|
503
|
+
removeShowEvent(option: AddEventListenerOptions = defaultListenerOption) {
|
|
511
504
|
/* 焦点|点击事件*/
|
|
512
505
|
popsDOMUtils.off(
|
|
513
|
-
[config
|
|
506
|
+
[config.$target, config.$inputTarget],
|
|
514
507
|
["focus", "click"],
|
|
515
508
|
void 0,
|
|
516
509
|
SearchSuggestion.showEvent,
|
|
517
510
|
option
|
|
518
511
|
);
|
|
519
|
-
|
|
520
|
-
popsDOMUtils.off([config
|
|
512
|
+
// 内容改变事件
|
|
513
|
+
popsDOMUtils.off([config.$inputTarget], ["input"], void 0, SearchSuggestion.showEvent, option);
|
|
521
514
|
},
|
|
522
515
|
/**
|
|
523
516
|
* 隐藏搜索建议框的事件
|
|
@@ -526,15 +519,15 @@ export const PopsSearchSuggestion = {
|
|
|
526
519
|
hideEvent(event: PointerEvent | MouseEvent) {
|
|
527
520
|
if (event.target instanceof Node) {
|
|
528
521
|
if ($shadowContainer.contains(event.target)) {
|
|
529
|
-
|
|
522
|
+
// 点击在shadow上的
|
|
530
523
|
return;
|
|
531
524
|
}
|
|
532
|
-
if (config
|
|
533
|
-
|
|
525
|
+
if (config.$target.contains(event.target)) {
|
|
526
|
+
// 点击在目标元素内
|
|
534
527
|
return;
|
|
535
528
|
}
|
|
536
|
-
if (config
|
|
537
|
-
|
|
529
|
+
if (config.$inputTarget.contains(event.target)) {
|
|
530
|
+
// 点击在目标input内
|
|
538
531
|
return;
|
|
539
532
|
}
|
|
540
533
|
SearchSuggestion.hide(true);
|
|
@@ -543,35 +536,21 @@ export const PopsSearchSuggestion = {
|
|
|
543
536
|
/**
|
|
544
537
|
* 设置隐藏搜索建议框的事件
|
|
545
538
|
*/
|
|
546
|
-
setHideEvent(
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
) {
|
|
551
|
-
/* 全局点击事件 */
|
|
552
|
-
/* 全局触摸屏点击事件 */
|
|
539
|
+
setHideEvent(option: AddEventListenerOptions = defaultListenerOption) {
|
|
540
|
+
// 全局点击事件
|
|
541
|
+
// 全局触摸屏点击事件
|
|
553
542
|
if (Array.isArray(SearchSuggestion.selfDocument)) {
|
|
554
543
|
SearchSuggestion.selfDocument.forEach(($checkParent) => {
|
|
555
544
|
popsDOMUtils.on($checkParent, ["click", "touchstart"], void 0, SearchSuggestion.hideEvent, option);
|
|
556
545
|
});
|
|
557
546
|
} else {
|
|
558
|
-
popsDOMUtils.on(
|
|
559
|
-
SearchSuggestion.selfDocument,
|
|
560
|
-
["click", "touchstart"],
|
|
561
|
-
void 0,
|
|
562
|
-
SearchSuggestion.hideEvent,
|
|
563
|
-
option
|
|
564
|
-
);
|
|
547
|
+
popsDOMUtils.on(SearchSuggestion.selfDocument, ["click", "touchstart"], SearchSuggestion.hideEvent, option);
|
|
565
548
|
}
|
|
566
549
|
},
|
|
567
550
|
/**
|
|
568
551
|
* 移除隐藏搜索建议框的事件
|
|
569
552
|
*/
|
|
570
|
-
removeHideEvent(
|
|
571
|
-
option: AddEventListenerOptions = {
|
|
572
|
-
capture: true,
|
|
573
|
-
}
|
|
574
|
-
) {
|
|
553
|
+
removeHideEvent(option: AddEventListenerOptions = defaultListenerOption) {
|
|
575
554
|
if (Array.isArray(SearchSuggestion.selfDocument)) {
|
|
576
555
|
SearchSuggestion.selfDocument.forEach(($checkParent) => {
|
|
577
556
|
popsDOMUtils.off($checkParent, ["click", "touchstart"], void 0, SearchSuggestion.hideEvent, option);
|
|
@@ -587,13 +566,9 @@ export const PopsSearchSuggestion = {
|
|
|
587
566
|
}
|
|
588
567
|
},
|
|
589
568
|
/**
|
|
590
|
-
*
|
|
569
|
+
* 设置所有监听,包括(input值改变、全局点击判断显示/隐藏建议框)
|
|
591
570
|
*/
|
|
592
|
-
setAllEvent(
|
|
593
|
-
option: AddEventListenerOptions = {
|
|
594
|
-
capture: true,
|
|
595
|
-
}
|
|
596
|
-
) {
|
|
571
|
+
setAllEvent(option: AddEventListenerOptions = defaultListenerOption) {
|
|
597
572
|
SearchSuggestion.setInputChangeEvent(option);
|
|
598
573
|
SearchSuggestion.setHideEvent(option);
|
|
599
574
|
SearchSuggestion.setShowEvent(option);
|
|
@@ -601,12 +576,8 @@ export const PopsSearchSuggestion = {
|
|
|
601
576
|
/**
|
|
602
577
|
* 移除所有监听
|
|
603
578
|
*/
|
|
604
|
-
removeAllEvent(
|
|
605
|
-
|
|
606
|
-
capture: true,
|
|
607
|
-
}
|
|
608
|
-
) {
|
|
609
|
-
SearchSuggestion.removeInputChangeEvent(option);
|
|
579
|
+
removeAllEvent(option: AddEventListenerOptions = defaultListenerOption) {
|
|
580
|
+
SearchSuggestion.removeInputChangeEvent();
|
|
610
581
|
SearchSuggestion.removeHideEvent(option);
|
|
611
582
|
SearchSuggestion.removeShowEvent(option);
|
|
612
583
|
},
|
|
@@ -627,7 +598,7 @@ export const PopsSearchSuggestion = {
|
|
|
627
598
|
*/
|
|
628
599
|
setPromptsInSearch() {
|
|
629
600
|
const $isSearching = popsDOMUtils.createElement("li", {
|
|
630
|
-
className: `pops-${popsType}-search-suggestion-
|
|
601
|
+
className: `pops-${popsType}-search-suggestion-dropdown-searching-item`,
|
|
631
602
|
innerHTML: config.searchingTip,
|
|
632
603
|
});
|
|
633
604
|
SearchSuggestion.addItem($isSearching);
|
|
@@ -636,8 +607,8 @@ export const PopsSearchSuggestion = {
|
|
|
636
607
|
* 移除正在搜索中的提示
|
|
637
608
|
*/
|
|
638
609
|
removePromptsInSearch() {
|
|
639
|
-
SearchSuggestion.$el.$
|
|
640
|
-
.querySelector<HTMLLIElement>(`li.pops-${popsType}-search-suggestion-
|
|
610
|
+
SearchSuggestion.$el.$dropdownContainer
|
|
611
|
+
.querySelector<HTMLLIElement>(`li.pops-${popsType}-search-suggestion-dropdown-searching-item`)
|
|
641
612
|
?.remove();
|
|
642
613
|
},
|
|
643
614
|
/**
|
|
@@ -646,13 +617,13 @@ export const PopsSearchSuggestion = {
|
|
|
646
617
|
* @param target 目标元素
|
|
647
618
|
* @param checkPositonAgain 是否在更新位置信息后检测更新位置信息,默认true
|
|
648
619
|
*/
|
|
649
|
-
changeHintULElementPosition(target = config
|
|
620
|
+
changeHintULElementPosition(target = config.$target ?? config.$inputTarget, checkPositonAgain: boolean = true) {
|
|
650
621
|
let targetRect: DOMRect | null = null;
|
|
651
622
|
if (config.followPosition === "inputCursor") {
|
|
652
623
|
targetRect = popsDOMUtils.getTextBoundingRect(
|
|
653
|
-
config
|
|
654
|
-
config
|
|
655
|
-
config
|
|
624
|
+
config.$inputTarget,
|
|
625
|
+
config.$inputTarget.selectionStart || 0,
|
|
626
|
+
config.$inputTarget.selectionEnd || 0,
|
|
656
627
|
false
|
|
657
628
|
);
|
|
658
629
|
} else {
|
|
@@ -669,12 +640,16 @@ export const PopsSearchSuggestion = {
|
|
|
669
640
|
}
|
|
670
641
|
// 文档最大宽度
|
|
671
642
|
const documentWidth = popsDOMUtils.width(document);
|
|
643
|
+
// 箭头
|
|
644
|
+
const arrowHeight = config.useArrow ? popsDOMUtils.height(SearchSuggestion.$el.$arrow) : 0;
|
|
672
645
|
|
|
673
646
|
let position = config.position;
|
|
674
647
|
if (config.position === "auto") {
|
|
675
648
|
// 需目标高度+搜索建议框高度大于文档高度,则显示在上面
|
|
676
649
|
const targetBottom = targetRect.bottom;
|
|
677
|
-
|
|
650
|
+
// 容器整体的高度
|
|
651
|
+
const searchSuggestionContainerHeight =
|
|
652
|
+
popsDOMUtils.height(SearchSuggestion.$el.$dropdownWrapper) + arrowHeight;
|
|
678
653
|
if (targetBottom + searchSuggestionContainerHeight > documentHeight) {
|
|
679
654
|
// 在上面
|
|
680
655
|
position = "top";
|
|
@@ -693,7 +668,7 @@ export const PopsSearchSuggestion = {
|
|
|
693
668
|
// 翻转折叠
|
|
694
669
|
SearchSuggestion.$el.root.setAttribute("data-popper-placement", "top");
|
|
695
670
|
}
|
|
696
|
-
const bottom = documentHeight - targetRect.top + config.topDistance;
|
|
671
|
+
const bottom = documentHeight - targetRect.top + config.topDistance + arrowHeight;
|
|
697
672
|
SearchSuggestion.$el.root.style.top = "";
|
|
698
673
|
SearchSuggestion.$el.root.style.bottom = bottom + "px";
|
|
699
674
|
} else if (position === "bottom") {
|
|
@@ -701,13 +676,13 @@ export const PopsSearchSuggestion = {
|
|
|
701
676
|
if (config.useFoldAnimation) {
|
|
702
677
|
SearchSuggestion.$el.root.setAttribute("data-popper-placement", "bottom-center");
|
|
703
678
|
}
|
|
704
|
-
const top = targetRect.height + targetRect.top + config.topDistance;
|
|
679
|
+
const top = targetRect.height + targetRect.top + config.topDistance + arrowHeight;
|
|
705
680
|
SearchSuggestion.$el.root.removeAttribute("data-top-reverse");
|
|
706
681
|
SearchSuggestion.$el.root.style.bottom = "";
|
|
707
682
|
SearchSuggestion.$el.root.style.top = top + "px";
|
|
708
683
|
}
|
|
709
684
|
let left = targetRect.left;
|
|
710
|
-
const hintUIWidth = popsDOMUtils.width(SearchSuggestion.$el.$
|
|
685
|
+
const hintUIWidth = popsDOMUtils.width(SearchSuggestion.$el.$dropdownWrapper);
|
|
711
686
|
if (hintUIWidth > documentWidth) {
|
|
712
687
|
// 超出宽度
|
|
713
688
|
left = left + documentWidth - hintUIWidth;
|
|
@@ -728,12 +703,12 @@ export const PopsSearchSuggestion = {
|
|
|
728
703
|
* 因为目标元素可能是动态隐藏的
|
|
729
704
|
* @param target 目标元素
|
|
730
705
|
*/
|
|
731
|
-
changeHintULElementWidth(target = config
|
|
706
|
+
changeHintULElementWidth(target = config.$target ?? config.$inputTarget) {
|
|
732
707
|
const targetRect = target.getBoundingClientRect();
|
|
733
708
|
if (config.followTargetWidth) {
|
|
734
|
-
SearchSuggestion.$el.$
|
|
709
|
+
SearchSuggestion.$el.$dropdownWrapper.style.width = targetRect.width + "px";
|
|
735
710
|
} else {
|
|
736
|
-
SearchSuggestion.$el.$
|
|
711
|
+
SearchSuggestion.$el.$dropdownWrapper.style.width = config.width;
|
|
737
712
|
}
|
|
738
713
|
},
|
|
739
714
|
/**
|
|
@@ -763,7 +738,7 @@ export const PopsSearchSuggestion = {
|
|
|
763
738
|
* @param $item 项元素
|
|
764
739
|
*/
|
|
765
740
|
addItem($item: HTMLElement | DocumentFragment) {
|
|
766
|
-
SearchSuggestion.$el.$
|
|
741
|
+
SearchSuggestion.$el.$dropdownContainer.appendChild($item);
|
|
767
742
|
},
|
|
768
743
|
/**
|
|
769
744
|
* 更新页面显示的搜索结果
|
|
@@ -774,14 +749,14 @@ export const PopsSearchSuggestion = {
|
|
|
774
749
|
throw new TypeError("传入的数据不是数组");
|
|
775
750
|
}
|
|
776
751
|
const data = updateData;
|
|
777
|
-
|
|
752
|
+
// 清空已有的搜索结果
|
|
778
753
|
if (data.length) {
|
|
779
754
|
SearchSuggestion.$data.isEmpty = false;
|
|
780
755
|
if (config.toHideWithNotResult) {
|
|
781
756
|
SearchSuggestion.show();
|
|
782
757
|
}
|
|
783
758
|
SearchSuggestion.clear(true);
|
|
784
|
-
|
|
759
|
+
// 添加进ul中
|
|
785
760
|
const fragment = document.createDocumentFragment();
|
|
786
761
|
data.forEach((item, index) => {
|
|
787
762
|
const $item = SearchSuggestion.createSearchItemLiElement(item, index);
|
|
@@ -791,7 +766,7 @@ export const PopsSearchSuggestion = {
|
|
|
791
766
|
});
|
|
792
767
|
SearchSuggestion.addItem(fragment);
|
|
793
768
|
} else {
|
|
794
|
-
|
|
769
|
+
// 清空
|
|
795
770
|
SearchSuggestion.clear();
|
|
796
771
|
}
|
|
797
772
|
},
|
|
@@ -800,7 +775,7 @@ export const PopsSearchSuggestion = {
|
|
|
800
775
|
* @param [onlyClearView=false] 是否仅清空元素,默认false
|
|
801
776
|
*/
|
|
802
777
|
clear(onlyClearView: boolean = false) {
|
|
803
|
-
PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$
|
|
778
|
+
PopsSafeUtils.setSafeHTML(SearchSuggestion.$el.$dropdownContainer, "");
|
|
804
779
|
if (onlyClearView) {
|
|
805
780
|
return;
|
|
806
781
|
}
|