@whitesev/pops 4.0.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/index.amd.js +363 -275
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.amd.min.js +1 -1
  4. package/dist/index.amd.min.js.map +1 -1
  5. package/dist/index.cjs.js +363 -275
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/index.cjs.min.js +1 -1
  8. package/dist/index.cjs.min.js.map +1 -1
  9. package/dist/index.esm.js +363 -275
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.esm.min.js +1 -1
  12. package/dist/index.esm.min.js.map +1 -1
  13. package/dist/index.iife.js +363 -275
  14. package/dist/index.iife.js.map +1 -1
  15. package/dist/index.iife.min.js +1 -1
  16. package/dist/index.iife.min.js.map +1 -1
  17. package/dist/index.system.js +363 -275
  18. package/dist/index.system.js.map +1 -1
  19. package/dist/index.system.min.js +1 -1
  20. package/dist/index.system.min.js.map +1 -1
  21. package/dist/index.umd.js +363 -275
  22. package/dist/index.umd.js.map +1 -1
  23. package/dist/index.umd.min.js +1 -1
  24. package/dist/index.umd.min.js.map +1 -1
  25. package/dist/types/src/Pops.d.ts +116 -16
  26. package/dist/types/src/components/loading/types/index.d.ts +1 -1
  27. package/dist/types/src/components/panel/index.d.ts +3 -2
  28. package/dist/types/src/components/rightClickMenu/types/index.d.ts +1 -1
  29. package/dist/types/src/components/searchSuggestion/types/index.d.ts +1 -1
  30. package/dist/types/src/components/tooltip/index.d.ts +82 -1
  31. package/dist/types/src/components/tooltip/types/index.d.ts +1 -1
  32. package/dist/types/src/config/GlobalConfig.d.ts +3 -3
  33. package/dist/types/src/event/EventEmiter.d.ts +7 -1
  34. package/dist/types/src/handler/PopsInstHandler.d.ts +4 -4
  35. package/dist/types/src/types/EventEmitter.d.ts +21 -0
  36. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +1 -1
  37. package/dist/types/src/types/components.d.ts +15 -18
  38. package/dist/types/src/types/global.d.ts +2 -0
  39. package/dist/types/src/types/mask.d.ts +6 -6
  40. package/dist/types/src/utils/PopsDOMUtils.d.ts +2 -2
  41. package/dist/types/src/utils/PopsInstanceUtils.d.ts +22 -0
  42. package/dist/types/src/utils/PopsUtils.d.ts +21 -16
  43. package/package.json +1 -1
  44. package/src/Pops.ts +11 -11
  45. package/src/components/alert/defaultConfig.ts +1 -1
  46. package/src/components/alert/index.ts +1 -1
  47. package/src/components/confirm/defaultConfig.ts +1 -1
  48. package/src/components/confirm/index.ts +1 -1
  49. package/src/components/drawer/defaultConfig.ts +1 -1
  50. package/src/components/drawer/index.ts +2 -1
  51. package/src/components/folder/defaultConfig.ts +1 -1
  52. package/src/components/folder/index.ts +1 -1
  53. package/src/components/iframe/defaultConfig.ts +1 -1
  54. package/src/components/iframe/index.ts +10 -6
  55. package/src/components/loading/defaultConfig.ts +1 -0
  56. package/src/components/loading/index.ts +10 -10
  57. package/src/components/loading/types/index.ts +1 -4
  58. package/src/components/panel/defaultConfig.ts +1 -1
  59. package/src/components/panel/handlerComponents.ts +4 -4
  60. package/src/components/panel/index.ts +3 -2
  61. package/src/components/prompt/defaultConfig.ts +1 -1
  62. package/src/components/prompt/index.ts +1 -1
  63. package/src/components/rightClickMenu/defaultConfig.ts +1 -1
  64. package/src/components/rightClickMenu/index.ts +1 -1
  65. package/src/components/rightClickMenu/types/index.ts +1 -1
  66. package/src/components/searchSuggestion/defaultConfig.ts +1 -0
  67. package/src/components/searchSuggestion/index.ts +1 -1
  68. package/src/components/searchSuggestion/types/index.ts +1 -1
  69. package/src/components/tooltip/defaultConfig.ts +1 -1
  70. package/src/components/tooltip/index.ts +1 -1
  71. package/src/components/tooltip/types/index.ts +1 -1
  72. package/src/event/EventEmiter.ts +15 -14
  73. package/src/handler/PopsHandler.ts +9 -21
  74. package/src/handler/PopsInstHandler.ts +65 -47
  75. package/src/types/EventEmitter.d.ts +21 -0
  76. package/src/types/PopsDOMUtilsEventType.d.ts +1 -1
  77. package/src/types/components.d.ts +15 -18
  78. package/src/types/global.d.ts +2 -0
  79. package/src/types/mask.d.ts +6 -6
  80. package/src/utils/PopsDOMUtils.ts +6 -3
  81. package/src/utils/PopsInstanceUtils.ts +50 -0
  82. package/src/utils/PopsUtils.ts +95 -68
  83. package/dist/types/src/utils/PopsDOMUtilsEventsConfig.d.ts +0 -4
  84. package/src/utils/PopsDOMUtilsEventsConfig.ts +0 -4
@@ -2,8 +2,9 @@ import type { EventMap, CustomEventMap } from "../types/EventEmitter";
2
2
  import type { PopsType } from "../types/main";
3
3
 
4
4
  class EventEmiter<T extends CustomEventMap = CustomEventMap> {
5
- #type: PopsType;
6
- #data = new Map<
5
+ [Symbol.toStringTag] = "EventEmiter";
6
+ type: PopsType;
7
+ data = new Map<
7
8
  string,
8
9
  {
9
10
  type: PopsType;
@@ -12,7 +13,7 @@ class EventEmiter<T extends CustomEventMap = CustomEventMap> {
12
13
  }[]
13
14
  >();
14
15
  constructor(type: PopsType) {
15
- this.#type = type;
16
+ this.type = type;
16
17
  document.addEventListener;
17
18
  }
18
19
  on<P extends keyof EventMap>(
@@ -30,9 +31,9 @@ class EventEmiter<T extends CustomEventMap = CustomEventMap> {
30
31
  emit: (...args: Parameters<T[P]>) => IPromise<void>;
31
32
  };
32
33
  on<P extends keyof EventMap | keyof CustomEventMap>(eventName: P, callback: (EventMap & CustomEventMap)[P]) {
33
- const eventList = this.#data.get(eventName) ?? [];
34
- eventList.push({ type: this.#type, time: Date.now(), callback: callback });
35
- this.#data.set(eventName, eventList);
34
+ const eventList = this.data.get(eventName) ?? [];
35
+ eventList.push({ type: this.type, time: Date.now(), callback: callback });
36
+ this.data.set(eventName, eventList);
36
37
  return {
37
38
  off: () => {
38
39
  this.off(eventName as keyof EventMap, callback);
@@ -45,7 +46,7 @@ class EventEmiter<T extends CustomEventMap = CustomEventMap> {
45
46
  off<P extends keyof EventMap>(eventName: P, callback: EventMap[P]): IPromise<void>;
46
47
  off<P extends keyof T>(eventName: P, callback: T[P]): IPromise<void>;
47
48
  off<P extends keyof EventMap | keyof CustomEventMap>(eventName: P, callback: (EventMap & CustomEventMap)[P]) {
48
- const eventList = this.#data.get(eventName) ?? [];
49
+ const eventList = this.data.get(eventName) ?? [];
49
50
  let isOffSuccess = false;
50
51
  for (let index = eventList.length - 1; index >= 0; index--) {
51
52
  if (eventList[index].callback === callback) {
@@ -55,18 +56,18 @@ class EventEmiter<T extends CustomEventMap = CustomEventMap> {
55
56
  }
56
57
  if (eventList.length === 0) {
57
58
  // empty
58
- this.#data.delete(eventName);
59
+ this.data.delete(eventName);
59
60
  } else {
60
61
  if (isOffSuccess) {
61
62
  // update
62
- this.#data.set(eventName, eventList);
63
+ this.data.set(eventName, eventList);
63
64
  }
64
65
  }
65
66
  }
66
67
  emit<P extends keyof T>(eventName: P, ...args: Parameters<T[P]>): IPromise<void>;
67
68
  emit<P extends keyof EventMap>(eventName: P, ...args: Parameters<EventMap[P]>): IPromise<void>;
68
69
  async emit<P extends keyof EventMap | keyof CustomEventMap>(eventName: P, ...args: Parameters<T[P]>) {
69
- const eventList = this.#data.get(eventName) ?? [];
70
+ const eventList = this.data.get(eventName) ?? [];
70
71
  for (const item of eventList) {
71
72
  await item.callback(...args);
72
73
  }
@@ -75,9 +76,9 @@ class EventEmiter<T extends CustomEventMap = CustomEventMap> {
75
76
  offAll<P extends keyof T>(eventName?: P): IPromise<void>;
76
77
  offAll<P extends keyof EventMap | keyof CustomEventMap>(eventName?: P) {
77
78
  if (typeof eventName === "string") {
78
- this.#data.delete(eventName);
79
+ this.data.delete(eventName);
79
80
  } else {
80
- this.#data.clear();
81
+ this.data.clear();
81
82
  }
82
83
  }
83
84
  /**
@@ -85,9 +86,9 @@ class EventEmiter<T extends CustomEventMap = CustomEventMap> {
85
86
  */
86
87
  getAllEvents(eventName?: string) {
87
88
  if (typeof eventName === "string") {
88
- return this.#data.get(eventName);
89
+ return this.data.get(eventName);
89
90
  } else {
90
- return Array.from(this.#data.values());
91
+ return Array.from(this.data.values());
91
92
  }
92
93
  }
93
94
  }
@@ -16,6 +16,7 @@ import type { CustomEventMap } from "../types/EventEmitter";
16
16
  import type { PopsInstGeneralConfig } from "../types/inst";
17
17
  import type { PopsInstStoreType, PopsSupportAnimConfigType, PopsSupportOnlyConfig, PopsType } from "../types/main";
18
18
  import { popsDOMUtils } from "../utils/PopsDOMUtils";
19
+ import { PopsInstanceUtils } from "../utils/PopsInstanceUtils";
19
20
  import { popsUtils } from "../utils/PopsUtils";
20
21
  import { PopsInstHandler } from "./PopsInstHandler";
21
22
 
@@ -154,11 +155,11 @@ export const PopsHandler = {
154
155
  * 点击其它区域的事件
155
156
  * @param event
156
157
  */
157
- function clickEvent(event: MouseEvent | PointerEvent) {
158
+ const clickEvent = (event: MouseEvent | PointerEvent) => {
158
159
  popsDOMUtils.preventEvent(event);
159
160
  // 获取该类型实例存储列表
160
161
  const targetInst = PopsInstData[config.type];
161
- function originalRun() {
162
+ const continueExec = () => {
162
163
  if (config.config.mask!.clickEvent!.toClose) {
163
164
  // 关闭
164
165
  return PopsInstHandler.close(config.config, config.type, targetInst, config.guid, config.animElement);
@@ -173,38 +174,25 @@ export const PopsHandler = {
173
174
  result.maskElement
174
175
  );
175
176
  }
176
- }
177
+ };
177
178
  if (typeof config.config.mask.clickCallBack === "function") {
178
- config.config.mask.clickCallBack(originalRun, config.config);
179
+ config.config.mask.clickCallBack(continueExec, config.config);
179
180
  } else {
180
- originalRun();
181
+ continueExec();
181
182
  }
182
183
  return false;
183
- }
184
+ };
184
185
  // 判断是否启用了遮罩层点击动作
185
186
  if (config.config.mask.clickEvent!.toClose || config.config.mask.clickEvent!.toHide) {
186
- /**
187
- * 判断点击的元素是否是动画层的元素
188
- * @param element
189
- * @returns
190
- */
191
- function isAnimElement(element: HTMLElement) {
192
- return Boolean(
193
- element?.localName?.toLowerCase() === "div" &&
194
- element.className &&
195
- element.className === "pops-anim" &&
196
- element.hasAttribute("anim")
197
- );
198
- }
199
187
  // 判断按下的元素是否是pops-anim
200
188
  popsDOMUtils.on(config.animElement, "pointerup", (event) => {
201
189
  const $click = event.composedPath()[0] as HTMLElement;
202
- isMaskClick = isAnimElement($click);
190
+ isMaskClick = PopsInstanceUtils.isAnimNode($click);
203
191
  });
204
192
  // 如果有动画层,在动画层上监听点击事件
205
193
  popsDOMUtils.on<MouseEvent | PointerEvent>(config.animElement, "click", (event) => {
206
194
  const $click = event.composedPath()[0] as HTMLElement;
207
- if (isMaskClick && isAnimElement($click)) {
195
+ if (isMaskClick && PopsInstanceUtils.isAnimNode($click)) {
208
196
  return clickEvent(event);
209
197
  }
210
198
  });
@@ -14,6 +14,7 @@ import { PopsInstData } from "../PopsInst";
14
14
  import type { PopsInstGeneralConfig } from "../types/inst";
15
15
  import type { PopsInstStoreType } from "../types/main";
16
16
  import { popsDOMUtils } from "../utils/PopsDOMUtils";
17
+ import { PopsInstanceUtils } from "../utils/PopsInstanceUtils";
17
18
  import { popsUtils } from "../utils/PopsUtils";
18
19
 
19
20
  export const PopsInstHandler = {
@@ -83,7 +84,7 @@ export const PopsInstHandler = {
83
84
  return totalInstConfigList;
84
85
  },
85
86
  /**
86
- * 隐藏
87
+ * 显示
87
88
  * @param popsType
88
89
  * @param instConfigList
89
90
  * @param guid
@@ -91,7 +92,7 @@ export const PopsInstHandler = {
91
92
  * @param $anim
92
93
  * @param $mask
93
94
  */
94
- hide(
95
+ show(
95
96
  config:
96
97
  | PopsAlertConfig
97
98
  | PopsDrawerConfig
@@ -110,48 +111,54 @@ export const PopsInstHandler = {
110
111
  // oxlint-disable-next-line no-async-promise-executor
111
112
  return new Promise<void>(async (resolve) => {
112
113
  const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
114
+
113
115
  const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
114
116
  if (fintInst) {
115
- // 存在实例
117
+ // 由于是隐蔽状态
118
+ // 先设置好动画状态
119
+ // 再显示,会自执行动画
120
+ const checkVisible = () => {
121
+ if (!PopsInstanceUtils.isHide($anim)) {
122
+ return true;
123
+ } else {
124
+ return false;
125
+ }
126
+ };
116
127
  const startAnim = async () => {
117
128
  if (popsType === "drawer") {
118
129
  // drawer是抽屉
119
130
  // 单独处理动画
120
131
  const drawerConfig = config as Required<PopsDrawerConfig>;
121
- await popsUtils.sleep(drawerConfig.closeDelay ?? 0);
132
+ await popsUtils.sleep(drawerConfig.openDelay ?? 0);
122
133
  if ($mask) {
123
- popsDOMUtils.css($mask, "display", "none");
134
+ popsDOMUtils.css($mask, "display", "");
124
135
  }
125
136
  const direction = drawerConfig.direction!;
126
- const size = "0";
137
+ const size = drawerConfig.size!.toString();
127
138
  if (["top", "bottom"].includes(direction)) {
128
139
  $pops.style.setProperty("height", size);
129
140
  } else if (["left", "right"].includes(direction)) {
130
141
  $pops.style.setProperty("width", size);
131
142
  } else {
132
- console.error("未知direction: ", direction);
143
+ console.error("未知direction", direction);
133
144
  }
134
145
  } else {
135
- instConfigItem.$anim.style.width = "100%";
136
- instConfigItem.$anim.style.height = "100%";
137
- Reflect.set(
138
- instConfigItem.$anim.style,
139
- "animation-name",
140
- instConfigItem.$anim.getAttribute("anim") + "-reverse"
141
- );
146
+ instConfigItem.$anim.style.width = "";
147
+ instConfigItem.$anim.style.height = "";
148
+ Reflect.set(instConfigItem.$anim.style, "animation-name", animName);
142
149
  }
143
- };
144
- const endCallback = () => {
145
- instConfigItem.$anim.style.display = "none";
150
+ instConfigItem.$anim.style.display = "";
146
151
  if (instConfigItem.$mask) {
147
- instConfigItem.$mask.style.display = "none";
152
+ instConfigItem.$mask.style.display = "";
148
153
  }
149
- fintInst.emitter.emit("pops:hide", instConfigItem);
154
+ };
155
+ const endCallback = () => {
156
+ fintInst.emitter.emit("pops:show", instConfigItem);
150
157
  };
151
158
  const instConfigItem = fintInst;
152
- fintInst.emitter.emit("pops:before-hide", instConfigItem);
153
- await startAnim();
154
- if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.$anim.style, "animation-name"))) {
159
+ const animName = instConfigItem.$anim!.getAttribute("anim")!.replace("-reverse", "");
160
+ fintInst.emitter.emit("pops:before-show", instConfigItem);
161
+ if (checkVisible() && PopsAnimation.hasAnim(animName)) {
155
162
  /**
156
163
  * 动画结束的回调
157
164
  */
@@ -166,21 +173,22 @@ export const PopsInstHandler = {
166
173
  animationendCallBack,
167
174
  {
168
175
  capture: true,
169
- once: true,
170
176
  }
171
177
  );
178
+ await startAnim();
172
179
  } else {
180
+ await startAnim();
173
181
  endCallback();
174
182
  resolve();
175
183
  }
176
184
  } else {
177
- console.error("hide-error: 该实例未存储");
185
+ console.error("show-error: 该实例未存储");
178
186
  resolve();
179
187
  }
180
188
  });
181
189
  },
182
190
  /**
183
- * 显示
191
+ * 隐藏
184
192
  * @param popsType
185
193
  * @param instConfigList
186
194
  * @param guid
@@ -188,7 +196,7 @@ export const PopsInstHandler = {
188
196
  * @param $anim
189
197
  * @param $mask
190
198
  */
191
- show(
199
+ hide(
192
200
  config:
193
201
  | PopsAlertConfig
194
202
  | PopsDrawerConfig
@@ -207,48 +215,55 @@ export const PopsInstHandler = {
207
215
  // oxlint-disable-next-line no-async-promise-executor
208
216
  return new Promise<void>(async (resolve) => {
209
217
  const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
210
-
211
218
  const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
212
219
  if (fintInst) {
220
+ // 由于是已显示状态
221
+ // 先执行动画
222
+ // 再隐藏
223
+ // 存在实例
224
+ const checkVisible = () => {
225
+ if (!PopsInstanceUtils.isHide($anim)) {
226
+ return true;
227
+ } else {
228
+ return false;
229
+ }
230
+ };
213
231
  const startAnim = async () => {
214
232
  if (popsType === "drawer") {
215
233
  // drawer是抽屉
216
234
  // 单独处理动画
217
235
  const drawerConfig = config as Required<PopsDrawerConfig>;
218
- await popsUtils.sleep(drawerConfig.openDelay ?? 0);
236
+ await popsUtils.sleep(drawerConfig.closeDelay ?? 0);
219
237
  if ($mask) {
220
- popsDOMUtils.css($mask, "display", "");
238
+ popsDOMUtils.css($mask, "display", "none");
221
239
  }
222
240
  const direction = drawerConfig.direction!;
223
- const size = drawerConfig.size!.toString();
241
+ const size = "0";
224
242
  if (["top", "bottom"].includes(direction)) {
225
243
  $pops.style.setProperty("height", size);
226
244
  } else if (["left", "right"].includes(direction)) {
227
245
  $pops.style.setProperty("width", size);
228
246
  } else {
229
- console.error("未知direction", direction);
247
+ console.error("未知direction: ", direction);
230
248
  }
231
249
  } else {
232
- instConfigItem.$anim.style.width = "";
233
- instConfigItem.$anim.style.height = "";
234
- Reflect.set(
235
- instConfigItem.$anim.style,
236
- "animation-name",
237
- instConfigItem.$anim!.getAttribute("anim")!.replace("-reverse", "")
238
- );
250
+ instConfigItem.$anim.style.width = "100%";
251
+ instConfigItem.$anim.style.height = "100%";
252
+ Reflect.set(instConfigItem.$anim.style, "animation-name", reverseAnimName);
239
253
  }
240
254
  };
241
255
  const endCallback = () => {
242
- instConfigItem.$anim.style.display = "";
256
+ instConfigItem.$anim.style.display = "none";
243
257
  if (instConfigItem.$mask) {
244
- instConfigItem.$mask.style.display = "";
258
+ instConfigItem.$mask.style.display = "none";
245
259
  }
246
- fintInst.emitter.emit("pops:show", instConfigItem);
260
+ fintInst.emitter.emit("pops:hide", instConfigItem);
247
261
  };
248
262
  const instConfigItem = fintInst;
249
- fintInst.emitter.emit("pops:before-show", instConfigItem);
250
- await startAnim();
251
- if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.$anim.style, "animation-name"))) {
263
+ const animName = instConfigItem.$anim!.getAttribute("anim")!.replace("-reverse", "");
264
+ const reverseAnimName = animName + "-reverse";
265
+ fintInst.emitter.emit("pops:before-hide", instConfigItem);
266
+ if (!checkVisible() && PopsAnimation.hasAnim(reverseAnimName)) {
252
267
  /**
253
268
  * 动画结束的回调
254
269
  */
@@ -263,14 +278,17 @@ export const PopsInstHandler = {
263
278
  animationendCallBack,
264
279
  {
265
280
  capture: true,
281
+ once: true,
266
282
  }
267
283
  );
284
+ await startAnim();
268
285
  } else {
286
+ await startAnim();
269
287
  endCallback();
270
288
  resolve();
271
289
  }
272
290
  } else {
273
- console.error("show-error: 该实例未存储");
291
+ console.error("hide-error: 该实例未存储");
274
292
  resolve();
275
293
  }
276
294
  });
@@ -324,7 +342,7 @@ export const PopsInstHandler = {
324
342
  await new Promise<void>(async (resolve) => {
325
343
  const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
326
344
  const drawerConfig = config as Required<PopsDrawerConfig>;
327
- const start = () => {
345
+ const startAnim = () => {
328
346
  /**
329
347
  * 弹窗已关闭的回调
330
348
  */
@@ -361,7 +379,7 @@ export const PopsInstHandler = {
361
379
  };
362
380
  if (popsType === "drawer") {
363
381
  await popsUtils.sleep(drawerConfig.closeDelay ?? 0);
364
- start();
382
+ startAnim();
365
383
  } else {
366
384
  await PopsInstHandler.removeInstance([instConfigList], guid);
367
385
  resolve();
@@ -1,12 +1,33 @@
1
1
  import type { PopsInstGeneralConfig } from "./inst";
2
2
 
3
3
  export type EventMap = {
4
+ /**
5
+ * 调用`.show`时触发
6
+ */
4
7
  "pops:before-show": (config: PopsInstGeneralConfig) => IPromise<void>;
8
+ /**
9
+ * 调用`.show`时触发
10
+ */
5
11
  "pops:show": (config: PopsInstGeneralConfig) => IPromise<void>;
12
+ /**
13
+ * 调用`.hide`时触发
14
+ */
6
15
  "pops:before-hide": (config: PopsInstGeneralConfig) => IPromise<void>;
16
+ /**
17
+ * 调用`.hide`时触发
18
+ */
7
19
  "pops:hide": (config: PopsInstGeneralConfig) => IPromise<void>;
20
+ /**
21
+ * 调用`.close`时触发
22
+ */
8
23
  "pops:before-destory": (config: PopsInstGeneralConfig) => IPromise<void>;
24
+ /**
25
+ * 调用`.close`时触发
26
+ */
9
27
  "pops:destory": () => IPromise<void>;
28
+ /**
29
+ * 插入到页面中时触发,但是需要传入`EventEmitter`来监听该事件,否则不触发
30
+ */
10
31
  "pops:before-append-to-page": (
11
32
  $shadowRoot: ShadowRoot | HTMLElement,
12
33
  $shadowContainer: HTMLDivElement
@@ -277,7 +277,7 @@ export declare type PopsDOMUtilsEventListenerOption = AddEventListenerOptions &
277
277
  isComposedPath?: boolean;
278
278
  };
279
279
 
280
- export type PopsDOMUtilsTargetElementType = HTMLElement | string | NodeList | HTMLElement[];
280
+ export type PopsDOMUtilsTargetElementType = IArray<HTMLElement> | string | NodeList;
281
281
 
282
282
  /**
283
283
  * 属性转驼峰
@@ -2,6 +2,8 @@ import type { PopsAnimation } from "./animation";
2
2
  import type { PopsPosition, PopsTextAlign, PopsJustifyContent } from "./position";
3
3
  import type { PopsGlobalButtonConfig, PopsButtonConfigAnyType, PopsHeaderCloseButtonConfig } from "./button";
4
4
  import type { PopsMaskConfig } from "./mask";
5
+ import type { EventEmiter } from "../event/EventEmiter";
6
+ import type { EventMap } from "./EventEmitter";
5
7
 
6
8
  /**
7
9
  * 标题配置
@@ -139,49 +141,41 @@ export interface PopsDragConfig {
139
141
  export interface PopsGeneralConfig {
140
142
  /**
141
143
  * 是否使用shadowRoot
142
- *
143
144
  * @default true
144
145
  */
145
146
  useShadowRoot?: boolean;
146
147
  /**
147
148
  * 自定义的className
148
- *
149
149
  * @default ""
150
150
  */
151
151
  class?: string;
152
152
  /**
153
153
  * 是否是唯一的
154
- *
155
154
  * @default false
156
155
  */
157
156
  only?: boolean;
158
157
  /**
159
158
  * 宽度
160
- *
161
159
  * @default "350px"
162
160
  */
163
161
  width: string;
164
162
  /**
165
163
  * 高度
166
- *
167
164
  * @default "200px"
168
165
  */
169
166
  height: string;
170
167
  /**
171
168
  * 位置
172
- *
173
169
  * @default "center"
174
170
  */
175
171
  position?: PopsPosition;
176
172
  /**
177
173
  * 动画
178
- *
179
174
  * @default "pops-anim-fadein-zoom"
180
175
  */
181
- animation?: PopsAnimation;
176
+ animation?: PopsAnimation | false;
182
177
  /**
183
178
  * z-index显示层级
184
- *
185
179
  * @default 10000
186
180
  */
187
181
  zIndex?: IFunction<number>;
@@ -193,38 +187,41 @@ export interface PopsGeneralConfig {
193
187
  * 是否禁用页面滚动
194
188
  *
195
189
  * 暂时不会生效
196
- *
197
190
  * @default false
198
191
  */
199
192
  forbiddenScroll?: boolean;
200
193
  /**
201
194
  * (可选)自定义style
202
- * @default ""
195
+ * @default null
203
196
  */
204
197
  style?: string | null;
205
198
  /**
206
199
  * (可选)自定义浅色模式的style
207
200
  *
208
- * 传入的css都在dark内
201
+ * css都在`@media (prefers-color-scheme: light)`内
202
+ * @default null
209
203
  */
210
204
  lightStyle?: string | null;
211
205
  /**
212
206
  * (可选)自定义深色模式的style
213
207
  *
214
- * 传入的css都在dark
208
+ * css都在`@media (prefers-color-scheme: dark)`内
209
+ * @default null
215
210
  */
216
211
  darkStyle?: string | null;
217
212
  /**
218
213
  * (可选)是否阻止`keydown`事件传播
219
214
  *
220
215
  * 主要是阻止当`keydown`触发来源为输入框时,即在输入框内按下按键不会触发页面的快捷键
221
- * @default true
216
+ * @default true 阻止
222
217
  */
223
218
  stopKeyDownEventPropagation?: boolean;
224
219
  /**
225
- * 在元素添加到页面前的事件
226
- * @param $shadowRoot 根元素
227
- * @param $shadowContainer 容器
220
+ * 可传入自定义事件监听器代替内部的eventEmitter
221
+ *
222
+ * 一般用于监听内部处理的事件
223
+ *
224
+ * 某些事件如:`pops:before-append-to-page`会提前触发,那么就需要自定义的监听器来监听
228
225
  */
229
- beforeAppendToPageCallBack?: ($shadowRoot: ShadowRoot | HTMLElement, $shadowContainer: HTMLDivElement) => void;
226
+ emitter?: EventEmiter | null | undefined;
230
227
  }
@@ -29,3 +29,5 @@ declare type DeepRequired<T> = T extends any[]
29
29
  declare type IPromise<T> = T | Promise<T>;
30
30
 
31
31
  declare type IFunction<T> = T | (() => T);
32
+
33
+ declare type IArray<T> = T | T[];
@@ -16,28 +16,28 @@ export interface PopsMaskConfig {
16
16
  */
17
17
  enable?: boolean;
18
18
  /**
19
- * 点击事件
19
+ * 点击事件配置
20
20
  */
21
21
  clickEvent?: {
22
22
  /**
23
- * 点击遮罩层是否触发关闭事件
23
+ * (可选)点击遮罩层是否触发关闭事件,默认false
24
24
  * @default false
25
25
  */
26
26
  toClose?: boolean;
27
27
  /**
28
- * 点击遮罩层是否触发隐藏事件
28
+ * (可选)点击遮罩层是否触发隐藏事件,默认false
29
29
  * @default false
30
30
  */
31
31
  toHide?: boolean;
32
32
  };
33
33
  /**
34
34
  * 遮罩层自定义的点击事件
35
- * @param originalRun 当toClose为true,它是关闭弹窗,当toHide为true,它是隐藏弹窗
36
- * @param config 配置信息
37
35
  */
38
36
  clickCallBack?:
39
37
  | ((
40
- originalRun: () => void | Promise<void>,
38
+ /** 当toClose为true,它是关闭弹窗,当toHide为true,它是隐藏弹窗 */
39
+ continueExec: () => void | Promise<void>,
40
+ /** 配置信息 */
41
41
  config:
42
42
  | PopsAlertConfig
43
43
  | PopsDrawerConfig
@@ -11,11 +11,14 @@ import type {
11
11
  PopsDOMUtilsCSSPropertyType,
12
12
  PopsDOMUtilsTargetElementType,
13
13
  } from "../types/PopsDOMUtilsEventType";
14
- import { SymbolEvents } from "./PopsDOMUtilsEventsConfig";
15
14
  import { OriginPrototype, PopsCore } from "../PopsCore";
16
15
  import { popsUtils } from "./PopsUtils";
17
16
  import { PopsSafeUtils } from "./PopsSafeUtils";
18
17
  import { PopsCommonCSSClassName } from "../config/CommonCSSClassName";
18
+ /**
19
+ * 存储在元素属性上的事件名
20
+ */
21
+ const SymbolEvents = Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1));
19
22
 
20
23
  class PopsDOMUtilsEvent {
21
24
  /**
@@ -1695,7 +1698,7 @@ class PopsDOMUtils extends PopsDOMUtilsEvent {
1695
1698
  * @param className className属性
1696
1699
  */
1697
1700
  addClassName(
1698
- $el: Element | undefined | null | undefined,
1701
+ $el: Element | undefined | null,
1699
1702
  className: string | string[] | (() => string | string[]) | undefined | null
1700
1703
  ) {
1701
1704
  if ($el == null) return;
@@ -1743,7 +1746,7 @@ class PopsDOMUtils extends PopsDOMUtilsEvent {
1743
1746
  * @param $el 目标元素
1744
1747
  * @param className className属性
1745
1748
  */
1746
- containsClassName($el: HTMLElement | undefined | null, className: string): boolean {
1749
+ containsClassName($el: Element | undefined | null, className: string): boolean {
1747
1750
  if ($el == null) {
1748
1751
  return false;
1749
1752
  }