@whitesev/pops 4.0.2 → 4.1.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 (76) hide show
  1. package/dist/index.amd.js +227 -141
  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 +227 -141
  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 +227 -141
  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 +227 -141
  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 +227 -141
  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 +227 -141
  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 +109 -10
  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/utils/PopsDOMUtils.d.ts +14 -2
  40. package/dist/types/src/utils/PopsUtils.d.ts +20 -15
  41. package/package.json +1 -1
  42. package/src/Pops.ts +3 -0
  43. package/src/components/alert/defaultConfig.ts +1 -1
  44. package/src/components/alert/index.ts +1 -1
  45. package/src/components/confirm/defaultConfig.ts +1 -1
  46. package/src/components/confirm/index.ts +1 -1
  47. package/src/components/drawer/defaultConfig.ts +1 -1
  48. package/src/components/drawer/index.ts +2 -1
  49. package/src/components/folder/defaultConfig.ts +1 -1
  50. package/src/components/folder/index.ts +1 -1
  51. package/src/components/iframe/defaultConfig.ts +1 -1
  52. package/src/components/iframe/index.ts +10 -6
  53. package/src/components/loading/defaultConfig.ts +1 -0
  54. package/src/components/loading/index.ts +10 -10
  55. package/src/components/loading/types/index.ts +1 -4
  56. package/src/components/panel/defaultConfig.ts +1 -1
  57. package/src/components/panel/index.ts +3 -2
  58. package/src/components/prompt/defaultConfig.ts +1 -1
  59. package/src/components/prompt/index.ts +1 -1
  60. package/src/components/rightClickMenu/defaultConfig.ts +1 -1
  61. package/src/components/rightClickMenu/index.ts +1 -1
  62. package/src/components/rightClickMenu/types/index.ts +1 -1
  63. package/src/components/searchSuggestion/defaultConfig.ts +1 -0
  64. package/src/components/searchSuggestion/index.ts +1 -1
  65. package/src/components/searchSuggestion/types/index.ts +1 -1
  66. package/src/components/tooltip/defaultConfig.ts +1 -1
  67. package/src/components/tooltip/index.ts +1 -1
  68. package/src/components/tooltip/types/index.ts +1 -1
  69. package/src/event/EventEmiter.ts +15 -14
  70. package/src/handler/PopsInstHandler.ts +64 -47
  71. package/src/types/EventEmitter.d.ts +21 -0
  72. package/src/types/PopsDOMUtilsEventType.d.ts +1 -1
  73. package/src/types/components.d.ts +15 -18
  74. package/src/types/global.d.ts +2 -0
  75. package/src/utils/PopsDOMUtils.ts +32 -2
  76. package/src/utils/PopsUtils.ts +94 -67
@@ -158,17 +158,26 @@ declare class PopsUtils {
158
158
  /**
159
159
  * 获取页面的坐标中最大的z-index的元素信息
160
160
  *
161
- * 其中坐标为
162
- *
163
- * + 左上角(宽: 1/8,高: 1/8)
164
- * + 右上角(宽: 7/8,高: 1/8)
165
- * + 左下角(宽: 1/8,高: 7/8)
166
- * + 右下角(宽: 7/8,高: 7/8)
167
- * + 中间(宽: 1/2,高: 1/2)
161
+ * 矩阵坐标计算
168
162
  * @param $el 仅检测目标元素最大的z-index(自动往上层找)
169
163
  * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少),默认为10
164
+ * @example
165
+ * Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"));
166
+ * @example
167
+ * Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"), 20);
168
+ * @example
169
+ * Utils.getMaxZIndexNodeInfoFromPoint([document.querySelector("a"), document.querySelector("div")]);
170
+ * @example
171
+ * Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500});
172
+ * @example
173
+ * Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500}, 20);
174
+ * @example
175
+ * Utils.getMaxZIndexNodeInfoFromPoint(() => {x: 500, y: 500}, 20);
170
176
  */
171
- getMaxZIndexNodeInfoFromPoint($el?: IFunction<HTMLElement | HTMLElement[]>, deviation?: number): {
177
+ getMaxZIndexNodeInfoFromPoint($el?: IFunction<IArray<HTMLElement> | IArray<{
178
+ x: number;
179
+ y: number;
180
+ }>>, deviation?: number): {
172
181
  /** 处理了偏移量后的z-index值 */
173
182
  zIndex: number;
174
183
  /** 原始z-index值 */
@@ -185,14 +194,10 @@ declare class PopsUtils {
185
194
  /**
186
195
  * 获取页面的坐标中最大的z-index的元素信息
187
196
  *
188
- * 其中坐标为
189
- *
190
- * + 左上角(宽: 1/8,高: 1/8)
191
- * + 右上角(宽: 7/8,高: 1/8)
192
- * + 左下角(宽: 1/8,高: 7/8)
193
- * + 右下角(宽: 7/8,高: 7/8)
194
- * + 中间(宽: 1/2,高: 1/2)
197
+ * 矩阵坐标计算
195
198
  * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少)
199
+ * @example
200
+ * Utils.getMaxZIndexNodeInfoFromPoint(20);
196
201
  */
197
202
  getMaxZIndexNodeInfoFromPoint(deviation: IFunction<number>): {
198
203
  /** 处理了偏移量后的z-index值 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/pops",
3
- "version": "4.0.2",
3
+ "version": "4.1.0",
4
4
  "description": "弹窗库,包含了alert、confirm、prompt、drawer、folder、loading、iframe、panel、tooltip、searchSuggestion、rightClickMenu组件",
5
5
  "keywords": [
6
6
  "ScriptCat",
package/src/Pops.ts CHANGED
@@ -22,6 +22,7 @@ import { PopsSearchSuggestion } from "./components/searchSuggestion";
22
22
  import type { PopsSearchSuggestionConfig } from "./components/searchSuggestion/types/index";
23
23
  import { PopsTooltip } from "./components/tooltip";
24
24
  import type { PopsToolTipConfig } from "./components/tooltip/types/index";
25
+ import { PopsCommonCSSClassName } from "./config/CommonCSSClassName";
25
26
  import { GlobalConfig } from "./config/GlobalConfig";
26
27
  import { EventEmiter } from "./event/EventEmiter";
27
28
  import { PopsInstHandler } from "./handler/PopsInstHandler";
@@ -69,6 +70,8 @@ class Pops {
69
70
  PopsAnimation,
70
71
  /** 事件类 */
71
72
  EventEmiter,
73
+ /** 通用的CSS类名 */
74
+ PopsCommonCSSClassName,
72
75
  };
73
76
  init() {}
74
77
  /**
@@ -59,7 +59,7 @@ export const PopsAlertDefaultConfig = (): DeepRequired<PopsAlertConfig> => {
59
59
  style: null,
60
60
  lightStyle: null,
61
61
  darkStyle: null,
62
- beforeAppendToPageCallBack() {},
63
62
  stopKeyDownEventPropagation: true,
63
+ emitter: null,
64
64
  } as DeepRequired<PopsAlertConfig>;
65
65
  };
@@ -16,13 +16,13 @@ export const PopsAlert = {
16
16
  const guid = popsUtils.getRandomGUID();
17
17
  // 设置当前类型
18
18
  const popsType: PopsType = "alert";
19
- const emitter = new EventEmiter<EventMap>(popsType);
20
19
 
21
20
  let config = PopsAlertDefaultConfig();
22
21
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
22
  config = popsUtils.assign(config, __config__);
24
23
  config = PopsHandler.handleOnly(popsType, config);
25
24
 
25
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
26
26
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
27
27
  PopsHandler.handleInit($shadowRoot, [
28
28
  {
@@ -87,7 +87,7 @@ export const PopsConfirmDefaultConfig = (): DeepRequired<PopsConfirmConfig> => {
87
87
  style: null,
88
88
  lightStyle: null,
89
89
  darkStyle: null,
90
- beforeAppendToPageCallBack() {},
91
90
  stopKeyDownEventPropagation: true,
91
+ emitter: null,
92
92
  } as DeepRequired<PopsConfirmConfig>;
93
93
  };
@@ -16,13 +16,13 @@ export const PopsConfirm = {
16
16
  const guid = popsUtils.getRandomGUID();
17
17
  // 设置当前类型
18
18
  const popsType: PopsType = "confirm";
19
- const emitter = new EventEmiter<EventMap>(popsType);
20
19
 
21
20
  let config = PopsConfirmDefaultConfig();
22
21
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
22
  config = popsUtils.assign(config, __config__);
24
23
  config = PopsHandler.handleOnly(popsType, config);
25
24
 
25
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
26
26
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
27
27
  PopsHandler.handleInit($shadowRoot, [
28
28
  {
@@ -85,8 +85,8 @@ export const PopsDrawerDefaultConfig = (): DeepRequired<PopsDrawerConfig> => {
85
85
  style: null,
86
86
  lightStyle: null,
87
87
  darkStyle: null,
88
- beforeAppendToPageCallBack() {},
89
88
  forbiddenScroll: false,
90
89
  stopKeyDownEventPropagation: true,
90
+ emitter: null,
91
91
  };
92
92
  };
@@ -16,12 +16,13 @@ export const PopsDrawer = {
16
16
  const guid = popsUtils.getRandomGUID();
17
17
  // 设置当前类型
18
18
  const popsType: PopsType = "drawer";
19
- const emitter = new EventEmiter<EventMap>(popsType);
20
19
 
21
20
  let config = PopsDrawerDefaultConfig();
22
21
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
22
  config = popsUtils.assign(config, __config__);
24
23
  config = PopsHandler.handleOnly(popsType, config);
24
+
25
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
25
26
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
26
27
  PopsHandler.handleInit($shadowRoot, [
27
28
  {
@@ -148,7 +148,7 @@ export const PopsFolderDefaultConfig = (): DeepRequired<PopsFolderConfig> => {
148
148
  style: null,
149
149
  lightStyle: null,
150
150
  darkStyle: null,
151
- beforeAppendToPageCallBack() {},
152
151
  stopKeyDownEventPropagation: true,
152
+ emitter: null,
153
153
  };
154
154
  };
@@ -19,13 +19,13 @@ export const PopsFolder = {
19
19
  const guid = popsUtils.getRandomGUID();
20
20
  // 设置当前类型
21
21
  const popsType: PopsType = "folder";
22
- const emitter = new EventEmiter<EventMap>(popsType);
23
22
 
24
23
  let config = PopsFolderDefaultConfig();
25
24
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
26
25
  config = popsUtils.assign(config, __config__);
27
26
  config = PopsHandler.handleOnly(popsType, config);
28
27
 
28
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
29
29
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
30
30
  PopsHandler.handleInit($shadowRoot, [
31
31
  {
@@ -57,7 +57,7 @@ export const PopsIframeDefaultConfig = (): DeepRequired<PopsIframeConfig> => {
57
57
  style: null,
58
58
  lightStyle: null,
59
59
  darkStyle: null,
60
- beforeAppendToPageCallBack() {},
61
60
  stopKeyDownEventPropagation: true,
61
+ emitter: null,
62
62
  };
63
63
  };
@@ -16,11 +16,7 @@ export const PopsIframe = {
16
16
  const guid = popsUtils.getRandomGUID();
17
17
  // 设置当前类型
18
18
  const popsType: PopsType = "iframe";
19
- const emitter = new EventEmiter<{
20
- "pops:iframe-min": (eventConfig: PopsIframeClickEventConfig, event: MouseEvent | PointerEvent) => void;
21
- "pops:iframe-mise": (eventConfig: PopsIframeClickEventConfig, event: MouseEvent | PointerEvent) => void;
22
- "pops:iframe-max": (eventConfig: PopsIframeClickEventConfig, event: MouseEvent | PointerEvent) => void;
23
- }>(popsType);
19
+
24
20
  let config = PopsIframeDefaultConfig();
25
21
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
26
22
  config = popsUtils.assign(config, __config__);
@@ -29,6 +25,13 @@ export const PopsIframe = {
29
25
  }
30
26
  config = PopsHandler.handleOnly(popsType, config);
31
27
 
28
+ const emitter =
29
+ config.emitter ??
30
+ new EventEmiter<{
31
+ "pops:iframe-min": (eventConfig: PopsIframeClickEventConfig, event: MouseEvent | PointerEvent) => void;
32
+ "pops:iframe-mise": (eventConfig: PopsIframeClickEventConfig, event: MouseEvent | PointerEvent) => void;
33
+ "pops:iframe-max": (eventConfig: PopsIframeClickEventConfig, event: MouseEvent | PointerEvent) => void;
34
+ }>(popsType);
32
35
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
33
36
  PopsHandler.handleInit($shadowRoot, [
34
37
  {
@@ -57,7 +60,8 @@ export const PopsIframe = {
57
60
  },
58
61
  ]);
59
62
 
60
- const maskExtraStyle = config.animation != null && <string>config.animation != "" ? "position:absolute;" : "";
63
+ const maskExtraStyle =
64
+ config.animation != null && <string>config.animation != "" && config.animation ? "position:absolute;" : "";
61
65
 
62
66
  // 先把z-index提取出来
63
67
  const zIndex = PopsHandler.getTargerOrFunctionValue(config.zIndex);
@@ -28,5 +28,6 @@ export const PopsLoadingDefaultConfig = (): DeepRequired<PopsLoadingConfig> => {
28
28
  darkStyle: null,
29
29
  addIndexCSS: true,
30
30
  stopKeyDownEventPropagation: true,
31
+ emitter: null,
31
32
  };
32
33
  };
@@ -13,14 +13,14 @@ export const PopsLoading = {
13
13
  init(__config__: PopsLoadingConfig) {
14
14
  const guid = popsUtils.getRandomGUID();
15
15
  // 设置当前类型
16
- const PopsType = "loading";
17
- const emitter = new EventEmiter<EventMap>(PopsType);
16
+ const popsType = "loading";
18
17
 
19
18
  let config = PopsLoadingDefaultConfig();
20
19
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
21
20
  config = popsUtils.assign(config, __config__);
22
- config = PopsHandler.handleOnly(PopsType, config);
21
+ config = PopsHandler.handleOnly(popsType, config);
23
22
 
23
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
24
24
  // 先把z-index提取出来
25
25
  const zIndex = PopsHandler.getTargerOrFunctionValue(config.zIndex);
26
26
  const maskHTML = PopsElementHandler.createMask(guid, zIndex);
@@ -28,10 +28,10 @@ export const PopsLoading = {
28
28
  const { contentPStyle } = PopsElementHandler.createContentStyle("loading", config);
29
29
  const animHTML = PopsElementHandler.createAnim(
30
30
  guid,
31
- PopsType,
31
+ popsType,
32
32
  config,
33
33
  /*html*/ `
34
- <div class="pops-content pops-${PopsType}-content">${
34
+ <div class="pops-content pops-${popsType}-content">${
35
35
  config.addIndexCSS
36
36
  ? /*html*/ `
37
37
  <style data-model-name="index">${PopsCSS.index}</style>
@@ -44,7 +44,7 @@ export const PopsLoading = {
44
44
  ${PopsCSS.loadingCSS}
45
45
  </style>
46
46
  ${config.style != null ? `<style>${config.style}</style>` : ""}
47
- <p pops class="pops-${PopsType}-content-text" style="${contentPStyle}">${config.content.text}</p>
47
+ <p pops class="pops-${popsType}-content-text" style="${contentPStyle}">${config.content.text}</p>
48
48
  </div>`,
49
49
  "",
50
50
  zIndex
@@ -56,7 +56,7 @@ export const PopsLoading = {
56
56
 
57
57
  const $anim = PopsElementHandler.parseElement<HTMLDivElement>(animHTML);
58
58
 
59
- const { $pops: $pops } = PopsHandler.handleQueryElement($anim, PopsType);
59
+ const { $pops: $pops } = PopsHandler.handleQueryElement($anim, popsType);
60
60
  /**
61
61
  * 遮罩层元素
62
62
  */
@@ -69,7 +69,7 @@ export const PopsLoading = {
69
69
  if (config.mask.enable) {
70
70
  // 创建遮罩层
71
71
  const handleMask = PopsHandler.handleMask({
72
- type: PopsType,
72
+ type: popsType,
73
73
  guid: guid,
74
74
 
75
75
  config: config,
@@ -79,12 +79,12 @@ export const PopsLoading = {
79
79
  $mask = handleMask.maskElement;
80
80
  $elList.push($mask);
81
81
  }
82
- const evtConfig = PopsHandler.handleLoadingEventConfig(config, guid, PopsType, $anim, $pops, emitter, $mask);
82
+ const evtConfig = PopsHandler.handleLoadingEventConfig(config, guid, popsType, $anim, $pops, emitter, $mask);
83
83
  popsDOMUtils.append(config.$parent, $elList);
84
84
  if ($mask != null) {
85
85
  $anim.after($mask);
86
86
  }
87
- PopsHandler.handlePush(PopsType, {
87
+ PopsHandler.handlePush(popsType, {
88
88
  $shadowContainer: $pops,
89
89
  $shadowRoot: $pops,
90
90
  guid: guid,
@@ -3,10 +3,7 @@ import type { PopsGeneralConfig, PopsContentConfig } from "../../../types/compon
3
3
  /**
4
4
  * pops.loading
5
5
  */
6
- export interface PopsLoadingConfig extends Omit<
7
- PopsGeneralConfig,
8
- "width" | "height" | "position" | "beforeAppendToPageCallBack"
9
- > {
6
+ export interface PopsLoadingConfig extends Omit<PopsGeneralConfig, "width" | "height" | "position"> {
10
7
  /**
11
8
  * 父元素,默认为document.body
12
9
  * @default document.body || document.documentElement
@@ -865,8 +865,8 @@ export const PopsPanelDefaultConfig = (): DeepRequired<PopsPanelConfig> => {
865
865
  style: null,
866
866
  lightStyle: null,
867
867
  darkStyle: null,
868
- beforeAppendToPageCallBack() {},
869
868
  stopKeyDownEventPropagation: true,
870
869
  listenEscapeKeyUpToExitDeepMenu: true,
870
+ emitter: null,
871
871
  };
872
872
  };
@@ -4,25 +4,26 @@ import { PopsElementHandler } from "../../handler/PopsElementHandler";
4
4
  import { PopsHandler } from "../../handler/PopsHandler";
5
5
  import { PopsInstHandler } from "../../handler/PopsInstHandler";
6
6
  import { PopsCSS } from "../../PopsCSS";
7
+ import type { EventMap } from "../../types/EventEmitter";
7
8
  import type { PopsType } from "../../types/main";
8
9
  import { popsDOMUtils } from "../../utils/PopsDOMUtils";
9
10
  import { popsUtils } from "../../utils/PopsUtils";
10
11
  import { PopsPanelDefaultConfig } from "./defaultConfig";
11
12
  import { PanelHandlerComponents } from "./handlerComponents";
12
- import type { PopsPanelConfig, PopsPanelEventType } from "./types";
13
+ import type { PopsPanelConfig } from "./types";
13
14
 
14
15
  export const PopsPanel = {
15
16
  init(__config__: PopsPanelConfig) {
16
17
  const guid = popsUtils.getRandomGUID();
17
18
  // 设置当前类型
18
19
  const popsType: PopsType = "panel";
19
- const emitter = new EventEmiter<PopsPanelEventType>(popsType);
20
20
 
21
21
  let config: Required<PopsPanelConfig> = PopsPanelDefaultConfig();
22
22
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
23
  config = popsUtils.assign(config, __config__);
24
24
  config = PopsHandler.handleOnly(popsType, config);
25
25
 
26
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
26
27
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
27
28
  PopsHandler.handleInit($shadowRoot, [
28
29
  {
@@ -91,7 +91,7 @@ export const PopsPromptDefaultConfig = (): DeepRequired<PopsPromptConfig> => {
91
91
  style: null,
92
92
  lightStyle: null,
93
93
  darkStyle: null,
94
- beforeAppendToPageCallBack() {},
95
94
  stopKeyDownEventPropagation: true,
95
+ emitter: null,
96
96
  };
97
97
  };
@@ -16,13 +16,13 @@ export const PopsPrompt = {
16
16
  const guid = popsUtils.getRandomGUID();
17
17
  // 设置当前类型
18
18
  const popsType: PopsType = "prompt";
19
- const emitter = new EventEmiter<EventMap>(popsType);
20
19
 
21
20
  let config = PopsPromptDefaultConfig();
22
21
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
22
  config = popsUtils.assign(config, __config__);
24
23
  config = PopsHandler.handleOnly(popsType, config);
25
24
 
25
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
26
26
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
27
27
  PopsHandler.handleInit($shadowRoot, [
28
28
  {
@@ -97,9 +97,9 @@ export const PopsRightClickMenuDefaultConfig = (): DeepRequired<PopsRightClickMe
97
97
  style: null,
98
98
  lightStyle: null,
99
99
  darkStyle: null,
100
- beforeAppendToPageCallBack() {},
101
100
  limitPositionXInView: true,
102
101
  limitPositionYInView: true,
103
102
  beforeShowCallBack() {},
103
+ emitter: null,
104
104
  };
105
105
  };
@@ -24,13 +24,13 @@ export const PopsRightClickMenu = {
24
24
  const guid = popsUtils.getRandomGUID();
25
25
  // 设置当前类型
26
26
  const popsType: PopsType = "rightClickMenu";
27
- const emitter = new EventEmiter<EventMap>(popsType);
28
27
 
29
28
  let config = PopsRightClickMenuDefaultConfig();
30
29
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
31
30
  config = popsUtils.assign(config, __config__);
32
31
  config = PopsHandler.handleOnly(popsType, config);
33
32
 
33
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
34
34
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
35
35
  PopsHandler.handleInit($shadowRoot, [
36
36
  {
@@ -70,7 +70,7 @@ export interface PopsRightClickMenuDataConfig {
70
70
  */
71
71
  export interface PopsRightClickMenuConfig extends Pick<
72
72
  PopsGeneralConfig,
73
- "useShadowRoot" | "beforeAppendToPageCallBack" | "zIndex" | "style" | "lightStyle" | "darkStyle" | "only"
73
+ "useShadowRoot" | "zIndex" | "style" | "lightStyle" | "darkStyle" | "only" | "emitter"
74
74
  > {
75
75
  /**
76
76
  * 目标元素
@@ -61,5 +61,6 @@ export const PopsSearchSuggestionDefaultConfig = (): DeepRequired<PopsSearchSugg
61
61
  style: "",
62
62
  lightStyle: null,
63
63
  darkStyle: null,
64
+ emitter: null,
64
65
  };
65
66
  };
@@ -17,7 +17,6 @@ export const PopsSearchSuggestion = {
17
17
  const guid = popsUtils.getRandomGUID();
18
18
  // 设置当前类型
19
19
  const popsType: PopsType = "searchSuggestion";
20
- const emitter = new EventEmiter<EventMap>(popsType);
21
20
 
22
21
  let config = PopsSearchSuggestionDefaultConfig();
23
22
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
@@ -27,6 +26,7 @@ export const PopsSearchSuggestion = {
27
26
  config.$inputTarget = config.$target as HTMLInputElement;
28
27
  }
29
28
 
29
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
30
30
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
31
31
  PopsHandler.handleInit($shadowRoot, [
32
32
  {
@@ -106,7 +106,7 @@ export type PopsSearchSuggestionData<T> = {
106
106
  */
107
107
  export interface PopsSearchSuggestionConfig<T = any> extends Pick<
108
108
  PopsGeneralConfig,
109
- "useShadowRoot" | "zIndex" | "style" | "lightStyle" | "darkStyle"
109
+ "useShadowRoot" | "zIndex" | "style" | "lightStyle" | "darkStyle" | "emitter"
110
110
  > {
111
111
  /**
112
112
  * 当前的环境,可以是document,可以是shadowroot,默认是document
@@ -30,6 +30,6 @@ export const PopsTooltipDefaultConfig = (): DeepRequired<PopsToolTipConfig> => {
30
30
  style: "",
31
31
  lightStyle: null,
32
32
  darkStyle: null,
33
- beforeAppendToPageCallBack() {},
33
+ emitter: null,
34
34
  };
35
35
  };
@@ -558,7 +558,6 @@ export const PopsTooltip = {
558
558
  const guid = popsUtils.getRandomGUID();
559
559
  // 设置当前类型
560
560
  const popsType: PopsType = "tooltip";
561
- const emitter = new EventEmiter<EventMap>(popsType);
562
561
 
563
562
  let config = PopsTooltipDefaultConfig();
564
563
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
@@ -577,6 +576,7 @@ export const PopsTooltip = {
577
576
  });
578
577
  }
579
578
 
579
+ const emitter = config.emitter ?? new EventEmiter<EventMap>(popsType);
580
580
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
581
581
  PopsHandler.handleInit($shadowRoot, [
582
582
  {
@@ -9,7 +9,7 @@ export type PopsTooltipPosition = "top" | "right" | "bottom" | "left" | "follow"
9
9
  */
10
10
  export interface PopsToolTipConfig extends Pick<
11
11
  PopsGeneralConfig,
12
- "useShadowRoot" | "only" | "zIndex" | "style" | "lightStyle" | "darkStyle" | "beforeAppendToPageCallBack"
12
+ "useShadowRoot" | "only" | "zIndex" | "style" | "lightStyle" | "darkStyle" | "emitter"
13
13
  > {
14
14
  /**
15
15
  * 目标元素
@@ -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
  }