@whitesev/pops 1.7.2 → 1.7.3

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.
@@ -0,0 +1,20 @@
1
+ type EnterReturnType<T> = null | T | (() => T);
2
+ type GlobalConfigOption = {
3
+ style?: EnterReturnType<string>;
4
+ zIndex?: EnterReturnType<number> | EnterReturnType<string>;
5
+ };
6
+ export declare const GlobalConfig: {
7
+ config: GlobalConfigOption;
8
+ /**
9
+ * 为所有弹窗设置全局属性
10
+ */
11
+ setGlobalConfig(config: GlobalConfigOption): void;
12
+ /**
13
+ * 获取全局配置
14
+ */
15
+ getGlobalConfig(): {
16
+ style?: string | undefined;
17
+ zIndex?: string | number | undefined;
18
+ };
19
+ };
20
+ export {};
@@ -231,6 +231,23 @@ declare class Pops {
231
231
  * @param userAgent
232
232
  */
233
233
  isPhone(userAgent?: string): boolean;
234
+ /**
235
+ * 为所有弹窗设置全局属性
236
+ */
237
+ GlobalConfig: {
238
+ config: {
239
+ style?: string | (() => string) | null;
240
+ zIndex?: (number | (() => number) | null) | (string | (() => string) | null);
241
+ };
242
+ setGlobalConfig(config: {
243
+ style?: string | (() => string) | null;
244
+ zIndex?: (number | (() => number) | null) | (string | (() => string) | null);
245
+ }): void;
246
+ getGlobalConfig(): {
247
+ style?: string | undefined;
248
+ zIndex?: string | number | undefined;
249
+ };
250
+ };
234
251
  /**
235
252
  * 普通信息框
236
253
  * @param details 配置
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/pops",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "弹窗库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -0,0 +1,60 @@
1
+ type EnterReturnType<T> = null | T | (() => T);
2
+
3
+ type GlobalConfigOption = {
4
+ style?: EnterReturnType<string>;
5
+ zIndex?: EnterReturnType<number> | EnterReturnType<string>;
6
+ };
7
+
8
+ type ResultGlobalConfigOption<T> = T extends null | undefined
9
+ ? never
10
+ : T extends (...args: any) => infer R
11
+ ? R
12
+ : T;
13
+ export const GlobalConfig = {
14
+ config: {} as GlobalConfigOption,
15
+ /**
16
+ * 为所有弹窗设置全局属性
17
+ */
18
+ setGlobalConfig(config: GlobalConfigOption) {
19
+ Reflect.ownKeys(config).forEach((keyName) => {
20
+ Reflect.set(GlobalConfig.config, keyName, Reflect.get(config, keyName));
21
+ });
22
+ },
23
+ /**
24
+ * 获取全局配置
25
+ */
26
+ getGlobalConfig() {
27
+ let result: {
28
+ [P in keyof GlobalConfigOption]: ResultGlobalConfigOption<
29
+ GlobalConfigOption[P]
30
+ >;
31
+ } = {};
32
+ let style =
33
+ GlobalConfig.config.style == null
34
+ ? ""
35
+ : typeof GlobalConfig.config.style === "function"
36
+ ? GlobalConfig.config.style()
37
+ : GlobalConfig.config.style;
38
+
39
+ if (typeof style === "string") {
40
+ result.style = style;
41
+ }
42
+ let zIndex =
43
+ GlobalConfig.config.zIndex == null
44
+ ? ""
45
+ : typeof GlobalConfig.config.zIndex === "function"
46
+ ? GlobalConfig.config.zIndex()
47
+ : GlobalConfig.config.zIndex;
48
+ if (typeof zIndex === "string") {
49
+ let newIndex = (zIndex = parseInt(zIndex));
50
+ if (!isNaN(newIndex)) {
51
+ result.zIndex = newIndex;
52
+ }
53
+ } else {
54
+ if (!isNaN(zIndex)) {
55
+ result.zIndex = zIndex;
56
+ }
57
+ }
58
+ return result;
59
+ },
60
+ };
package/src/Pops.ts CHANGED
@@ -77,12 +77,13 @@ import type {
77
77
  import { PopsSearchSuggestion } from "./components/searchSuggestion";
78
78
  import { PopsMathFloatUtils } from "./utils/PopsMathUtils";
79
79
  import { PanelHandleContentDetails } from "./components/panel/PanelHandleContentDetails";
80
+ import { GlobalConfig } from "./GlobalConfig";
80
81
 
81
82
  class Pops {
82
83
  /** 配置 */
83
84
  config = {
84
85
  /** 版本号 */
85
- version: "2024.10.1",
86
+ version: "2024.10.13",
86
87
  cssText: {
87
88
  /** 主CSS */
88
89
  index: indexCSS,
@@ -230,6 +231,10 @@ class Pops {
230
231
  isPhone(userAgent = PopsCore.globalThis.navigator.userAgent): boolean {
231
232
  return Boolean(/(iPhone|iPad|iPod|iOS|Android)/i.test(userAgent));
232
233
  }
234
+ /**
235
+ * 为所有弹窗设置全局属性
236
+ */
237
+ GlobalConfig = GlobalConfig;
233
238
  /**
234
239
  * 普通信息框
235
240
  * @param details 配置
@@ -1,3 +1,4 @@
1
+ import { GlobalConfig } from "../../GlobalConfig";
1
2
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { pops } from "../../Pops";
@@ -22,6 +23,7 @@ export class PopsAlert {
22
23
  ]);
23
24
 
24
25
  let config: Required<PopsAlertDetails> = PopsAlertConfig();
26
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
25
27
  config = popsUtils.assign(config, details);
26
28
  let guid = popsUtils.getRandomGUID();
27
29
  // 设置当前类型
@@ -1,3 +1,4 @@
1
+ import { GlobalConfig } from "../../GlobalConfig";
1
2
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { pops } from "../../Pops";
@@ -20,6 +21,7 @@ export class PopsConfirm {
20
21
  pops.config.cssText.confirmCSS,
21
22
  ]);
22
23
  let config: Required<PopsConfirmDetails> = PopsConfirmConfig();
24
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
25
  config = popsUtils.assign(config, details);
24
26
  let guid = popsUtils.getRandomGUID();
25
27
  // 设置当前类型
@@ -1,3 +1,4 @@
1
+ import { GlobalConfig } from "../../GlobalConfig";
1
2
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { pops } from "../../Pops";
@@ -20,6 +21,7 @@ export class PopsDrawer {
20
21
  ]);
21
22
 
22
23
  let config: Required<PopsDrawerDetails> = PopsDrawerConfig();
24
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
25
  config = popsUtils.assign(config, details);
24
26
  let guid = popsUtils.getRandomGUID();
25
27
  const PopsType = "drawer";
@@ -1,3 +1,4 @@
1
+ import { GlobalConfig } from "../../GlobalConfig";
1
2
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { pops } from "../../Pops";
@@ -22,6 +23,8 @@ export class PopsFolder {
22
23
  ]);
23
24
 
24
25
  let config: Required<PopsFolderDetails> = PopsFolderConfig();
26
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
27
+ config = popsUtils.assign(config, details);
25
28
 
26
29
  /* 办公几件套 */
27
30
  (Folder_ICON as any).docx = Folder_ICON.doc;
@@ -82,7 +85,6 @@ export class PopsFolder {
82
85
  (Folder_ICON as any)[keyName] = Folder_ICON.apk;
83
86
  });
84
87
 
85
- config = popsUtils.assign(config, details);
86
88
  if (details?.folder) {
87
89
  config.folder = details.folder;
88
90
  }
@@ -1,3 +1,4 @@
1
+ import { GlobalConfig } from "../../GlobalConfig";
1
2
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { pops } from "../../Pops";
@@ -21,6 +22,7 @@ export class PopsIframe {
21
22
  ]);
22
23
 
23
24
  let config: Required<PopsIframeDetails> = PopsIframeConfig();
25
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
24
26
  config = popsUtils.assign(config, details);
25
27
  if (config.url == null) {
26
28
  throw "config.url不能为空";
@@ -1,3 +1,4 @@
1
+ import { GlobalConfig } from "../../GlobalConfig";
1
2
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { pops } from "../../Pops";
@@ -9,6 +10,7 @@ import type { PopsLoadingDetails } from "./indexType";
9
10
  export class PopsLoading {
10
11
  constructor(details: PopsLoadingDetails) {
11
12
  let config: Required<PopsLoadingDetails> = PopsLoadingConfig();
13
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
12
14
  config = popsUtils.assign(config, details);
13
15
  let guid = popsUtils.getRandomGUID();
14
16
  const PopsType = "loading";
@@ -7,6 +7,7 @@ import { popsUtils } from "../../utils/PopsUtils";
7
7
  import type { PopsPanelDetails } from "./indexType";
8
8
  import { PopsPanelConfig } from "./config";
9
9
  import { PanelHandleContentDetails } from "./PanelHandleContentDetails";
10
+ import { GlobalConfig } from "../../GlobalConfig";
10
11
 
11
12
  export class PopsPanel {
12
13
  constructor(details: PopsPanelDetails) {
@@ -22,6 +23,7 @@ export class PopsPanel {
22
23
  ]);
23
24
 
24
25
  let config: Required<PopsPanelDetails> = PopsPanelConfig();
26
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
25
27
  config = popsUtils.assign(config, details);
26
28
  if (details && Array.isArray(details.content)) {
27
29
  config.content = details.content;
@@ -1,3 +1,4 @@
1
+ import { GlobalConfig } from "../../GlobalConfig";
1
2
  import { PopsElementHandler } from "../../handler/PopsElementHandler";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { pops } from "../../Pops";
@@ -20,6 +21,7 @@ export class PopsPrompt {
20
21
  pops.config.cssText.promptCSS,
21
22
  ]);
22
23
  let config: Required<PopsPromptDetails> = PopsPromptConfig();
24
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
23
25
  config = popsUtils.assign(config, details);
24
26
  let guid = popsUtils.getRandomGUID();
25
27
  const PopsType = "prompt";
@@ -1,4 +1,5 @@
1
1
  import { OriginPrototype } from "../../Core";
2
+ import { GlobalConfig } from "../../GlobalConfig";
2
3
  import { PopsHandler } from "../../handler/PopsHandler";
3
4
  import { pops } from "../../Pops";
4
5
  import type { PopsIcon } from "../../types/icon";
@@ -22,6 +23,7 @@ export class PopsRightClickMenu {
22
23
 
23
24
  let config: Required<PopsRightClickMenuDetails> =
24
25
  PopsRightClickMenuConfig();
26
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
25
27
  config = popsUtils.assign(config, details);
26
28
  if (config.target == null) {
27
29
  throw "config.target 不能为空";
@@ -4,6 +4,7 @@ import { popsDOMUtils } from "../../utils/PopsDOMUtils";
4
4
  import { popsUtils } from "../../utils/PopsUtils";
5
5
  import type { PopsSearchSuggestionDetails } from "./indexType";
6
6
  import { searchSuggestionConfig as PopsSearchSuggestionConfig } from "./config";
7
+ import { GlobalConfig } from "../../GlobalConfig";
7
8
 
8
9
  export class PopsSearchSuggestion {
9
10
  constructor(details: PopsSearchSuggestionDetails) {
@@ -16,6 +17,7 @@ export class PopsSearchSuggestion {
16
17
 
17
18
  let config: Required<PopsSearchSuggestionDetails> =
18
19
  PopsSearchSuggestionConfig();
20
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
19
21
  config = popsUtils.assign(config, details);
20
22
  if (config.target == null) {
21
23
  throw new TypeError("config.target 不能为空");
@@ -1,3 +1,4 @@
1
+ import { GlobalConfig } from "../../GlobalConfig";
1
2
  import { PopsHandler } from "../../handler/PopsHandler";
2
3
  import { pops } from "../../Pops";
3
4
  import { popsDOMUtils } from "../../utils/PopsDOMUtils";
@@ -16,6 +17,7 @@ export class PopsTooltip {
16
17
  ]);
17
18
 
18
19
  let config: Required<PopsToolTipDetails> = PopsTooltipConfig();
20
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
19
21
  config = popsUtils.assign(config, details);
20
22
  if (!(config.target instanceof HTMLElement)) {
21
23
  throw "config.target 必须是HTMLElement类型";