@whitesev/pops 1.8.9 → 1.9.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.
@@ -146,15 +146,15 @@ declare class Pops {
146
146
  };
147
147
  /** pops创建的实例使用的工具类 */
148
148
  InstanceUtils: {
149
- getMaxZIndexNodeInfo(deviation?: number): {
149
+ getMaxZIndexNodeInfo(deviation?: number, target?: Element | ShadowRoot | Document, ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void): {
150
150
  node: Element;
151
151
  zIndex: number;
152
152
  };
153
- getMaxZIndex(deviation?: number): number;
154
153
  getPopsMaxZIndex(deviation?: number): {
155
154
  zIndex: number;
156
155
  animElement: HTMLDivElement | null;
157
156
  };
157
+ getMaxZIndex(deviation?: number): number;
158
158
  getKeyFrames(sheet: CSSStyleSheet): {};
159
159
  removeInstance(moreLayerConfigList: PopsLayerCommonConfig[][], guid: string, isAll?: boolean): PopsLayerCommonConfig[][];
160
160
  hide(popsType: PopsLayerMode, layerConfigList: PopsLayerCommonConfig[], guid: string, config: PopsAlertDetails | PopsDrawerDetails | PopsPromptDetails | PopsConfirmDetails | PopsIframeDetails | PopsLoadingDetails | PopsPanelDetails | PopsFolderDetails, animElement: HTMLElement, maskElement: HTMLElement): void;
@@ -25,6 +25,8 @@ export declare const PopsHandler: {
25
25
  handleInit($shadowRoot?: ShadowRoot, cssText?: string | string[]): void;
26
26
  /**
27
27
  * 处理遮罩层
28
+ *
29
+ * + 设置遮罩层的点击事件
28
30
  * @param details 传递的配置
29
31
  */
30
32
  handleMask(details?: {
@@ -38,7 +40,7 @@ export declare const PopsHandler: {
38
40
  };
39
41
  /**
40
42
  * 处理获取元素
41
- * @param {HTMLDivElement} animElement
43
+ * @param animElement
42
44
  * @param type
43
45
  */
44
46
  handleQueryElement(animElement: HTMLDivElement, type: PopsType): {
@@ -12,6 +12,8 @@ export declare const PopsInstanceUtils: {
12
12
  /**
13
13
  * 获取页面中最大的z-index的元素信息
14
14
  * @param deviation 获取最大的z-index值的偏移,默认是+1
15
+ * @param node 进行判断的元素,默认是document
16
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
15
17
  * @example
16
18
  * Utils.getMaxZIndexNodeInfo();
17
19
  * > {
@@ -19,18 +21,10 @@ export declare const PopsInstanceUtils: {
19
21
  * zIndex: 1001
20
22
  * }
21
23
  **/
22
- getMaxZIndexNodeInfo(deviation?: number): {
24
+ getMaxZIndexNodeInfo(deviation?: number, target?: Element | ShadowRoot | Document, ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void): {
23
25
  node: Element;
24
26
  zIndex: number;
25
27
  };
26
- /**
27
- * 获取页面中最大的z-index
28
- * @param deviation 获取最大的z-index值的偏移,默认是+1
29
- * @example
30
- * Utils.getMaxZIndex();
31
- * > 1001
32
- **/
33
- getMaxZIndex(deviation?: number): number;
34
28
  /**
35
29
  * 获取pops所有弹窗中的最大的z-index
36
30
  * @param deviation
@@ -39,6 +33,14 @@ export declare const PopsInstanceUtils: {
39
33
  zIndex: number;
40
34
  animElement: HTMLDivElement | null;
41
35
  };
36
+ /**
37
+ * 获取页面中最大的z-index
38
+ * @param deviation 获取最大的z-index值的偏移,默认是+1
39
+ * @example
40
+ * Utils.getMaxZIndex();
41
+ * > 1001
42
+ **/
43
+ getMaxZIndex(deviation?: number): number;
42
44
  /**
43
45
  * 获取CSS Rule
44
46
  * @param sheet
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/pops",
3
- "version": "1.8.9",
3
+ "version": "1.9.0",
4
4
  "description": "弹窗库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -93,19 +93,19 @@ export class PopsPanel {
93
93
  /**
94
94
  * 已创建的元素列表
95
95
  */
96
- let elementList: HTMLElement[] = [$anim];
96
+ let isCreatedElementList: HTMLElement[] = [$anim];
97
97
 
98
98
  /* 遮罩层元素 */
99
99
  if (config.mask.enable) {
100
- let _handleMask_ = PopsHandler.handleMask({
100
+ let { maskElement } = PopsHandler.handleMask({
101
101
  type: PopsType,
102
102
  guid: guid,
103
103
  config: config,
104
104
  animElement: $anim,
105
105
  maskHTML: maskHTML,
106
106
  });
107
- $mask = _handleMask_.maskElement;
108
- elementList.push($mask);
107
+ $mask = maskElement;
108
+ isCreatedElementList.push($mask);
109
109
  }
110
110
 
111
111
  /* 处理返回的配置 */
@@ -128,7 +128,7 @@ export class PopsPanel {
128
128
  );
129
129
 
130
130
  /* 创建到页面中 */
131
- popsDOMUtils.append($shadowRoot, elementList);
131
+ popsDOMUtils.append($shadowRoot, isCreatedElementList);
132
132
  if (typeof config.beforeAppendToPageCallBack === "function") {
133
133
  config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
134
134
  }
@@ -62,6 +62,8 @@ export const PopsHandler = {
62
62
  },
63
63
  /**
64
64
  * 处理遮罩层
65
+ *
66
+ * + 设置遮罩层的点击事件
65
67
  * @param details 传递的配置
66
68
  */
67
69
  handleMask(
@@ -130,27 +132,32 @@ export const PopsHandler = {
130
132
  }
131
133
  return false;
132
134
  }
133
- function isAnimElement(element: HTMLDivElement) {
134
- return Boolean(
135
- element?.localName?.toLowerCase() === "div" &&
136
- element.className &&
137
- element.className === "pops-anim" &&
138
- element.hasAttribute("anim")
139
- );
140
- }
135
+ // 判断是否启用了遮罩层点击动作
141
136
  if (
142
137
  details.config.mask.clickEvent!.toClose ||
143
138
  details.config.mask.clickEvent!.toHide
144
139
  ) {
140
+ /**
141
+ * 判断点击的元素是否是动画层的元素
142
+ * @param element
143
+ * @returns
144
+ */
145
+ function isAnimElement(element: HTMLElement) {
146
+ return Boolean(
147
+ element?.localName?.toLowerCase() === "div" &&
148
+ element.className &&
149
+ element.className === "pops-anim" &&
150
+ element.hasAttribute("anim")
151
+ );
152
+ }
145
153
  /* 判断按下的元素是否是pops-anim */
146
154
  popsDOMUtils.on(
147
155
  details.animElement,
148
156
  ["touchstart", "mousedown"],
149
157
  void 0,
150
158
  (event) => {
151
- isMaskClick = isAnimElement(
152
- event.composedPath()[0] as HTMLDivElement
153
- );
159
+ let $click = event.composedPath()[0] as HTMLElement;
160
+ isMaskClick = isAnimElement($click);
154
161
  }
155
162
  );
156
163
  /* 如果有动画层,在动画层上监听点击事件 */
@@ -159,10 +166,8 @@ export const PopsHandler = {
159
166
  "click",
160
167
  void 0,
161
168
  (event) => {
162
- if (
163
- isAnimElement(event.composedPath()[0] as HTMLDivElement) &&
164
- isMaskClick
165
- ) {
169
+ let $click = event.composedPath()[0] as HTMLElement;
170
+ if (isAnimElement($click) && isMaskClick) {
166
171
  return clickEvent(event);
167
172
  }
168
173
  }
@@ -183,7 +188,7 @@ export const PopsHandler = {
183
188
  },
184
189
  /**
185
190
  * 处理获取元素
186
- * @param {HTMLDivElement} animElement
191
+ * @param animElement
187
192
  * @param type
188
193
  */
189
194
  handleQueryElement(animElement: HTMLDivElement, type: PopsType) {
@@ -17,6 +17,8 @@ export const PopsInstanceUtils = {
17
17
  /**
18
18
  * 获取页面中最大的z-index的元素信息
19
19
  * @param deviation 获取最大的z-index值的偏移,默认是+1
20
+ * @param node 进行判断的元素,默认是document
21
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
20
22
  * @example
21
23
  * Utils.getMaxZIndexNodeInfo();
22
24
  * > {
@@ -24,14 +26,20 @@ export const PopsInstanceUtils = {
24
26
  * zIndex: 1001
25
27
  * }
26
28
  **/
27
- getMaxZIndexNodeInfo(deviation = 1): {
29
+ getMaxZIndexNodeInfo(
30
+ deviation = 1,
31
+ target: Element | ShadowRoot | Document = PopsCore.document,
32
+ ignoreCallBack?: (
33
+ $ele: Element | HTMLElement | ShadowRoot
34
+ ) => boolean | void
35
+ ): {
28
36
  node: Element;
29
37
  zIndex: number;
30
38
  } {
31
39
  deviation = Number.isNaN(deviation) ? 1 : deviation;
32
- // 最大值2147483647
33
- const maxZIndex = Math.pow(2, 31) - 1;
34
- // 比较值2000000000
40
+ // 最大值 2147483647
41
+ // const maxZIndex = Math.pow(2, 31) - 1;
42
+ // 比较值 2000000000
35
43
  const maxZIndexCompare = 2 * Math.pow(10, 9);
36
44
  // 当前页面最大的z-index
37
45
  let zIndex = 0;
@@ -51,6 +59,12 @@ export const PopsInstanceUtils = {
51
59
  * @param $ele
52
60
  */
53
61
  function queryMaxZIndex($ele: Element) {
62
+ if (typeof ignoreCallBack === "function") {
63
+ let ignoreResult = ignoreCallBack($ele);
64
+ if (typeof ignoreResult === "boolean" && !ignoreResult) {
65
+ return;
66
+ }
67
+ }
54
68
  /** 元素的样式 */
55
69
  const nodeStyle = PopsCore.window.getComputedStyle($ele);
56
70
  /* 不对position为static和display为none的元素进行获取它们的z-index */
@@ -71,50 +85,49 @@ export const PopsInstanceUtils = {
71
85
  }
72
86
  }
73
87
  }
74
- PopsCore.document.querySelectorAll("*").forEach(($ele, index) => {
88
+ target.querySelectorAll("*").forEach(($ele, index) => {
75
89
  queryMaxZIndex($ele);
76
90
  });
77
91
  zIndex += deviation;
78
92
  if (zIndex >= maxZIndexCompare) {
79
93
  // 最好不要超过最大值
80
- zIndex = maxZIndex;
94
+ zIndex = maxZIndexCompare;
81
95
  }
82
96
  return {
83
97
  node: maxZIndexNode,
84
98
  zIndex: zIndex,
85
99
  };
86
100
  },
87
- /**
88
- * 获取页面中最大的z-index
89
- * @param deviation 获取最大的z-index值的偏移,默认是+1
90
- * @example
91
- * Utils.getMaxZIndex();
92
- * > 1001
93
- **/
94
- getMaxZIndex(deviation = 1): number {
95
- return this.getMaxZIndexNodeInfo(deviation).zIndex;
96
- },
97
101
  /**
98
102
  * 获取pops所有弹窗中的最大的z-index
99
103
  * @param deviation
100
104
  */
101
105
  getPopsMaxZIndex(deviation: number = 1) {
102
106
  deviation = Number.isNaN(deviation) ? 1 : deviation;
103
- // 最大值2147483647
104
- let maxZIndex = Math.pow(2, 31) - 1;
105
-
107
+ // 最大值 2147483647
108
+ // 最大值 2147483647
109
+ // const maxZIndex = Math.pow(2, 31) - 1;
110
+ // 比较值 2000000000
111
+ const maxZIndexCompare = 2 * Math.pow(10, 9);
106
112
  // 当前页面最大的z-index
107
113
  let zIndex = 0;
108
114
  // 当前的最大z-index的元素,调试使用
109
115
  let maxZIndexNode = null as HTMLDivElement | null;
110
116
 
117
+ /**
118
+ * 元素是否可见
119
+ * @param $css
120
+ */
121
+ function isVisibleNode($css: CSSStyleDeclaration): boolean {
122
+ return $css.position !== "static" && $css.display !== "none";
123
+ }
111
124
  Object.keys(pops.config.layer).forEach((layerName) => {
112
125
  let layerList = pops.config.layer[layerName as PopsLayerMode];
113
126
  for (let index = 0; index < layerList.length; index++) {
114
127
  const layer = layerList[index];
115
128
  let nodeStyle = window.getComputedStyle(layer.animElement);
116
129
  /* 不对position为static和display为none的元素进行获取它们的z-index */
117
- if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
130
+ if (isVisibleNode(nodeStyle)) {
118
131
  let nodeZIndex = parseInt(nodeStyle.zIndex);
119
132
  if (!isNaN(nodeZIndex)) {
120
133
  if (nodeZIndex > zIndex) {
@@ -126,14 +139,22 @@ export const PopsInstanceUtils = {
126
139
  }
127
140
  });
128
141
  zIndex += deviation;
129
- // 用于比较的值2000000000,大于该值就取该值
130
- let maxZIndexCompare = 2 * Math.pow(10, 9);
131
142
  if (zIndex >= maxZIndexCompare) {
132
143
  // 最好不要超过最大值
133
- zIndex = maxZIndex;
144
+ zIndex = maxZIndexCompare;
134
145
  }
135
146
  return { zIndex: zIndex, animElement: maxZIndexNode };
136
147
  },
148
+ /**
149
+ * 获取页面中最大的z-index
150
+ * @param deviation 获取最大的z-index值的偏移,默认是+1
151
+ * @example
152
+ * Utils.getMaxZIndex();
153
+ * > 1001
154
+ **/
155
+ getMaxZIndex(deviation = 1): number {
156
+ return this.getMaxZIndexNodeInfo(deviation).zIndex;
157
+ },
137
158
  /**
138
159
  * 获取CSS Rule
139
160
  * @param sheet