@whitesev/pops 3.3.5 → 4.0.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 (81) hide show
  1. package/dist/index.amd.js +13118 -12932
  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 +761 -575
  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 +761 -575
  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 +13119 -12933
  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 +13122 -12936
  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 +13121 -12935
  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 +66 -52
  26. package/dist/types/src/PopsAnimation.d.ts +33 -0
  27. package/dist/types/src/PopsIcon.d.ts +1 -1
  28. package/dist/types/src/components/alert/index.d.ts +3 -1
  29. package/dist/types/src/components/confirm/index.d.ts +3 -1
  30. package/dist/types/src/components/drawer/index.d.ts +3 -1
  31. package/dist/types/src/components/folder/index.d.ts +3 -1
  32. package/dist/types/src/components/iframe/index.d.ts +6 -1
  33. package/dist/types/src/components/iframe/types/index.d.ts +4 -2
  34. package/dist/types/src/components/loading/index.d.ts +3 -1
  35. package/dist/types/src/components/panel/handlerComponents.d.ts +4 -1
  36. package/dist/types/src/components/panel/index.d.ts +2 -16
  37. package/dist/types/src/components/panel/types/index.d.ts +7 -2
  38. package/dist/types/src/components/prompt/index.d.ts +3 -1
  39. package/dist/types/src/components/searchSuggestion/index.d.ts +4 -1
  40. package/dist/types/src/components/tooltip/index.d.ts +5 -1
  41. package/dist/types/src/event/EventEmiter.d.ts +33 -0
  42. package/dist/types/src/handler/PopsHandler.d.ts +16 -11
  43. package/dist/types/src/handler/PopsInstHandler.d.ts +67 -0
  44. package/dist/types/src/types/EventEmitter.d.ts +18 -0
  45. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +4 -0
  46. package/dist/types/src/types/button.d.ts +2 -1
  47. package/dist/types/src/types/event.d.ts +6 -2
  48. package/dist/types/src/types/inst.d.ts +4 -4
  49. package/dist/types/src/utils/PopsDOMUtils.d.ts +0 -16
  50. package/dist/types/src/utils/PopsInstanceUtils.d.ts +0 -88
  51. package/dist/types/src/utils/PopsUtils.d.ts +57 -0
  52. package/package.json +3 -3
  53. package/src/Pops.ts +7 -2
  54. package/src/PopsAnimation.ts +126 -0
  55. package/src/components/alert/index.ts +9 -9
  56. package/src/components/confirm/index.ts +9 -9
  57. package/src/components/drawer/index.ts +12 -9
  58. package/src/components/folder/index.ts +9 -8
  59. package/src/components/iframe/index.ts +18 -12
  60. package/src/components/iframe/types/index.ts +10 -8
  61. package/src/components/loading/index.ts +12 -6
  62. package/src/components/panel/defaultConfig.ts +1 -0
  63. package/src/components/panel/handlerComponents.ts +41 -111
  64. package/src/components/panel/index.ts +34 -28
  65. package/src/components/panel/types/index.ts +7 -2
  66. package/src/components/prompt/index.ts +9 -8
  67. package/src/components/rightClickMenu/index.ts +17 -14
  68. package/src/components/searchSuggestion/index.ts +5 -1
  69. package/src/components/tooltip/index.ts +20 -10
  70. package/src/event/EventEmiter.ts +95 -0
  71. package/src/handler/PopsElementHandler.ts +6 -4
  72. package/src/handler/PopsHandler.ts +66 -48
  73. package/src/handler/PopsInstHandler.ts +557 -0
  74. package/src/types/EventEmitter.d.ts +18 -0
  75. package/src/types/PopsDOMUtilsEventType.d.ts +4 -0
  76. package/src/types/button.d.ts +2 -1
  77. package/src/types/event.d.ts +6 -2
  78. package/src/types/inst.d.ts +4 -4
  79. package/src/utils/PopsDOMUtils.ts +1 -40
  80. package/src/utils/PopsInstanceUtils.ts +19 -627
  81. package/src/utils/PopsUtils.ts +194 -0
@@ -0,0 +1,67 @@
1
+ import type { PopsAlertConfig } from "../components/alert/types";
2
+ import type { PopsConfirmConfig } from "../components/confirm/types";
3
+ import type { PopsDrawerConfig } from "../components/drawer/types";
4
+ import type { PopsFolderConfig } from "../components/folder/types";
5
+ import type { PopsIframeConfig } from "../components/iframe/types";
6
+ import type { PopsLoadingConfig } from "../components/loading/types";
7
+ import type { PopsPanelConfig } from "../components/panel/types";
8
+ import type { PopsPromptConfig } from "../components/prompt/types";
9
+ import type { PopsInstGeneralConfig } from "../types/inst";
10
+ import type { PopsInstStoreType } from "../types/main";
11
+ export declare const PopsInstHandler: {
12
+ /**
13
+ * 删除配置中对应的对象
14
+ * @param totalInstConfigList 配置实例列表
15
+ * @param guid 唯一标识
16
+ * @param isAll 是否全部删除
17
+ */
18
+ removeInstance(totalInstConfigList: PopsInstGeneralConfig[][], guid?: string, isAll?: boolean): Promise<PopsInstGeneralConfig[][]>;
19
+ /**
20
+ * 隐藏
21
+ * @param popsType
22
+ * @param instConfigList
23
+ * @param guid
24
+ * @param config
25
+ * @param $anim
26
+ * @param $mask
27
+ */
28
+ hide(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, popsType: PopsInstStoreType, instConfigList: PopsInstGeneralConfig[], guid: string, $anim: HTMLElement, $mask?: HTMLElement): Promise<void>;
29
+ /**
30
+ * 显示
31
+ * @param popsType
32
+ * @param instConfigList
33
+ * @param guid
34
+ * @param config
35
+ * @param $anim
36
+ * @param $mask
37
+ */
38
+ show(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, popsType: PopsInstStoreType, instConfigList: PopsInstGeneralConfig[], guid: string, $anim: HTMLElement, $mask?: HTMLElement): Promise<void>;
39
+ /**
40
+ * 关闭
41
+ * @param popsType
42
+ * @param instConfigList
43
+ * @param guid
44
+ * @param config
45
+ * @param $anim
46
+ */
47
+ close(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, popsType: string, instConfigList: PopsInstGeneralConfig[], guid: string, $anim: HTMLElement): Promise<void>;
48
+ /**
49
+ * 拖拽元素
50
+ * 说明:
51
+ * + 元素的position为absolute或者fixed
52
+ * + 会为元素的
53
+ * @param $move 需要拖拽的元素
54
+ * @param options 配置
55
+ */
56
+ drag($move: HTMLElement, options: {
57
+ dragElement: HTMLElement;
58
+ limit: boolean;
59
+ emitClick?: boolean;
60
+ extraDistance: number;
61
+ container?: Window | typeof globalThis | HTMLElement;
62
+ startCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
63
+ moveCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
64
+ endCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
65
+ preventEvent?: (event: TouchEvent | PointerEvent) => boolean;
66
+ }): void;
67
+ };
@@ -0,0 +1,18 @@
1
+ import type { PopsInstGeneralConfig } from "./inst";
2
+
3
+ export type EventMap = {
4
+ "pops:before-show": (config: PopsInstGeneralConfig) => IPromise<void>;
5
+ "pops:show": (config: PopsInstGeneralConfig) => IPromise<void>;
6
+ "pops:before-hide": (config: PopsInstGeneralConfig) => IPromise<void>;
7
+ "pops:hide": (config: PopsInstGeneralConfig) => IPromise<void>;
8
+ "pops:before-destory": (config: PopsInstGeneralConfig) => IPromise<void>;
9
+ "pops:destory": () => IPromise<void>;
10
+ "pops:before-append-to-page": (
11
+ $shadowRoot: ShadowRoot | HTMLElement,
12
+ $shadowContainer: HTMLDivElement
13
+ ) => IPromise<void>;
14
+ };
15
+
16
+ export type CustomEventMap = {
17
+ [K in string]: (...args: any[]) => IPromise<void>;
18
+ };
@@ -34,6 +34,10 @@ export type PopsDOMUtils_MouseEventType = keyof PopsDOMUtils_MouseEvent;
34
34
  */
35
35
  export interface PopsDOMUtils_KeyboardEvent {
36
36
  keydown: KeyboardEvent;
37
+ /**
38
+ * @link https://developer.mozilla.org/zh-CN/docs/Web/API/Element/keypress_event
39
+ * @deprecated
40
+ */
37
41
  keypress: KeyboardEvent;
38
42
  keyup: KeyboardEvent;
39
43
  }
@@ -1,3 +1,4 @@
1
+ import type { EventEmiter } from "../event/EventEmiter";
1
2
  import type { PopsEventConfig, PopsHandlerEventConfig } from "./event";
2
3
  import type { PopsIconType } from "./icon";
3
4
 
@@ -63,7 +64,7 @@ export interface PopsGlobalButtonConfig<T = object> {
63
64
  *
64
65
  * 如果传入该值,那么将不会自动关闭弹窗
65
66
  */
66
- callback(eventConfig: PopsHandlerEventConfig & T, event: PointerEvent | MouseEvent): void;
67
+ callback(eventConfig: PopsHandlerEventConfig<EventEmiter> & T, event: PointerEvent | MouseEvent): void;
67
68
  }
68
69
 
69
70
  /**
@@ -1,9 +1,11 @@
1
+ import type { EventEmiter } from "../event/EventEmiter";
2
+ import type { CustomEventMap } from "./EventEmitter";
1
3
  import type { PopsType } from "./main";
2
4
 
3
5
  /**
4
6
  * 事件配置
5
7
  */
6
- export interface PopsEventConfig {
8
+ export interface PopsEventConfig<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>> {
7
9
  /** 最外层包裹的元素 */
8
10
  $shadowContainer: HTMLDivElement;
9
11
  /** ShadowRoot */
@@ -20,6 +22,8 @@ export interface PopsEventConfig {
20
22
  mode: PopsType;
21
23
  /** 唯一id */
22
24
  guid: string;
25
+ /** 事件发送器 */
26
+ emitter: E;
23
27
  /**
24
28
  * 关闭弹窗
25
29
  */
@@ -37,7 +41,7 @@ export interface PopsEventConfig {
37
41
  /**
38
42
  * 处理过的事件配置
39
43
  */
40
- export interface PopsHandlerEventConfig extends PopsEventConfig {
44
+ export interface PopsHandlerEventConfig<E extends EventEmiter<CustomEventMap>> extends PopsEventConfig<E> {
41
45
  /** 当前按钮类型 */
42
46
  type: "cancel" | "close" | "ok" | "other";
43
47
  }
@@ -1,3 +1,5 @@
1
+ import type { EventEmiter } from "../event/EventEmiter";
2
+
1
3
  /**
2
4
  * config实例配置
3
5
  */
@@ -19,10 +21,8 @@ export interface PopsInstGeneralConfig extends PopsInstConfig {
19
21
  $shadowContainer: HTMLDivElement;
20
22
  /** shadow容器的shandowRoot */
21
23
  $shadowRoot: ShadowRoot | HTMLElement;
22
- /** 移除实例前的回调函数 */
23
- beforeRemoveCallBack?: (instCommonConfig: PopsInstGeneralConfig) => void;
24
24
  /** 配置 */
25
25
  config: any;
26
- /** 销毁元素 */
27
- destory(): void | Promise<void>;
26
+ /** 事件发送器 */
27
+ emitter: EventEmiter;
28
28
  }
@@ -289,22 +289,6 @@ declare class PopsDOMUtilsEvent {
289
289
  * })
290
290
  */
291
291
  onKeydown(target: HTMLElement | Window | typeof globalThis | string, handler: (event: PopsDOMUtils_Event["keydown"]) => void, option?: boolean | AddEventListenerOptions): PopsDOMUtilsAddEventListenerResult | undefined;
292
- /**
293
- * 当按键按下时触发事件
294
- * keydown - > keypress - > keyup
295
- * @param target 目标
296
- * @param handler 事件处理函数
297
- * @param option 配置
298
- * @example
299
- * // 监听a.xx元素的按键按下
300
- * DOMUtils.keypress(document.querySelector("a.xx"),()=>{
301
- * console.log("按键按下");
302
- * })
303
- * DOMUtils.keypress("a.xx",()=>{
304
- * console.log("按键按下");
305
- * })
306
- */
307
- onKeypress(target: HTMLElement | Window | typeof globalThis | string, handler: (event: PopsDOMUtils_Event["keypress"]) => void, option?: boolean | AddEventListenerOptions): PopsDOMUtilsAddEventListenerResult | undefined;
308
292
  /**
309
293
  * 阻止事件传递
310
294
  *
@@ -1,30 +1,4 @@
1
- import type { PopsAlertConfig } from "../components/alert/types";
2
- import type { PopsConfirmConfig } from "../components/confirm/types";
3
- import type { PopsDrawerConfig } from "../components/drawer/types";
4
- import type { PopsFolderConfig } from "../components/folder/types";
5
- import type { PopsIframeConfig } from "../components/iframe/types";
6
- import type { PopsLoadingConfig } from "../components/loading/types";
7
- import type { PopsPanelConfig } from "../components/panel/types";
8
- import type { PopsPromptConfig } from "../components/prompt/types/index";
9
- import type { PopsInstGeneralConfig } from "../types/inst";
10
- import type { PopsInstStoreType } from "../types/main";
11
1
  export declare const PopsInstanceUtils: {
12
- /**
13
- * 获取页面中最大的z-index的元素信息
14
- * @param deviation 获取最大的z-index值的偏移,默认是+1
15
- * @param node 进行判断的元素,默认是document
16
- * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
17
- * @example
18
- * Utils.getMaxZIndexNodeInfo();
19
- * > {
20
- * node: ...,
21
- * zIndex: 1001
22
- * }
23
- **/
24
- getMaxZIndexNodeInfo(deviation?: number, target?: Element | ShadowRoot | Document, ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void): {
25
- node: Element;
26
- zIndex: number;
27
- };
28
2
  /**
29
3
  * 获取pops所有弹窗中的最大的z-index
30
4
  * @param deviation
@@ -34,68 +8,6 @@ export declare const PopsInstanceUtils: {
34
8
  animElement: HTMLDivElement | null;
35
9
  isOverMaxZIndex: boolean;
36
10
  };
37
- /**
38
- * 获取页面中最大的z-index
39
- * @param deviation 获取最大的z-index值的偏移,默认是+1
40
- * @example
41
- * getMaxZIndex();
42
- * > 1001
43
- **/
44
- getMaxZIndex(deviation?: number): number;
45
- /**
46
- * 删除配置中对应的对象
47
- * @param totalInstConfigList 配置实例列表
48
- * @param guid 唯一标识
49
- * @param isAll 是否全部删除
50
- */
51
- removeInstance(totalInstConfigList: PopsInstGeneralConfig[][], guid?: string, isAll?: boolean): Promise<PopsInstGeneralConfig[][]>;
52
- /**
53
- * 隐藏
54
- * @param popsType
55
- * @param instConfigList
56
- * @param guid
57
- * @param config
58
- * @param $anim
59
- * @param $mask
60
- */
61
- hide(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, popsType: PopsInstStoreType, instConfigList: PopsInstGeneralConfig[], guid: string, $anim: HTMLElement, $mask?: HTMLElement): Promise<void>;
62
- /**
63
- * 显示
64
- * @param popsType
65
- * @param instConfigList
66
- * @param guid
67
- * @param config
68
- * @param $anim
69
- * @param $mask
70
- */
71
- show(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, popsType: PopsInstStoreType, instConfigList: PopsInstGeneralConfig[], guid: string, $anim: HTMLElement, $mask?: HTMLElement): Promise<void>;
72
- /**
73
- * 关闭
74
- * @param popsType
75
- * @param instConfigList
76
- * @param guid
77
- * @param config
78
- * @param $anim
79
- */
80
- close(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, popsType: string, instConfigList: PopsInstGeneralConfig[], guid: string, $anim: HTMLElement): Promise<void>;
81
- /**
82
- * 拖拽元素
83
- * 说明:
84
- * + 元素的position为absolute或者fixed
85
- * + 会为元素的
86
- * @param $move 需要拖拽的元素
87
- * @param options 配置
88
- */
89
- drag($move: HTMLElement, options: {
90
- dragElement: HTMLElement;
91
- limit: boolean;
92
- emitClick?: boolean;
93
- extraDistance: number;
94
- container?: Window | typeof globalThis | HTMLElement;
95
- moveCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
96
- endCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
97
- preventEvent?: (event: TouchEvent | PointerEvent) => boolean;
98
- }): void;
99
11
  /**
100
12
  * 排序数组
101
13
  * @param getBeforeValueFun
@@ -1,6 +1,10 @@
1
1
  import AnyTouch from "any-touch";
2
2
  import doubletap from "@any-touch/doubletap";
3
3
  declare class PopsUtils {
4
+ /**
5
+ * 超时时间
6
+ */
7
+ sleep(timeout: number): Promise<unknown>;
4
8
  /**
5
9
  * 判断是否是window,例如window、self、globalThis
6
10
  * @param target
@@ -151,6 +155,59 @@ declare class PopsUtils {
151
155
  * 覆盖对象中的数组新值
152
156
  */
153
157
  setArray<T>(target: T, key: keyof T, newArr: any[]): void;
158
+ /**
159
+ * 获取页面的坐标中最大的z-index的元素信息
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)
168
+ * @param $el 仅检测目标元素最大的z-index(自动往上层找)
169
+ * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少),默认为10
170
+ */
171
+ getMaxZIndexNodeInfoFromPoint($el?: IFunction<HTMLElement | HTMLElement[]>, deviation?: number): {
172
+ /** 处理了偏移量后的z-index值 */
173
+ zIndex: number;
174
+ /** 原始z-index值 */
175
+ originZIndex: number;
176
+ /** 拥有最大z-index的元素 */
177
+ node: HTMLElement | null;
178
+ /** 目标坐标元素 */
179
+ positionNode: HTMLElement;
180
+ /** x坐标 */
181
+ positionX: number;
182
+ /** y坐标 */
183
+ positionY: number;
184
+ }[];
185
+ /**
186
+ * 获取页面的坐标中最大的z-index的元素信息
187
+ *
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)
195
+ * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少)
196
+ */
197
+ getMaxZIndexNodeInfoFromPoint(deviation: IFunction<number>): {
198
+ /** 处理了偏移量后的z-index值 */
199
+ zIndex: number;
200
+ /** 原始z-index值 */
201
+ originZIndex: number;
202
+ /** 拥有最大z-index的元素 */
203
+ node: HTMLElement | null;
204
+ /** 目标坐标元素 */
205
+ positionNode: HTMLElement;
206
+ /** x坐标 */
207
+ positionX: number;
208
+ /** y坐标 */
209
+ positionY: number;
210
+ }[];
154
211
  }
155
212
  declare const popsUtils: PopsUtils;
156
213
  export { popsUtils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/pops",
3
- "version": "3.3.5",
3
+ "version": "4.0.0",
4
4
  "description": "弹窗库,包含了alert、confirm、prompt、drawer、folder、loading、iframe、panel、tooltip、searchSuggestion、rightClickMenu组件",
5
5
  "keywords": [
6
6
  "ScriptCat",
@@ -57,8 +57,8 @@
57
57
  "eslint-plugin-compat": "^6.0.2",
58
58
  "eslint-plugin-prettier": "^5.5.4",
59
59
  "globals": "^16.5.0",
60
- "oxfmt": "^0.35.0",
61
- "oxlint": "1.50.0",
60
+ "oxfmt": "^0.36.0",
61
+ "oxlint": "1.51.0",
62
62
  "rollup": "^4.54.0",
63
63
  "rollup-plugin-clear": "^2.0.7",
64
64
  "rollup-plugin-import-css": "^4.1.2",
package/src/Pops.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { version } from "../package.json";
1
2
  import { PopsAlert } from "./components/alert";
2
3
  import type { PopsAlertConfig } from "./components/alert/types";
3
4
  import { PopsConfirm } from "./components/confirm";
@@ -22,6 +23,7 @@ import type { PopsSearchSuggestionConfig } from "./components/searchSuggestion/t
22
23
  import { PopsTooltip } from "./components/tooltip";
23
24
  import type { PopsToolTipConfig } from "./components/tooltip/types/index";
24
25
  import { GlobalConfig } from "./config/GlobalConfig";
26
+ import { EventEmiter } from "./event/EventEmiter";
25
27
  import { PopsAnimation } from "./PopsAnimation";
26
28
  import { PopsCore } from "./PopsCore";
27
29
  import { PopsCSS } from "./PopsCSS";
@@ -31,7 +33,6 @@ import { popsDOMUtils } from "./utils/PopsDOMUtils";
31
33
  import { PopsInstanceUtils } from "./utils/PopsInstanceUtils";
32
34
  import { PopsMathFloatUtils } from "./utils/PopsMathUtils";
33
35
  import { popsUtils } from "./utils/PopsUtils";
34
- import { version } from "../package.json";
35
36
 
36
37
  class Pops {
37
38
  /** 配置 */
@@ -60,7 +61,11 @@ class Pops {
60
61
  /** pops处理float类型使用的工具类 */
61
62
  MathFloatUtils: PopsMathFloatUtils,
62
63
  /** pops.panel中用于处理各个类型的工具 */
63
- PanelHandlerComponents: PanelHandlerComponents,
64
+ PanelHandlerComponents,
65
+ /** pops.panel中的动画 */
66
+ PopsAnimation,
67
+ /** 事件类 */
68
+ EventEmiter,
64
69
  };
65
70
  init() {}
66
71
  /**
@@ -29,4 +29,130 @@ export const PopsAnimation = {
29
29
  hasAnim(name: string) {
30
30
  return Object.prototype.hasOwnProperty.call(this.$data, name);
31
31
  },
32
+ /**
33
+ * 带动画的进入元素
34
+ * @param $el 当前元素
35
+ * @param $next 切换的元素
36
+ * @param option 配置
37
+ */
38
+ createSwitchElementWithAnimation(
39
+ $el: HTMLElement,
40
+ $next: HTMLElement,
41
+ option: {
42
+ /**
43
+ * 是否使用动画
44
+ * @default true
45
+ */
46
+ useAnimation?: boolean;
47
+ /**
48
+ * 动画配置
49
+ *
50
+ * + `duration`: 默认`220`
51
+ * + `easing`: 默认`"ease-in-out"`
52
+ */
53
+ animOptions?: KeyframeAnimationOptions;
54
+ /** 为$next内部添加元素 */
55
+ enterToAddElementCallback: () => IPromise<void>;
56
+ /** 退出时移除$next元素 */
57
+ exitToRemoveElementCallback?: () => IPromise<void>;
58
+ }
59
+ ) {
60
+ const animOptions: KeyframeAnimationOptions = {
61
+ // 150 220 300
62
+ duration: 220,
63
+ easing: "ease-in-out",
64
+ ...(option.animOptions ?? {}),
65
+ };
66
+ if (option.useAnimation == null) {
67
+ option.useAnimation = true;
68
+ }
69
+ return {
70
+ /**
71
+ * 进入
72
+ */
73
+ async enter() {
74
+ const transitionEndCallback = async () => {
75
+ // 先直接隐藏旧的容器
76
+ popsDOMUtils.cssHide($el, true);
77
+ // 添加元素
78
+ await option.enterToAddElementCallback();
79
+ };
80
+ // 进入下一层
81
+ if (option.useAnimation && typeof document.startViewTransition == "function") {
82
+ // 处理添加的元素的动画
83
+ const transition = document.startViewTransition(transitionEndCallback);
84
+ await transition.ready;
85
+ await $next.animate(
86
+ // 从右向左移入(进入动画)
87
+ [
88
+ {
89
+ // from
90
+ transform: "translateX(100%)",
91
+ },
92
+ {
93
+ // to
94
+ transform: "translateX(0)",
95
+ },
96
+ ],
97
+ animOptions
98
+ ).finished;
99
+ await transition.finished;
100
+ } else {
101
+ await transitionEndCallback();
102
+ }
103
+ },
104
+ /**
105
+ * 退出
106
+ */
107
+ async exit() {
108
+ // 返回上一层菜单
109
+ const transitionEndCallback = async () => {
110
+ // 显示上层菜单
111
+ popsDOMUtils.cssShow($el);
112
+ // 移除下一层的菜单
113
+ $next.remove();
114
+ if (typeof option.exitToRemoveElementCallback === "function") {
115
+ await option.exitToRemoveElementCallback();
116
+ }
117
+ };
118
+ if (option.useAnimation && typeof document.startViewTransition == "function") {
119
+ const leaveTransition = document.startViewTransition(transitionEndCallback);
120
+ await leaveTransition.ready;
121
+ await Promise.all([
122
+ // 从原位置向右移出
123
+ $next.animate(
124
+ [
125
+ {
126
+ // from
127
+ transform: "translateX(0)",
128
+ },
129
+ {
130
+ // to
131
+ transform: "translateX(100%)",
132
+ },
133
+ ],
134
+ animOptions
135
+ ).finished,
136
+ // 从最左边向右移入
137
+ $el.animate(
138
+ [
139
+ {
140
+ // from
141
+ transform: "translateX(-100%)",
142
+ },
143
+ {
144
+ // to
145
+ transform: "translateX(0)",
146
+ },
147
+ ],
148
+ animOptions
149
+ ).finished,
150
+ ]);
151
+ await leaveTransition.finished;
152
+ } else {
153
+ await transitionEndCallback();
154
+ }
155
+ },
156
+ };
157
+ },
32
158
  };
@@ -1,10 +1,12 @@
1
1
  import { GlobalConfig } from "../../config/GlobalConfig";
2
+ import { EventEmiter } from "../../event/EventEmiter";
2
3
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
3
4
  import { PopsHandler } from "../../handler/PopsHandler";
5
+ import { PopsInstHandler } from "../../handler/PopsInstHandler";
4
6
  import { PopsCSS } from "../../PopsCSS";
7
+ import type { EventMap } from "../../types/EventEmitter";
5
8
  import type { PopsType } from "../../types/main";
6
9
  import { popsDOMUtils } from "../../utils/PopsDOMUtils";
7
- import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
8
10
  import { popsUtils } from "../../utils/PopsUtils";
9
11
  import { PopsAlertDefaultConfig } from "./defaultConfig";
10
12
  import type { PopsAlertConfig } from "./types";
@@ -14,6 +16,7 @@ export const PopsAlert = {
14
16
  const guid = popsUtils.getRandomGUID();
15
17
  // 设置当前类型
16
18
  const popsType: PopsType = "alert";
19
+ const emitter = new EventEmiter<EventMap>(popsType);
17
20
 
18
21
  let config = PopsAlertDefaultConfig();
19
22
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
@@ -53,7 +56,7 @@ export const PopsAlert = {
53
56
  ]);
54
57
 
55
58
  // 先把z-index提取出来
56
- const zIndex = PopsHandler.handleZIndex(config.zIndex);
59
+ const zIndex = PopsHandler.getTargerOrFunctionValue(config.zIndex);
57
60
  const maskHTML = PopsElementHandler.createMask(guid, zIndex);
58
61
  const headerBtnHTML = PopsElementHandler.createHeader(popsType, config);
59
62
  const bottomBtnHTML = PopsElementHandler.createBottom(popsType, config);
@@ -116,6 +119,7 @@ export const PopsAlert = {
116
119
  popsType,
117
120
  $anim,
118
121
  $pops,
122
+ emitter,
119
123
  $mask
120
124
  );
121
125
  const result = PopsHandler.handleResultConfig(evtConfig);
@@ -125,12 +129,8 @@ export const PopsAlert = {
125
129
  PopsHandler.handleClickEvent("ok", btnOkElement, evtConfig, config.btn.ok?.callback);
126
130
 
127
131
  // 创建到页面中
128
-
129
132
  popsDOMUtils.append($shadowRoot, $elList);
130
- if (typeof config.beforeAppendToPageCallBack === "function") {
131
- config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
132
- }
133
-
133
+ emitter.emit("pops:before-append-to-page", $shadowRoot, $shadowContainer);
134
134
  popsDOMUtils.appendBody($shadowContainer);
135
135
  if ($mask != null) {
136
136
  // 添加遮罩层
@@ -145,11 +145,11 @@ export const PopsAlert = {
145
145
  $shadowContainer: $shadowContainer,
146
146
  $shadowRoot: $shadowRoot,
147
147
  config: config,
148
- destory: result.close,
148
+ emitter,
149
149
  });
150
150
  // 拖拽
151
151
  if (config.drag) {
152
- PopsInstanceUtils.drag($pops!, {
152
+ PopsInstHandler.drag($pops!, {
153
153
  dragElement: $title!,
154
154
  limit: config.dragLimit,
155
155
  extraDistance: config.dragExtraDistance!,
@@ -1,10 +1,12 @@
1
1
  import { GlobalConfig } from "../../config/GlobalConfig";
2
+ import { EventEmiter } from "../../event/EventEmiter";
2
3
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
3
4
  import { PopsHandler } from "../../handler/PopsHandler";
5
+ import { PopsInstHandler } from "../../handler/PopsInstHandler";
4
6
  import { PopsCSS } from "../../PopsCSS";
7
+ import type { EventMap } from "../../types/EventEmitter";
5
8
  import type { PopsType } from "../../types/main";
6
9
  import { popsDOMUtils } from "../../utils/PopsDOMUtils";
7
- import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
8
10
  import { popsUtils } from "../../utils/PopsUtils";
9
11
  import { PopsConfirmDefaultConfig } from "./defaultConfig";
10
12
  import type { PopsConfirmConfig } from "./types";
@@ -14,6 +16,7 @@ export const PopsConfirm = {
14
16
  const guid = popsUtils.getRandomGUID();
15
17
  // 设置当前类型
16
18
  const popsType: PopsType = "confirm";
19
+ const emitter = new EventEmiter<EventMap>(popsType);
17
20
 
18
21
  let config = PopsConfirmDefaultConfig();
19
22
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
@@ -53,7 +56,7 @@ export const PopsConfirm = {
53
56
  ]);
54
57
 
55
58
  // 先把z-index提取出来
56
- const zIndex = PopsHandler.handleZIndex(config.zIndex);
59
+ const zIndex = PopsHandler.getTargerOrFunctionValue(config.zIndex);
57
60
  const maskHTML = PopsElementHandler.createMask(guid, zIndex);
58
61
 
59
62
  const headerBtnHTML = PopsElementHandler.createHeader(popsType, config);
@@ -121,6 +124,7 @@ export const PopsConfirm = {
121
124
  popsType,
122
125
  $anim,
123
126
  $pops,
127
+ emitter,
124
128
  $mask
125
129
  );
126
130
  const result = PopsHandler.handleResultConfig(evtConfig);
@@ -130,12 +134,8 @@ export const PopsConfirm = {
130
134
  PopsHandler.handleClickEvent("other", $btnOther, evtConfig, config.btn.other.callback);
131
135
 
132
136
  // 创建到页面中
133
-
134
137
  popsDOMUtils.append($shadowRoot, $elList);
135
- if (typeof config.beforeAppendToPageCallBack === "function") {
136
- config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
137
- }
138
-
138
+ emitter.emit("pops:before-append-to-page", $shadowRoot, $shadowContainer);
139
139
  popsDOMUtils.appendBody($shadowContainer);
140
140
  if ($mask != null) {
141
141
  $anim.after($mask);
@@ -148,11 +148,11 @@ export const PopsConfirm = {
148
148
  $shadowContainer: $shadowContainer,
149
149
  $shadowRoot: $shadowRoot,
150
150
  config: config,
151
- destory: result.close,
151
+ emitter,
152
152
  });
153
153
  // 拖拽
154
154
  if (config.drag) {
155
- PopsInstanceUtils.drag($pops!, {
155
+ PopsInstHandler.drag($pops!, {
156
156
  dragElement: $title!,
157
157
  limit: config.dragLimit,
158
158
  extraDistance: config.dragExtraDistance,