@whitesev/pops 2.3.7 → 2.4.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.
@@ -151,6 +151,9 @@ declare class Pops {
151
151
  transformLeft: number;
152
152
  transformTop: number;
153
153
  };
154
+ onInput($el: HTMLInputElement | HTMLTextAreaElement, callback: (evt: InputEvent) => void | Promise<void>, option?: import("./types/PopsDOMUtilsEventType").PopsDOMUtilsEventListenerOption | boolean): {
155
+ off: () => void;
156
+ };
154
157
  on<T extends import("./types/PopsDOMUtilsEventType").PopsDOMUtils_EventType>(element: import("./types/PopsDOMUtilsEventType").PopsDOMUtilsElementEventType, eventType: T | T[], callback: (this: HTMLElement, event: import("./types/PopsDOMUtilsEventType").PopsDOMUtils_Event[T]) => void, option?: import("./types/PopsDOMUtilsEventType").PopsDOMUtilsEventListenerOption | boolean): void;
155
158
  on<T extends Event>(element: import("./types/PopsDOMUtilsEventType").PopsDOMUtilsElementEventType, eventType: string | string[], callback: (this: HTMLElement, event: T) => void, option?: import("./types/PopsDOMUtilsEventType").PopsDOMUtilsEventListenerOption | boolean): void;
156
159
  on<T extends import("./types/PopsDOMUtilsEventType").PopsDOMUtils_EventType>(element: import("./types/PopsDOMUtilsEventType").PopsDOMUtilsElementEventType, eventType: T | T[], selector: string | string[] | undefined | null, callback: (this: HTMLElement, event: import("./types/PopsDOMUtilsEventType").PopsDOMUtils_Event[T], selectorTarget: HTMLElement) => void, option?: import("./types/PopsDOMUtilsEventType").PopsDOMUtilsEventListenerOption | boolean): void;
@@ -21409,16 +21412,20 @@ declare class Pops {
21409
21412
  $hintULContainer: HTMLUListElement;
21410
21413
  $dynamicCSS: HTMLStyleElement;
21411
21414
  };
21415
+ $evt: {
21416
+ offInputChangeEvtHandler: Function[];
21417
+ };
21412
21418
  $data: {
21413
21419
  isEmpty: boolean;
21414
21420
  };
21415
- initEl(): void;
21416
21421
  init(parentElement?: HTMLElement): void;
21417
- getData(): any[];
21422
+ initEl(): void;
21423
+ getData(): import("./components/searchSuggestion/types/index").PopsSearchSuggestionData<T>[];
21424
+ setData(data: import("./components/searchSuggestion/types/index").PopsSearchSuggestionData<T>[]): void;
21418
21425
  createSearchSelectElement(): HTMLDivElement;
21419
21426
  getDynamicCSS(): string;
21420
- createSearchItemLiElement(data: any, index: number): HTMLLIElement;
21421
- getItemDataValue(data: any): any;
21427
+ getItemDataValue(data: import("./components/searchSuggestion/types/index").PopsSearchSuggestionData<T>): import("./components/searchSuggestion/types/index").PopsSearchSuggestionData<T>;
21428
+ createSearchItemLiElement(dataItem: import("./components/searchSuggestion/types/index").PopsSearchSuggestionData<T>, dateItemIndex: number): HTMLLIElement;
21422
21429
  setSearchItemClickEvent($searchItem: HTMLLIElement): void;
21423
21430
  setSearchItemSelectEvent(liElement: HTMLLIElement): void;
21424
21431
  setInputChangeEvent(option?: AddEventListenerOptions): void;
@@ -21431,16 +21438,16 @@ declare class Pops {
21431
21438
  removeHideEvent(option?: AddEventListenerOptions): void;
21432
21439
  setAllEvent(option?: AddEventListenerOptions): void;
21433
21440
  removeAllEvent(option?: AddEventListenerOptions): void;
21434
- getDeleteIconHTML(size?: number, fill?: string): string;
21441
+ createItemDeleteIcon(size?: number, fill?: string): HTMLElement;
21435
21442
  setPromptsInSearch(): void;
21436
21443
  removePromptsInSearch(): void;
21437
- clearAllSearchItemLi(): void;
21438
- changeHintULElementPosition(target?: HTMLElement): void;
21444
+ changeHintULElementPosition(target?: HTMLElement, checkPositonAgain?: Boolean): void;
21439
21445
  changeHintULElementWidth(target?: HTMLElement): void;
21440
21446
  updateDynamicCSS(): void;
21441
21447
  updateStyleSheet(): void;
21442
- update(data?: any[]): void;
21443
- clear(): void;
21448
+ addItem($item: HTMLElement | DocumentFragment): void;
21449
+ update(updateData?: import("./components/searchSuggestion/types/index").PopsSearchSuggestionData<T>[]): void;
21450
+ clear(onlyClearView?: boolean): void;
21444
21451
  hide(useAnimationToHide?: boolean): void;
21445
21452
  show(): void;
21446
21453
  };
@@ -1,2 +1,2 @@
1
1
  import type { PopsSearchSuggestionDetails } from "./types/index";
2
- export declare const searchSuggestionConfig: () => DeepRequired<PopsSearchSuggestionDetails>;
2
+ export declare const searchSuggestionConfig: () => DeepRequired<PopsSearchSuggestionDetails<any>>;
@@ -1,6 +1,6 @@
1
- import type { PopsSearchSuggestionDetails } from "./types/index";
1
+ import type { PopsSearchSuggestionData, PopsSearchSuggestionDetails } from "./types/index";
2
2
  export declare const PopsSearchSuggestion: {
3
- init(details: PopsSearchSuggestionDetails): {
3
+ init<T>(details: PopsSearchSuggestionDetails<T>): {
4
4
  /**
5
5
  * 当前的环境,可以是document,可以是shadowroot,默认是document
6
6
  */
@@ -13,40 +13,53 @@ export declare const PopsSearchSuggestion: {
13
13
  /** 动态更新CSS */
14
14
  $dynamicCSS: HTMLStyleElement;
15
15
  };
16
+ $evt: {
17
+ offInputChangeEvtHandler: Function[];
18
+ };
16
19
  $data: {
17
20
  /** 是否结果为空 */
18
21
  isEmpty: boolean;
19
22
  };
20
- /** 初始化元素变量 */
21
- initEl(): void;
22
23
  /**
23
24
  * 初始化
25
+ * @param parentElement 父元素
24
26
  */
25
27
  init(parentElement?: HTMLElement): void;
28
+ /**
29
+ * 初始化元素变量
30
+ */
31
+ initEl(): void;
26
32
  /**
27
33
  * 获取数据
28
34
  */
29
- getData(): any[];
35
+ getData(): PopsSearchSuggestionData<T>[];
36
+ /**
37
+ * 更新数据
38
+ * @param data 数据
39
+ */
40
+ setData(data: PopsSearchSuggestionData<T>[]): void;
30
41
  /**
31
42
  * 获取显示出搜索建议框的html
32
43
  */
33
44
  createSearchSelectElement(): HTMLDivElement;
34
- /** 动态获取CSS */
35
- getDynamicCSS(): string;
36
45
  /**
37
- * 获取显示出搜索建议框的每一项的html
38
- * @param data 当前项的值
39
- * @param index 当前项的下标
46
+ * 动态获取CSS
40
47
  */
41
- createSearchItemLiElement(data: any, index: number): HTMLLIElement;
48
+ getDynamicCSS(): string;
42
49
  /**
43
50
  * 获取data-value值
44
- * @param data
51
+ * @param data 数据项
52
+ */
53
+ getItemDataValue(data: PopsSearchSuggestionData<T>): PopsSearchSuggestionData<T>;
54
+ /**
55
+ * 获取显示出搜索建议框的每一项的html
56
+ * @param dataItem 当前项的值
57
+ * @param dateItemIndex 当前项的下标
45
58
  */
46
- getItemDataValue(data: any): any;
59
+ createSearchItemLiElement(dataItem: PopsSearchSuggestionData<T>, dateItemIndex: number): HTMLLIElement;
47
60
  /**
48
61
  * 设置搜索建议框每一项的点击事件
49
- * @param $searchItem
62
+ * @param $searchItem 当前项的元素
50
63
  */
51
64
  setSearchItemClickEvent($searchItem: HTMLLIElement): void;
52
65
  /**
@@ -98,7 +111,7 @@ export declare const PopsSearchSuggestion: {
98
111
  /**
99
112
  * 获取删除按钮的html
100
113
  */
101
- getDeleteIconHTML(size?: number, fill?: string): string;
114
+ createItemDeleteIcon(size?: number, fill?: string): HTMLElement;
102
115
  /**
103
116
  * 设置当前正在搜索中的提示
104
117
  */
@@ -107,18 +120,17 @@ export declare const PopsSearchSuggestion: {
107
120
  * 移除正在搜索中的提示
108
121
  */
109
122
  removePromptsInSearch(): void;
110
- /**
111
- * 清空所有的搜索结果
112
- */
113
- clearAllSearchItemLi(): void;
114
123
  /**
115
124
  * 更新搜索建议框的位置(top、left)
116
125
  * 因为目标元素可能是动态隐藏的
126
+ * @param target 目标元素
127
+ * @param checkPositonAgain 是否在更新位置信息后检测更新位置信息,默认true
117
128
  */
118
- changeHintULElementPosition(target?: HTMLElement): void;
129
+ changeHintULElementPosition(target?: HTMLElement, checkPositonAgain?: Boolean): void;
119
130
  /**
120
131
  * 更新搜索建议框的width
121
132
  * 因为目标元素可能是动态隐藏的
133
+ * @param target 目标元素
122
134
  */
123
135
  changeHintULElementWidth(target?: HTMLElement): void;
124
136
  /**
@@ -127,17 +139,27 @@ export declare const PopsSearchSuggestion: {
127
139
  updateDynamicCSS(): void;
128
140
  /**
129
141
  * 数据项的数量改变时调用
142
+ *
143
+ * - 更新css
144
+ * - 更新建议框的宽度
145
+ * - 更新建议框的位置
130
146
  */
131
147
  updateStyleSheet(): void;
148
+ /**
149
+ * 添加搜索结果元素
150
+ * @param $item 项元素
151
+ */
152
+ addItem($item: HTMLElement | DocumentFragment): void;
132
153
  /**
133
154
  * 更新页面显示的搜索结果
134
- * @param data
155
+ * @param updateData
135
156
  */
136
- update(data?: any[]): void;
157
+ update(updateData?: PopsSearchSuggestionData<T>[]): void;
137
158
  /**
138
159
  * 清空当前的搜索结果并显示无结果
160
+ * @param [onlyClearView=false] 是否仅清空元素,默认false
139
161
  */
140
- clear(): void;
162
+ clear(onlyClearView?: boolean): void;
141
163
  /**
142
164
  * 隐藏搜索建议框
143
165
  * @param useAnimationToHide 是否使用动画隐藏
@@ -1,4 +1,103 @@
1
1
  import type { PopsCommonConfig } from "../../../types/components";
2
+ export type PopsSearchSuggestionData<T = any> = {
3
+ /**
4
+ * 值
5
+ */
6
+ value: T;
7
+ /**
8
+ * 显示的文本
9
+ */
10
+ text: string;
11
+ /**
12
+ * 是否启用右侧的删除按钮
13
+ * @default true
14
+ */
15
+ enableDeleteButton?: boolean;
16
+ /**
17
+ * 删除按钮的点击回调
18
+ * @returns
19
+ *
20
+ * + true 移除该元素并且从data中移除该数据, 如果data是函数返回数组的话,那么不会生效
21
+ */
22
+ deleteButtonClickCallback?: (
23
+ /**
24
+ * 点击事件
25
+ */
26
+ event: MouseEvent | PointerEvent,
27
+ /**
28
+ * 当前项的元素
29
+ */
30
+ $dataItem: HTMLLIElement,
31
+ /**
32
+ * 数据项
33
+ */
34
+ dataItem: PopsSearchSuggestionData<T>,
35
+ /**
36
+ * 当前配置
37
+ */
38
+ config: PopsSearchSuggestionDetails<T>) => void | Boolean | Promise<void | Boolean>;
39
+ /**
40
+ * 获取每一项的html,在显示的时候会调用该函数
41
+ *
42
+ * 它的父元素是一个\<li>元素
43
+ */
44
+ itemView: (
45
+ /**
46
+ * 数据项
47
+ */
48
+ dateItem: PopsSearchSuggestionData<T>,
49
+ /**
50
+ * 父元素\<li>
51
+ */
52
+ $parent: HTMLLIElement,
53
+ /**
54
+ * 当前配置
55
+ */
56
+ config: PopsSearchSuggestionDetails<T>) => HTMLElement | string;
57
+ /**
58
+ * 每一项的点击回调
59
+ * @returns
60
+ *
61
+ * + true 如果设置了inputTarget且类型是input或textarea的话,那么将自动设置目标值为当前点击项的value值
62
+ */
63
+ clickCallback?: (
64
+ /**
65
+ * 点击事件
66
+ */
67
+ event: MouseEvent | PointerEvent,
68
+ /**
69
+ * 当前项的元素
70
+ */
71
+ $dataItem: HTMLLIElement,
72
+ /**
73
+ * 数据项
74
+ */
75
+ dataItem: PopsSearchSuggestionData<T>,
76
+ /**
77
+ * 当前配置
78
+ */
79
+ config: PopsSearchSuggestionDetails<T>) => void | Boolean | Promise<void | Boolean>;
80
+ /**
81
+ * 键盘的上下键选择的回调
82
+ */
83
+ selectCallback?: (
84
+ /**
85
+ * 键盘事件
86
+ */
87
+ event: KeyboardEvent,
88
+ /**
89
+ * 当前项的元素
90
+ */
91
+ $dataItem: HTMLLIElement,
92
+ /**
93
+ * 数据项
94
+ */
95
+ dataItem: PopsSearchSuggestionData<T>,
96
+ /**
97
+ * 当前配置
98
+ */
99
+ config: PopsSearchSuggestionDetails<T>) => void;
100
+ };
2
101
  /**
3
102
  * 搜索建议悬浮窗
4
103
  * pops.searchSuggestion
@@ -15,32 +114,25 @@ export interface PopsSearchSuggestionDetails<T = any> extends Pick<PopsCommonCon
15
114
  target: HTMLElement;
16
115
  /**
17
116
  * 目标input元素,监听它的focus/click/input事件
117
+ *
118
+ * 如果未填,那么自动使用target的值
119
+ * @default config.target
18
120
  */
19
121
  inputTarget?: HTMLInputElement | HTMLTextAreaElement;
20
122
  /**
21
123
  * 数据
22
124
  */
23
- data: T[] | (() => T[]);
24
- /**
25
- * 右边的删除按钮图标
26
- */
27
- deleteIcon?: {
28
- /**
29
- * 是否启用
30
- * @default true
31
- */
32
- enable?: boolean;
33
- /**
34
- * 点击回调
35
- */
36
- callback?: (event: MouseEvent | PointerEvent, $dataItem: HTMLLIElement, dataItem: T) => void;
37
- };
125
+ data: PopsSearchSuggestionData<T>[] | (() => PopsSearchSuggestionData<T>[]);
38
126
  /**
39
127
  * 自定义的className
128
+ * @default ""
40
129
  */
41
130
  className?: string;
42
131
  /**
43
- * position是否使用absolut,否则是relative
132
+ * 建议框的position位置
133
+ *
134
+ * + `true`:absolute
135
+ * + `false`:relative
44
136
  * @default true
45
137
  */
46
138
  isAbsolute?: boolean;
@@ -90,7 +182,7 @@ export interface PopsSearchSuggestionDetails<T = any> extends Pick<PopsCommonCon
90
182
  */
91
183
  positionTopToReverse?: boolean;
92
184
  /**
93
- * 搜索中的提示
185
+ * 搜索中的提示,可以是html
94
186
  *
95
187
  * 前提:inputTarget是input/textarea
96
188
  *
@@ -103,42 +195,42 @@ export interface PopsSearchSuggestionDetails<T = any> extends Pick<PopsCommonCon
103
195
  * 前提:inputTarget是input/textarea
104
196
  *
105
197
  * 触发change事件,且没有搜索到数据,则显示此结果项
198
+ *
199
+ * 如果该值是函数,需要返回的\<li>元素属性上存在data-none="true"
200
+ * @example
201
+ * <li data-none="true">暂无结果</li>
106
202
  */
107
- toSearhNotResultHTML?: string;
203
+ toSearhNotResultHTML?: string | (() => HTMLLIElement);
108
204
  /**
109
- * 没有搜索结果是否隐藏提示框
205
+ * 当没有搜索结果时,是否隐藏建议框
110
206
  * @default false
111
207
  */
112
208
  toHideWithNotResult?: boolean;
113
209
  /**
114
210
  * 跟随目标的位置
211
+ *
212
+ * + `target`:跟随config.target的位置
213
+ * + `input`:跟随config.inputTarget的位置
214
+ * + `inputCursor`:跟随config.inputTarget的输入框光标位置
215
+ *
115
216
  * @default "target"
116
217
  */
117
218
  followPosition?: "target" | "input" | "inputCursor";
118
219
  /**
119
- * 获取每一项的html,在显示的时候会调用该函数
120
- *
121
- * 它的父元素是一个<li>标签
220
+ * 当config.target触发input时自动调用该函数来获取数据
221
+ * @returns 返回是需要显示的数据
122
222
  */
123
- getItemHTML: (dataItem: T) => string;
223
+ inputTargetChangeRefreshShowDataCallback?: (
124
224
  /**
125
- * 当config.target触发input时自动调用该函数来获取数据
126
- * @param inputValue 当前输入框的值
127
- * @param data 当前数据
225
+ * 当前输入框的值
128
226
  */
129
- getData?: (inputValue: string, data: T[]) => Promise<T[]> | T[];
227
+ inputValue: string,
130
228
  /**
131
- * 每一项的点击回调
132
- * @param event 触发的事件
133
- * @param $dataItem 每一项的元素
134
- * @param dataItem config.data的点击项的值
229
+ * config.data的数据
135
230
  */
136
- itemClickCallBack?: (event: MouseEvent | PointerEvent, $dataItem: HTMLLIElement, dataItem: T) => void;
231
+ data: PopsSearchSuggestionData<T>[],
137
232
  /**
138
- * 键盘的上下键选择的回调
139
- * @param event 触发的事件
140
- * @param $dataItem 每一项的元素
141
- * @param dataItem config.data的选中项的值
233
+ * 当前配置
142
234
  */
143
- selectCallBack?: (event: MouseEvent, $dataItem: HTMLLIElement, dataItem: T) => void;
235
+ config: PopsSearchSuggestionDetails<T>) => Promise<PopsSearchSuggestionData<T>[]> | PopsSearchSuggestionData<T>[];
144
236
  }
@@ -750,6 +750,12 @@ declare class PopsDOMUtils extends PopsDOMUtilsEvent {
750
750
  transformLeft: number;
751
751
  transformTop: number;
752
752
  };
753
+ /**
754
+ * 监input、textarea的输入框值改变的事件
755
+ */
756
+ onInput($el: HTMLInputElement | HTMLTextAreaElement, callback: (evt: InputEvent) => void | Promise<void>, option?: PopsDOMUtilsEventListenerOption | boolean): {
757
+ off: () => void;
758
+ };
753
759
  }
754
760
  declare const popsDOMUtils: PopsDOMUtils;
755
761
  export { popsDOMUtils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/pops",
3
- "version": "2.3.7",
3
+ "version": "2.4.0",
4
4
  "description": "弹窗库",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/WhiteSevs/TamperMonkeyScript/tree/master/lib/pops#readme",