@whitesev/pops 3.3.4 → 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 (93) hide show
  1. package/dist/index.amd.js +13118 -12906
  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 +805 -593
  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 +805 -593
  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 -12907
  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 -12910
  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 -12909
  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 +61 -46
  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/folder/types/index.d.ts +4 -0
  33. package/dist/types/src/components/iframe/index.d.ts +6 -1
  34. package/dist/types/src/components/iframe/types/index.d.ts +4 -2
  35. package/dist/types/src/components/loading/index.d.ts +3 -1
  36. package/dist/types/src/components/panel/handlerComponents.d.ts +4 -1
  37. package/dist/types/src/components/panel/index.d.ts +2 -16
  38. package/dist/types/src/components/panel/types/index.d.ts +7 -2
  39. package/dist/types/src/components/prompt/index.d.ts +3 -1
  40. package/dist/types/src/components/searchSuggestion/index.d.ts +4 -1
  41. package/dist/types/src/components/tooltip/index.d.ts +6 -2
  42. package/dist/types/src/config/GlobalConfig.d.ts +1 -0
  43. package/dist/types/src/event/EventEmiter.d.ts +33 -0
  44. package/dist/types/src/handler/PopsHandler.d.ts +18 -16
  45. package/dist/types/src/handler/PopsInstHandler.d.ts +67 -0
  46. package/dist/types/src/types/EventEmitter.d.ts +18 -0
  47. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +4 -0
  48. package/dist/types/src/types/button.d.ts +2 -1
  49. package/dist/types/src/types/components.d.ts +7 -0
  50. package/dist/types/src/types/event.d.ts +6 -2
  51. package/dist/types/src/types/inst.d.ts +4 -4
  52. package/dist/types/src/utils/PopsDOMUtils.d.ts +0 -16
  53. package/dist/types/src/utils/PopsInstanceUtils.d.ts +0 -88
  54. package/dist/types/src/utils/PopsUtils.d.ts +57 -0
  55. package/package.json +3 -3
  56. package/src/Pops.ts +7 -2
  57. package/src/PopsAnimation.ts +126 -0
  58. package/src/components/alert/defaultConfig.ts +1 -0
  59. package/src/components/alert/index.ts +9 -9
  60. package/src/components/confirm/defaultConfig.ts +1 -0
  61. package/src/components/confirm/index.ts +9 -9
  62. package/src/components/drawer/defaultConfig.ts +1 -0
  63. package/src/components/drawer/index.ts +12 -9
  64. package/src/components/folder/defaultConfig.ts +1 -0
  65. package/src/components/folder/index.ts +9 -8
  66. package/src/components/folder/types/index.ts +4 -0
  67. package/src/components/iframe/defaultConfig.ts +1 -0
  68. package/src/components/iframe/index.ts +18 -12
  69. package/src/components/iframe/types/index.ts +10 -8
  70. package/src/components/loading/defaultConfig.ts +1 -0
  71. package/src/components/loading/index.ts +12 -6
  72. package/src/components/panel/defaultConfig.ts +2 -0
  73. package/src/components/panel/handlerComponents.ts +41 -111
  74. package/src/components/panel/index.ts +34 -28
  75. package/src/components/panel/types/index.ts +7 -2
  76. package/src/components/prompt/defaultConfig.ts +1 -0
  77. package/src/components/prompt/index.ts +9 -8
  78. package/src/components/rightClickMenu/index.ts +17 -14
  79. package/src/components/searchSuggestion/index.ts +5 -1
  80. package/src/components/tooltip/index.ts +20 -10
  81. package/src/event/EventEmiter.ts +95 -0
  82. package/src/handler/PopsElementHandler.ts +6 -4
  83. package/src/handler/PopsHandler.ts +100 -58
  84. package/src/handler/PopsInstHandler.ts +557 -0
  85. package/src/types/EventEmitter.d.ts +18 -0
  86. package/src/types/PopsDOMUtilsEventType.d.ts +4 -0
  87. package/src/types/button.d.ts +2 -1
  88. package/src/types/components.d.ts +7 -0
  89. package/src/types/event.d.ts +6 -2
  90. package/src/types/inst.d.ts +4 -4
  91. package/src/utils/PopsDOMUtils.ts +1 -40
  92. package/src/utils/PopsInstanceUtils.ts +19 -627
  93. package/src/utils/PopsUtils.ts +194 -0
@@ -6,20 +6,19 @@ import type { PopsIframeConfig } from "../components/iframe/types";
6
6
  import type { PopsLoadingConfig } from "../components/loading/types";
7
7
  import type { PopsPanelConfig } from "../components/panel/types";
8
8
  import type { PopsPromptConfig } from "../components/prompt/types/index";
9
+ import type { EventEmiter } from "../event/EventEmiter";
9
10
  import type { PopsGeneralConfig } from "../types/components";
10
11
  import type { PopsEventConfig, PopsHandlerEventConfig } from "../types/event";
12
+ import type { CustomEventMap } from "../types/EventEmitter";
11
13
  import type { PopsInstGeneralConfig } from "../types/inst";
12
- import type { PopsInstStoreType, PopsType, PopsSupportAnimConfigType, PopsSupportOnlyConfig } from "../types/main";
14
+ import type { PopsInstStoreType, PopsSupportAnimConfigType, PopsSupportOnlyConfig, PopsType } from "../types/main";
13
15
  export declare const PopsHandler: {
14
16
  /**
15
17
  * 创建shadow
16
18
  */
17
- handlerShadow(config: Pick<PopsGeneralConfig, "useShadowRoot">): {
19
+ handlerShadow(config: Pick<PopsGeneralConfig, "useShadowRoot" | "stopKeyDownEventPropagation">): {
18
20
  $shadowContainer: HTMLDivElement;
19
- $shadowRoot: ShadowRoot;
20
- } | {
21
- $shadowContainer: HTMLDivElement;
22
- $shadowRoot: HTMLDivElement;
21
+ $shadowRoot: HTMLElement | ShadowRoot;
23
22
  };
24
23
  /**
25
24
  * 处理初始化
@@ -183,7 +182,7 @@ export declare const PopsHandler: {
183
182
  * @param $mask 遮罩层
184
183
  * @param config 当前配置
185
184
  */
186
- handleEventConfig(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, guid: string, $shadowContainer: HTMLDivElement, $shadowRoot: ShadowRoot | HTMLElement, type: PopsInstStoreType, $anim: HTMLDivElement, $pops: HTMLDivElement, $mask?: HTMLDivElement): PopsEventConfig;
185
+ handleEventConfig<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>>(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, guid: string, $shadowContainer: HTMLDivElement, $shadowRoot: ShadowRoot | HTMLElement, type: PopsInstStoreType, $anim: HTMLDivElement, $pops: HTMLDivElement, emitter: E, $mask?: HTMLDivElement): PopsEventConfig<E>;
187
186
  /**
188
187
  * 获取loading的事件配置
189
188
  * @param guid
@@ -193,7 +192,7 @@ export declare const PopsHandler: {
193
192
  * @param $mask 遮罩层
194
193
  * @param config 当前配置
195
194
  */
196
- handleLoadingEventConfig(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, guid: string, type: "loading", $anim: HTMLDivElement, $pops: HTMLDivElement, $mask?: HTMLDivElement): Omit<PopsEventConfig, "$shadowContainer" | "$shadowRoot">;
195
+ handleLoadingEventConfig<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>>(config: PopsAlertConfig | PopsDrawerConfig | PopsPromptConfig | PopsConfirmConfig | PopsIframeConfig | PopsLoadingConfig | PopsPanelConfig | PopsFolderConfig, guid: string, type: "loading", $anim: HTMLDivElement, $pops: HTMLDivElement, emitter: E, $mask?: HTMLDivElement): Omit<PopsEventConfig<E>, "$shadowContainer" | "$shadowRoot">;
197
196
  /**
198
197
  * 处理返回的配置,针对popsHandler.handleEventConfig
199
198
  * @param config 配置
@@ -206,16 +205,14 @@ export declare const PopsHandler: {
206
205
  * @param eventConfig 事件配置,由popsHandler.handleEventConfig创建的
207
206
  * @param callback 点击回调
208
207
  */
209
- handleClickEvent(type: PopsHandlerEventConfig["type"], $btn: HTMLElement, eventConfig: PopsEventConfig, callback?: (details: PopsHandlerEventConfig, event: PointerEvent | MouseEvent) => void): void;
208
+ handleClickEvent<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>>(type: PopsHandlerEventConfig<E>["type"], $btn: HTMLElement, eventConfig: PopsEventConfig<E>, callback?: (details: PopsHandlerEventConfig<E>, event: PointerEvent | MouseEvent) => void): import("../types/PopsDOMUtilsEventType").PopsDOMUtilsAddEventListenerResult | undefined;
210
209
  /**
211
210
  * 全局监听键盘事件
212
211
  * @param keyName 键名|键值
213
212
  * @param otherKeyList 组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
214
213
  * @param callback 回调函数
215
214
  */
216
- handleKeyboardEvent(keyName: string | number, otherKeyList: string[] | undefined, callback: (event: KeyboardEvent) => void): {
217
- removeKeyboardEvent(): void;
218
- };
215
+ handleKeyboardEvent(keyName: string | number, otherKeyList: string[] | undefined, callback: (event: KeyboardEvent) => void): import("../types/PopsDOMUtilsEventType").PopsDOMUtilsAddEventListenerResult;
219
216
  /**
220
217
  * 处理prompt的点击事件
221
218
  * @param type 触发事件类型
@@ -224,21 +221,26 @@ export declare const PopsHandler: {
224
221
  * @param eventConfig 事件配置,由popsHandler.handleEventConfig创建的
225
222
  * @param callback 点击回调
226
223
  */
227
- handlePromptClickEvent(type: PopsHandlerEventConfig["type"], inputElement: HTMLInputElement | HTMLTextAreaElement, $btn: HTMLElement, eventConfig: PopsEventConfig, callback: (details: PopsEventConfig & {
224
+ handlePromptClickEvent<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>>(type: PopsHandlerEventConfig<E>["type"], inputElement: HTMLInputElement | HTMLTextAreaElement, $btn: HTMLElement, eventConfig: PopsEventConfig<E>, callback: (details: PopsEventConfig<E> & {
228
225
  type: any;
229
226
  text: string;
230
227
  }, event: MouseEvent | PointerEvent) => void): void;
231
228
  /**
232
- * 把配置的z-index配置转为数字
233
- * @param zIndex
229
+ * 获取数值
230
+ * @param target
234
231
  */
235
- handleZIndex(zIndex: number | (() => number)): number;
232
+ getTargerOrFunctionValue<T>(target: T | (() => T)): T;
236
233
  /**
237
234
  * 处理config.only
238
235
  * @param type 当前弹窗类型
239
236
  * @param config 配置
240
237
  */
241
238
  handleOnly<T extends Required<PopsSupportOnlyConfig[keyof PopsSupportOnlyConfig]>>(type: PopsType, config: T): T;
239
+ /**
240
+ * 处理z-index
241
+ * @param config 配置
242
+ */
243
+ handleZIndex<T extends Required<PopsSupportOnlyConfig[keyof PopsSupportOnlyConfig]>>(config: T): T;
242
244
  /**
243
245
  * 处理把已创建的元素保存到内部环境中
244
246
  * @param type 当前弹窗类型
@@ -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
  /**
@@ -214,6 +214,13 @@ export interface PopsGeneralConfig {
214
214
  * 传入的css都在dark内
215
215
  */
216
216
  darkStyle?: string | null;
217
+ /**
218
+ * (可选)是否阻止`keydown`事件传播
219
+ *
220
+ * 主要是阻止当`keydown`触发来源为输入框时,即在输入框内按下按键不会触发页面的快捷键
221
+ * @default true
222
+ */
223
+ stopKeyDownEventPropagation?: boolean;
217
224
  /**
218
225
  * 在元素添加到页面前的事件
219
226
  * @param $shadowRoot 根元素
@@ -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.4",
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
  };
@@ -60,5 +60,6 @@ export const PopsAlertDefaultConfig = (): DeepRequired<PopsAlertConfig> => {
60
60
  lightStyle: null,
61
61
  darkStyle: null,
62
62
  beforeAppendToPageCallBack() {},
63
+ stopKeyDownEventPropagation: true,
63
64
  } as DeepRequired<PopsAlertConfig>;
64
65
  };