@whitesev/pops 3.2.0 → 3.2.2
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.
- package/README.md +249 -249
- package/dist/index.amd.js +702 -667
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +702 -667
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +702 -667
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +702 -667
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +702 -667
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +702 -667
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/components/folder/types/index.d.ts +43 -13
- package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +313 -313
- package/dist/types/src/types/animation.d.ts +19 -19
- package/dist/types/src/types/button.d.ts +94 -94
- package/dist/types/src/types/components.d.ts +211 -211
- package/dist/types/src/types/event.d.ts +43 -43
- package/dist/types/src/types/global.d.ts +31 -31
- package/dist/types/src/types/icon.d.ts +32 -32
- package/dist/types/src/types/inst.d.ts +28 -28
- package/dist/types/src/types/main.d.ts +66 -66
- package/dist/types/src/types/mask.d.ts +52 -52
- package/dist/types/src/types/position.d.ts +60 -60
- package/package.json +27 -25
- package/src/Pops.ts +206 -206
- package/src/PopsAnimation.ts +32 -32
- package/src/PopsCSS.ts +54 -54
- package/src/PopsCore.ts +37 -37
- package/src/PopsIcon.ts +95 -95
- package/src/PopsInst.ts +21 -21
- package/src/components/alert/defaultConfig.ts +62 -62
- package/src/components/alert/index.ts +163 -163
- package/src/components/alert/types/index.ts +23 -23
- package/src/components/confirm/defaultConfig.ts +90 -90
- package/src/components/confirm/index.ts +165 -165
- package/src/components/confirm/types/index.ts +13 -17
- package/src/components/drawer/defaultConfig.ts +89 -89
- package/src/components/drawer/index.css +37 -37
- package/src/components/drawer/index.ts +245 -245
- package/src/components/drawer/types/index.ts +62 -61
- package/src/components/folder/defaultConfig.ts +151 -151
- package/src/components/folder/folderIcon.ts +28 -28
- package/src/components/folder/index.css +303 -303
- package/src/components/folder/index.ts +953 -932
- package/src/components/folder/types/index.ts +143 -110
- package/src/components/iframe/defaultConfig.ts +60 -60
- package/src/components/iframe/index.css +76 -76
- package/src/components/iframe/index.ts +331 -331
- package/src/components/iframe/types/index.ts +96 -96
- package/src/components/loading/defaultConfig.ts +29 -29
- package/src/components/loading/index.css +66 -66
- package/src/components/loading/index.ts +101 -101
- package/src/components/loading/types/index.ts +36 -34
- package/src/components/panel/css/components-select.css +84 -84
- package/src/components/panel/defaultConfig.ts +868 -868
- package/src/components/panel/handlerComponents.ts +3993 -3993
- package/src/components/panel/index.css +1403 -1401
- package/src/components/panel/index.ts +221 -221
- package/src/components/panel/types/components-button.ts +56 -56
- package/src/components/panel/types/components-common.ts +73 -73
- package/src/components/panel/types/components-container.ts +25 -25
- package/src/components/panel/types/components-deepMenu.ts +64 -64
- package/src/components/panel/types/components-input.ts +90 -90
- package/src/components/panel/types/components-own.ts +16 -16
- package/src/components/panel/types/components-select.ts +169 -169
- package/src/components/panel/types/components-selectMultiple.ts +105 -104
- package/src/components/panel/types/components-slider.ts +55 -55
- package/src/components/panel/types/components-switch.ts +33 -33
- package/src/components/panel/types/components-textarea.ts +45 -45
- package/src/components/panel/types/index.ts +244 -244
- package/src/components/prompt/defaultConfig.ts +94 -94
- package/src/components/prompt/index.css +34 -34
- package/src/components/prompt/index.ts +187 -215
- package/src/components/prompt/types/index.ts +57 -56
- package/src/components/rightClickMenu/defaultConfig.ts +103 -103
- package/src/components/rightClickMenu/index.css +115 -115
- package/src/components/rightClickMenu/index.ts +662 -662
- package/src/components/rightClickMenu/types/index.ts +145 -143
- package/src/components/searchSuggestion/defaultConfig.ts +63 -63
- package/src/components/searchSuggestion/index.ts +813 -813
- package/src/components/searchSuggestion/types/index.ts +244 -242
- package/src/components/tooltip/defaultConfig.ts +33 -33
- package/src/components/tooltip/index.css +199 -199
- package/src/components/tooltip/index.ts +617 -617
- package/src/components/tooltip/types/index.ts +123 -121
- package/src/config/CommonCSSClassName.ts +17 -17
- package/src/config/GlobalConfig.ts +63 -63
- package/src/css/animation.css +987 -987
- package/src/css/button.css +551 -551
- package/src/css/common.css +54 -54
- package/src/css/index.css +253 -253
- package/src/css/ninePalaceGridPosition.css +50 -50
- package/src/css/scrollbar.css +22 -22
- package/src/handler/PopsElementHandler.ts +303 -303
- package/src/handler/PopsHandler.ts +611 -611
- package/src/types/PopsDOMUtilsEventType.d.ts +313 -313
- package/src/types/animation.d.ts +19 -19
- package/src/types/button.d.ts +94 -94
- package/src/types/components.d.ts +211 -211
- package/src/types/event.d.ts +43 -43
- package/src/types/global.d.ts +31 -31
- package/src/types/icon.d.ts +32 -32
- package/src/types/inst.d.ts +28 -28
- package/src/types/main.d.ts +66 -66
- package/src/types/mask.d.ts +52 -52
- package/src/types/position.d.ts +60 -60
- package/src/utils/PopsDOMUtils.ts +2483 -2483
- package/src/utils/PopsDOMUtilsEventsConfig.ts +4 -4
- package/src/utils/PopsInstanceUtils.ts +714 -714
- package/src/utils/PopsMathUtils.ts +71 -71
- package/src/utils/PopsSafeUtils.ts +22 -22
- package/src/utils/PopsUtils.ts +421 -421
|
@@ -1,714 +1,714 @@
|
|
|
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
|
-
import { popsDOMUtils } from "./PopsDOMUtils";
|
|
12
|
-
import { popsUtils } from "./PopsUtils";
|
|
13
|
-
import { PopsCore } from "../PopsCore";
|
|
14
|
-
import { PopsInstData } from "../PopsInst";
|
|
15
|
-
import { PopsAnimation } from "../PopsAnimation";
|
|
16
|
-
import type { PopsRightClickMenuConfig } from "../components/rightClickMenu/types";
|
|
17
|
-
import type { PopsToolTipConfig } from "../components/tooltip/types";
|
|
18
|
-
|
|
19
|
-
export const PopsInstanceUtils = {
|
|
20
|
-
/**
|
|
21
|
-
* 获取页面中最大的z-index的元素信息
|
|
22
|
-
* @param deviation 获取最大的z-index值的偏移,默认是+1
|
|
23
|
-
* @param node 进行判断的元素,默认是document
|
|
24
|
-
* @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
|
|
25
|
-
* @example
|
|
26
|
-
* Utils.getMaxZIndexNodeInfo();
|
|
27
|
-
* > {
|
|
28
|
-
* node: ...,
|
|
29
|
-
* zIndex: 1001
|
|
30
|
-
* }
|
|
31
|
-
**/
|
|
32
|
-
getMaxZIndexNodeInfo(
|
|
33
|
-
deviation = 1,
|
|
34
|
-
target: Element | ShadowRoot | Document = PopsCore.document,
|
|
35
|
-
ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
|
|
36
|
-
): {
|
|
37
|
-
node: Element;
|
|
38
|
-
zIndex: number;
|
|
39
|
-
} {
|
|
40
|
-
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
41
|
-
// 最大值 2147483647
|
|
42
|
-
// const maxZIndex = Math.pow(2, 31) - 1;
|
|
43
|
-
// 比较值 2000000000
|
|
44
|
-
const maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
45
|
-
// 当前页面最大的z-index
|
|
46
|
-
let zIndex = 0;
|
|
47
|
-
// 当前的最大z-index的元素,调试使用
|
|
48
|
-
let maxZIndexNode: Element | null = null;
|
|
49
|
-
/**
|
|
50
|
-
* 元素是否可见
|
|
51
|
-
* @param $css
|
|
52
|
-
*/
|
|
53
|
-
function isVisibleNode($css: CSSStyleDeclaration): boolean {
|
|
54
|
-
return $css.position !== "static" && $css.display !== "none";
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 查询元素的z-index
|
|
58
|
-
* 并比较值是否是已获取的最大值
|
|
59
|
-
* @param $ele
|
|
60
|
-
*/
|
|
61
|
-
function queryMaxZIndex($ele: Element) {
|
|
62
|
-
if (typeof ignoreCallBack === "function") {
|
|
63
|
-
const ignoreResult = ignoreCallBack($ele);
|
|
64
|
-
if (typeof ignoreResult === "boolean" && !ignoreResult) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/** 元素的样式 */
|
|
69
|
-
const nodeStyle = PopsCore.window.getComputedStyle($ele);
|
|
70
|
-
// 不对position为static和display为none的元素进行获取它们的z-index
|
|
71
|
-
if (isVisibleNode(nodeStyle)) {
|
|
72
|
-
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
73
|
-
if (!isNaN(nodeZIndex)) {
|
|
74
|
-
if (nodeZIndex > zIndex) {
|
|
75
|
-
// 赋值到全局
|
|
76
|
-
zIndex = nodeZIndex;
|
|
77
|
-
maxZIndexNode = $ele;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// 判断shadowRoot
|
|
81
|
-
if ($ele.shadowRoot != null && $ele instanceof ShadowRoot) {
|
|
82
|
-
$ele.shadowRoot.querySelectorAll("*").forEach(($shadowEle) => {
|
|
83
|
-
queryMaxZIndex($shadowEle);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
target.querySelectorAll("*").forEach(($ele) => {
|
|
89
|
-
queryMaxZIndex($ele);
|
|
90
|
-
});
|
|
91
|
-
zIndex += deviation;
|
|
92
|
-
if (zIndex >= maxZIndexCompare) {
|
|
93
|
-
// 最好不要超过最大值
|
|
94
|
-
zIndex = maxZIndexCompare;
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
node: maxZIndexNode!,
|
|
98
|
-
zIndex: zIndex,
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
/**
|
|
102
|
-
* 获取pops所有弹窗中的最大的z-index
|
|
103
|
-
* @param deviation
|
|
104
|
-
*/
|
|
105
|
-
getPopsMaxZIndex(deviation: number = 1) {
|
|
106
|
-
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
107
|
-
// 最大值 2147483647
|
|
108
|
-
// const browserMaxZIndex = Math.pow(2, 31) - 1;
|
|
109
|
-
// 比较值 2000000000
|
|
110
|
-
const maxZIndex = 2 * Math.pow(10, 9);
|
|
111
|
-
// 当前页面最大的z-index
|
|
112
|
-
let zIndex = 0;
|
|
113
|
-
// 当前的最大z-index的元素,调试使用
|
|
114
|
-
let maxZIndexNode = null as HTMLDivElement | null;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 元素是否可见
|
|
118
|
-
* @param $css
|
|
119
|
-
*/
|
|
120
|
-
function isVisibleNode($css: CSSStyleDeclaration): boolean {
|
|
121
|
-
return $css.position !== "static" && $css.display !== "none";
|
|
122
|
-
}
|
|
123
|
-
Object.keys(PopsInstData).forEach((instKeyName) => {
|
|
124
|
-
const instData = PopsInstData[instKeyName as PopsInstStoreType];
|
|
125
|
-
for (let index = 0; index < instData.length; index++) {
|
|
126
|
-
const inst = instData[index];
|
|
127
|
-
const nodeStyle = window.getComputedStyle(inst.$anim);
|
|
128
|
-
// 不对position为static和display为none的元素进行获取它们的z-index
|
|
129
|
-
if (isVisibleNode(nodeStyle)) {
|
|
130
|
-
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
131
|
-
if (!isNaN(nodeZIndex)) {
|
|
132
|
-
if (nodeZIndex > zIndex) {
|
|
133
|
-
zIndex = nodeZIndex;
|
|
134
|
-
maxZIndexNode = inst.$anim;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
zIndex += deviation;
|
|
141
|
-
const isOverMaxZIndex = zIndex >= maxZIndex;
|
|
142
|
-
if (isOverMaxZIndex) {
|
|
143
|
-
// 超出z-index最大值
|
|
144
|
-
zIndex = maxZIndex;
|
|
145
|
-
}
|
|
146
|
-
return { zIndex: zIndex, animElement: maxZIndexNode, isOverMaxZIndex };
|
|
147
|
-
},
|
|
148
|
-
/**
|
|
149
|
-
* 获取页面中最大的z-index
|
|
150
|
-
* @param deviation 获取最大的z-index值的偏移,默认是+1
|
|
151
|
-
* @example
|
|
152
|
-
* getMaxZIndex();
|
|
153
|
-
* > 1001
|
|
154
|
-
**/
|
|
155
|
-
getMaxZIndex(deviation = 1): number {
|
|
156
|
-
return this.getMaxZIndexNodeInfo(deviation).zIndex;
|
|
157
|
-
},
|
|
158
|
-
/**
|
|
159
|
-
* 删除配置中对应的对象
|
|
160
|
-
* @param totalInstConfigList 配置实例列表
|
|
161
|
-
* @param guid 唯一标识
|
|
162
|
-
* @param isAll 是否全部删除
|
|
163
|
-
*/
|
|
164
|
-
async removeInstance(totalInstConfigList: PopsInstGeneralConfig[][], guid?: string, isAll = false) {
|
|
165
|
-
/**
|
|
166
|
-
* 移除元素实例
|
|
167
|
-
* @param instCommonConfig
|
|
168
|
-
*/
|
|
169
|
-
const removeInst = function (instCommonConfig: PopsInstGeneralConfig) {
|
|
170
|
-
if (typeof instCommonConfig.beforeRemoveCallBack === "function") {
|
|
171
|
-
// 调用移除签的回调
|
|
172
|
-
instCommonConfig.beforeRemoveCallBack(instCommonConfig);
|
|
173
|
-
}
|
|
174
|
-
instCommonConfig?.$anim?.remove();
|
|
175
|
-
instCommonConfig?.$pops?.remove();
|
|
176
|
-
instCommonConfig?.$mask?.remove();
|
|
177
|
-
instCommonConfig?.$shadowContainer?.remove();
|
|
178
|
-
};
|
|
179
|
-
const asyncInstTask: Promise<void>[] = [];
|
|
180
|
-
// [ inst[], inst[],...]
|
|
181
|
-
totalInstConfigList.forEach((instConfigList) => {
|
|
182
|
-
// inst[]
|
|
183
|
-
instConfigList.forEach(async (instConfigItem, index) => {
|
|
184
|
-
// 移除全部或者guid相同
|
|
185
|
-
if (isAll || (typeof guid === "string" && instConfigItem.guid === guid)) {
|
|
186
|
-
// 判断是否有动画
|
|
187
|
-
const animName = instConfigItem.$anim.getAttribute("anim")!;
|
|
188
|
-
if (PopsAnimation.hasAnim(animName)) {
|
|
189
|
-
const reverseAnimName = animName + "-reverse";
|
|
190
|
-
popsDOMUtils.css(instConfigItem.$anim, "width", "100%");
|
|
191
|
-
popsDOMUtils.css(instConfigItem.$anim, "height", "100%");
|
|
192
|
-
popsDOMUtils.css(instConfigItem.$anim, "animation-name", reverseAnimName);
|
|
193
|
-
if (PopsAnimation.hasAnim(popsDOMUtils.css(instConfigItem.$anim, "animation-name"))) {
|
|
194
|
-
asyncInstTask.push(
|
|
195
|
-
new Promise<void>((resolve) => {
|
|
196
|
-
popsDOMUtils.on(
|
|
197
|
-
instConfigItem.$anim,
|
|
198
|
-
popsDOMUtils.getAnimationEndNameList(),
|
|
199
|
-
function () {
|
|
200
|
-
removeInst(instConfigItem);
|
|
201
|
-
resolve();
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
capture: true,
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
})
|
|
208
|
-
);
|
|
209
|
-
} else {
|
|
210
|
-
removeInst(instConfigItem);
|
|
211
|
-
}
|
|
212
|
-
} else {
|
|
213
|
-
removeInst(instConfigItem);
|
|
214
|
-
}
|
|
215
|
-
instConfigList.splice(index, 1);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
await Promise.all(asyncInstTask);
|
|
220
|
-
return totalInstConfigList;
|
|
221
|
-
},
|
|
222
|
-
/**
|
|
223
|
-
* 隐藏
|
|
224
|
-
* @param popsType
|
|
225
|
-
* @param instConfigList
|
|
226
|
-
* @param guid
|
|
227
|
-
* @param config
|
|
228
|
-
* @param $anim
|
|
229
|
-
* @param $mask
|
|
230
|
-
*/
|
|
231
|
-
hide(
|
|
232
|
-
config:
|
|
233
|
-
| PopsAlertConfig
|
|
234
|
-
| PopsDrawerConfig
|
|
235
|
-
| PopsPromptConfig
|
|
236
|
-
| PopsConfirmConfig
|
|
237
|
-
| PopsIframeConfig
|
|
238
|
-
| PopsLoadingConfig
|
|
239
|
-
| PopsPanelConfig
|
|
240
|
-
| PopsFolderConfig,
|
|
241
|
-
popsType: PopsInstStoreType,
|
|
242
|
-
instConfigList: PopsInstGeneralConfig[],
|
|
243
|
-
guid: string,
|
|
244
|
-
$anim: HTMLElement,
|
|
245
|
-
$mask?: HTMLElement
|
|
246
|
-
) {
|
|
247
|
-
return new Promise<void>((resolve) => {
|
|
248
|
-
const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
|
|
249
|
-
if (popsType === "drawer") {
|
|
250
|
-
const drawerConfig = config as Required<PopsDrawerConfig>;
|
|
251
|
-
popsUtils.setTimeout(() => {
|
|
252
|
-
if ($mask) {
|
|
253
|
-
popsDOMUtils.css($mask, "display", "none");
|
|
254
|
-
}
|
|
255
|
-
if (["top", "bottom"].includes(drawerConfig.direction)) {
|
|
256
|
-
$pops.style.setProperty("height", "0");
|
|
257
|
-
} else if (["left", "right"].includes(drawerConfig.direction)) {
|
|
258
|
-
$pops.style.setProperty("width", "0");
|
|
259
|
-
} else {
|
|
260
|
-
console.error("未知direction:", drawerConfig.direction);
|
|
261
|
-
}
|
|
262
|
-
resolve();
|
|
263
|
-
}, drawerConfig.closeDelay);
|
|
264
|
-
} else {
|
|
265
|
-
const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
|
|
266
|
-
if (fintInst) {
|
|
267
|
-
// 存在动画
|
|
268
|
-
const instConfigItem = fintInst;
|
|
269
|
-
instConfigItem.$anim.style.width = "100%";
|
|
270
|
-
instConfigItem.$anim.style.height = "100%";
|
|
271
|
-
Reflect.set(
|
|
272
|
-
instConfigItem.$anim.style,
|
|
273
|
-
"animation-name",
|
|
274
|
-
instConfigItem.$anim.getAttribute("anim") + "-reverse"
|
|
275
|
-
);
|
|
276
|
-
if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.$anim.style, "animation-name"))) {
|
|
277
|
-
/**
|
|
278
|
-
* 动画结束的回调
|
|
279
|
-
*/
|
|
280
|
-
function animationendCallBack() {
|
|
281
|
-
instConfigItem.$anim.style.display = "none";
|
|
282
|
-
if (instConfigItem.$mask) {
|
|
283
|
-
instConfigItem.$mask.style.display = "none";
|
|
284
|
-
}
|
|
285
|
-
popsDOMUtils.off(instConfigItem.$anim, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
|
|
286
|
-
capture: true,
|
|
287
|
-
});
|
|
288
|
-
resolve();
|
|
289
|
-
}
|
|
290
|
-
popsDOMUtils.on(instConfigItem.$anim, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
|
|
291
|
-
capture: true,
|
|
292
|
-
});
|
|
293
|
-
} else {
|
|
294
|
-
instConfigItem.$anim.style.display = "none";
|
|
295
|
-
if (instConfigItem.$mask) {
|
|
296
|
-
instConfigItem.$mask.style.display = "none";
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
resolve();
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
},
|
|
305
|
-
/**
|
|
306
|
-
* 显示
|
|
307
|
-
* @param popsType
|
|
308
|
-
* @param instConfigList
|
|
309
|
-
* @param guid
|
|
310
|
-
* @param config
|
|
311
|
-
* @param $anim
|
|
312
|
-
* @param $mask
|
|
313
|
-
*/
|
|
314
|
-
show(
|
|
315
|
-
config:
|
|
316
|
-
| PopsAlertConfig
|
|
317
|
-
| PopsDrawerConfig
|
|
318
|
-
| PopsPromptConfig
|
|
319
|
-
| PopsConfirmConfig
|
|
320
|
-
| PopsIframeConfig
|
|
321
|
-
| PopsLoadingConfig
|
|
322
|
-
| PopsPanelConfig
|
|
323
|
-
| PopsFolderConfig,
|
|
324
|
-
popsType: PopsInstStoreType,
|
|
325
|
-
instConfigList: PopsInstGeneralConfig[],
|
|
326
|
-
guid: string,
|
|
327
|
-
$anim: HTMLElement,
|
|
328
|
-
$mask?: HTMLElement
|
|
329
|
-
) {
|
|
330
|
-
return new Promise<void>((resolve) => {
|
|
331
|
-
const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
|
|
332
|
-
if (popsType === "drawer") {
|
|
333
|
-
const drawerConfig = config as PopsDrawerConfig;
|
|
334
|
-
popsUtils.setTimeout(() => {
|
|
335
|
-
if ($mask) {
|
|
336
|
-
popsDOMUtils.css($mask, "display", "");
|
|
337
|
-
}
|
|
338
|
-
const direction = drawerConfig.direction!;
|
|
339
|
-
const size = drawerConfig.size!.toString();
|
|
340
|
-
if (["top", "bottom"].includes(direction)) {
|
|
341
|
-
$pops.style.setProperty("height", size);
|
|
342
|
-
} else if (["left", "right"].includes(direction)) {
|
|
343
|
-
$pops.style.setProperty("width", size);
|
|
344
|
-
} else {
|
|
345
|
-
console.error("未知direction:", direction);
|
|
346
|
-
}
|
|
347
|
-
resolve();
|
|
348
|
-
}, drawerConfig.openDelay ?? 0);
|
|
349
|
-
} else {
|
|
350
|
-
const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
|
|
351
|
-
if (fintInst) {
|
|
352
|
-
const instConfigItem = fintInst;
|
|
353
|
-
instConfigItem.$anim.style.width = "";
|
|
354
|
-
instConfigItem.$anim.style.height = "";
|
|
355
|
-
Reflect.set(
|
|
356
|
-
instConfigItem.$anim.style,
|
|
357
|
-
"animation-name",
|
|
358
|
-
instConfigItem.$anim!.getAttribute("anim")!.replace("-reverse", "")
|
|
359
|
-
);
|
|
360
|
-
if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.$anim.style, "animation-name"))) {
|
|
361
|
-
/**
|
|
362
|
-
* 动画结束的回调
|
|
363
|
-
*/
|
|
364
|
-
function animationendCallBack() {
|
|
365
|
-
popsDOMUtils.off(instConfigItem.$anim, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
|
|
366
|
-
capture: true,
|
|
367
|
-
});
|
|
368
|
-
resolve();
|
|
369
|
-
}
|
|
370
|
-
instConfigItem.$anim.style.display = "";
|
|
371
|
-
if (instConfigItem.$mask) {
|
|
372
|
-
instConfigItem.$mask.style.display = "";
|
|
373
|
-
}
|
|
374
|
-
popsDOMUtils.on(instConfigItem.$anim, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
|
|
375
|
-
capture: true,
|
|
376
|
-
});
|
|
377
|
-
} else {
|
|
378
|
-
instConfigItem.$anim.style.display = "";
|
|
379
|
-
if (instConfigItem.$mask) {
|
|
380
|
-
instConfigItem.$mask.style.display = "";
|
|
381
|
-
}
|
|
382
|
-
resolve();
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
},
|
|
388
|
-
/**
|
|
389
|
-
* 关闭
|
|
390
|
-
* @param popsType
|
|
391
|
-
* @param instConfigList
|
|
392
|
-
* @param guid
|
|
393
|
-
* @param config
|
|
394
|
-
* @param $anim
|
|
395
|
-
*/
|
|
396
|
-
async close(
|
|
397
|
-
config:
|
|
398
|
-
| PopsAlertConfig
|
|
399
|
-
| PopsDrawerConfig
|
|
400
|
-
| PopsPromptConfig
|
|
401
|
-
| PopsConfirmConfig
|
|
402
|
-
| PopsIframeConfig
|
|
403
|
-
| PopsLoadingConfig
|
|
404
|
-
| PopsPanelConfig
|
|
405
|
-
| PopsFolderConfig,
|
|
406
|
-
popsType: string,
|
|
407
|
-
instConfigList: PopsInstGeneralConfig[],
|
|
408
|
-
guid: string,
|
|
409
|
-
$anim: HTMLElement
|
|
410
|
-
) {
|
|
411
|
-
// eslint-disable-next-line no-async-promise-executor
|
|
412
|
-
await new Promise<void>(async (resolve) => {
|
|
413
|
-
const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
|
|
414
|
-
const drawerConfig = config as Required<PopsDrawerConfig>;
|
|
415
|
-
/**
|
|
416
|
-
* 动画结束事件
|
|
417
|
-
*/
|
|
418
|
-
function transitionendEvent() {
|
|
419
|
-
/**
|
|
420
|
-
* 弹窗已关闭的回调
|
|
421
|
-
*/
|
|
422
|
-
async function closeCallBack(event: Event) {
|
|
423
|
-
if ((event as TransitionEvent).propertyName !== "transform") {
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
popsDOMUtils.off($pops, popsDOMUtils.getTransitionEndNameList(), closeCallBack);
|
|
427
|
-
await PopsInstanceUtils.removeInstance([instConfigList], guid);
|
|
428
|
-
resolve();
|
|
429
|
-
}
|
|
430
|
-
// 监听过渡结束
|
|
431
|
-
popsDOMUtils.on($pops, popsDOMUtils.getTransitionEndNameList(), closeCallBack);
|
|
432
|
-
const popsTransForm = getComputedStyle($pops).transform;
|
|
433
|
-
if (popsTransForm !== "none") {
|
|
434
|
-
popsDOMUtils.emit($pops, popsDOMUtils.getTransitionEndNameList(), void 0, true);
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
if (["top"].includes(drawerConfig.direction)) {
|
|
438
|
-
$pops.style.setProperty("transform", "translateY(-100%)");
|
|
439
|
-
} else if (["bottom"].includes(drawerConfig.direction)) {
|
|
440
|
-
$pops.style.setProperty("transform", "translateY(100%)");
|
|
441
|
-
} else if (["left"].includes(drawerConfig.direction)) {
|
|
442
|
-
$pops.style.setProperty("transform", "translateX(-100%)");
|
|
443
|
-
} else if (["right"].includes(drawerConfig.direction)) {
|
|
444
|
-
$pops.style.setProperty("transform", "translateX(100%)");
|
|
445
|
-
} else {
|
|
446
|
-
console.error("未知direction:", drawerConfig.direction);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (popsType === "drawer") {
|
|
451
|
-
popsUtils.setTimeout(() => {
|
|
452
|
-
transitionendEvent();
|
|
453
|
-
}, drawerConfig.closeDelay);
|
|
454
|
-
} else {
|
|
455
|
-
await PopsInstanceUtils.removeInstance([instConfigList], guid);
|
|
456
|
-
resolve();
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
// 判断组件内是否有rightClickMenu、tooltip、searchSuggestion组件
|
|
461
|
-
// 有的话也需要关闭
|
|
462
|
-
PopsInstData.rightClickMenu.forEach((itemConfig) => {
|
|
463
|
-
const config = itemConfig.config as PopsRightClickMenuConfig;
|
|
464
|
-
if (config.$target instanceof HTMLElement) {
|
|
465
|
-
const $root = config.$target.getRootNode();
|
|
466
|
-
if ($root instanceof HTMLElement && $root.parentElement == null) {
|
|
467
|
-
// 触发销毁元素
|
|
468
|
-
itemConfig.destory();
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
PopsInstData.tooltip.forEach((itemConfig) => {
|
|
473
|
-
const config = itemConfig.config as PopsToolTipConfig;
|
|
474
|
-
if (config.$target instanceof HTMLElement) {
|
|
475
|
-
const $root = config.$target.getRootNode();
|
|
476
|
-
if ($root instanceof HTMLElement && $root.parentElement == null) {
|
|
477
|
-
// 触发销毁元素
|
|
478
|
-
itemConfig.destory();
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
},
|
|
483
|
-
/**
|
|
484
|
-
* 拖拽元素
|
|
485
|
-
* 说明:
|
|
486
|
-
* + 元素的position为absolute或者fixed
|
|
487
|
-
* + 会为元素的
|
|
488
|
-
* @param $move 需要拖拽的元素
|
|
489
|
-
* @param options 配置
|
|
490
|
-
*/
|
|
491
|
-
drag(
|
|
492
|
-
$move: HTMLElement,
|
|
493
|
-
options: {
|
|
494
|
-
dragElement: HTMLElement;
|
|
495
|
-
limit: boolean;
|
|
496
|
-
emitClick?: boolean;
|
|
497
|
-
extraDistance: number;
|
|
498
|
-
container?: Window | typeof globalThis | HTMLElement;
|
|
499
|
-
moveCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
|
|
500
|
-
endCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
|
|
501
|
-
preventEvent?: (event: TouchEvent | PointerEvent) => boolean;
|
|
502
|
-
}
|
|
503
|
-
) {
|
|
504
|
-
options = Object.assign(
|
|
505
|
-
{
|
|
506
|
-
limit: true,
|
|
507
|
-
extraDistance: 3,
|
|
508
|
-
container: PopsCore.globalThis,
|
|
509
|
-
emitClick: true,
|
|
510
|
-
},
|
|
511
|
-
options
|
|
512
|
-
);
|
|
513
|
-
let isMove = false;
|
|
514
|
-
// 点击元素,left偏移
|
|
515
|
-
let clickElementLeftOffset = 0;
|
|
516
|
-
// 点击元素,top偏移
|
|
517
|
-
let clickElementTopOffset = 0;
|
|
518
|
-
const AnyTouch = popsUtils.AnyTouch();
|
|
519
|
-
const anyTouchElement = new AnyTouch(options.dragElement, {
|
|
520
|
-
preventDefault(event: Event) {
|
|
521
|
-
if (typeof options.preventEvent === "function") {
|
|
522
|
-
return options.preventEvent(event as any);
|
|
523
|
-
} else {
|
|
524
|
-
// 返回true阻止滑动
|
|
525
|
-
return true;
|
|
526
|
-
}
|
|
527
|
-
},
|
|
528
|
-
});
|
|
529
|
-
popsDOMUtils.css(options.dragElement, {
|
|
530
|
-
cursor: "move",
|
|
531
|
-
});
|
|
532
|
-
/**
|
|
533
|
-
* 修改移动的元素的style
|
|
534
|
-
*/
|
|
535
|
-
function changeMoveElementStyle(element: HTMLElement) {
|
|
536
|
-
const old_transitionDuration = element.style.transitionDuration;
|
|
537
|
-
if (globalThis.getComputedStyle(element).transitionDuration !== "0s") {
|
|
538
|
-
element.style.transitionDuration = "0s";
|
|
539
|
-
}
|
|
540
|
-
return () => {
|
|
541
|
-
element.style.transitionDuration = old_transitionDuration;
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* 获取容器的高度、宽度,一般是window为容器
|
|
546
|
-
*/
|
|
547
|
-
function getContainerWidthOrHeight(container: HTMLElement | Window | typeof globalThis) {
|
|
548
|
-
container = container ?? globalThis;
|
|
549
|
-
return {
|
|
550
|
-
width: popsDOMUtils.width(container),
|
|
551
|
-
height: popsDOMUtils.height(container),
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* 获取容器的最小left、top偏移
|
|
556
|
-
*/
|
|
557
|
-
|
|
558
|
-
function getContainerTopOrLeft(container: HTMLElement | Window | typeof globalThis) {
|
|
559
|
-
container = container ?? globalThis;
|
|
560
|
-
if (popsUtils.isWin(container)) {
|
|
561
|
-
return {
|
|
562
|
-
left: 0,
|
|
563
|
-
top: 0,
|
|
564
|
-
};
|
|
565
|
-
} else {
|
|
566
|
-
const rect = (container as HTMLElement).getBoundingClientRect();
|
|
567
|
-
return {
|
|
568
|
-
left: rect.left,
|
|
569
|
-
top: rect.top,
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
// 获取transform偏移
|
|
574
|
-
let transformInfo = popsDOMUtils.getTransform($move);
|
|
575
|
-
|
|
576
|
-
let resumeMoveElementStyle: ((...args: any[]) => any) | null = null;
|
|
577
|
-
|
|
578
|
-
anyTouchElement.on("pan", function (event) {
|
|
579
|
-
if (!isMove) {
|
|
580
|
-
isMove = true;
|
|
581
|
-
const rect = options.dragElement.getBoundingClientRect();
|
|
582
|
-
clickElementLeftOffset = event.x - rect.left;
|
|
583
|
-
clickElementTopOffset = event.y - rect.top;
|
|
584
|
-
transformInfo = popsDOMUtils.getTransform($move);
|
|
585
|
-
//if (event.nativeEvent.offsetX) {
|
|
586
|
-
// clickElementLeftOffset = parseInt(event.nativeEvent.offsetX);
|
|
587
|
-
//} else {
|
|
588
|
-
// clickElementLeftOffset = parseInt(event.getOffset().x);
|
|
589
|
-
//}
|
|
590
|
-
//if (event.nativeEvent.offsetY) {
|
|
591
|
-
// clickElementTopOffset = parseInt(event.nativeEvent.offsetY);
|
|
592
|
-
//} else {
|
|
593
|
-
// clickElementTopOffset = parseInt(event.getOffset().y);
|
|
594
|
-
//}
|
|
595
|
-
resumeMoveElementStyle = changeMoveElementStyle($move);
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
/** 当前移动的left偏移 */
|
|
599
|
-
let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformInfo.transformLeft;
|
|
600
|
-
/** 当前移动的top偏移 */
|
|
601
|
-
let currentMoveTopOffset = event.y - clickElementTopOffset + transformInfo.transformTop;
|
|
602
|
-
// 拖拽移动
|
|
603
|
-
if (event.phase === "move") {
|
|
604
|
-
if (options.limit) {
|
|
605
|
-
// 限制在容器内移动
|
|
606
|
-
// left偏移最大值
|
|
607
|
-
const maxLeftOffset =
|
|
608
|
-
getContainerWidthOrHeight(options.container!).width -
|
|
609
|
-
popsDOMUtils.width($move) +
|
|
610
|
-
transformInfo.transformLeft;
|
|
611
|
-
const { left: minLeftOffset, top: minTopOffset } = getContainerTopOrLeft(options.container!);
|
|
612
|
-
// top偏移的最大值
|
|
613
|
-
const maxTopOffset =
|
|
614
|
-
getContainerWidthOrHeight(options.container!).height -
|
|
615
|
-
popsDOMUtils.height($move) +
|
|
616
|
-
transformInfo.transformTop;
|
|
617
|
-
if (currentMoveLeftOffset > maxLeftOffset) {
|
|
618
|
-
// 不允许超过容器的最大宽度
|
|
619
|
-
currentMoveLeftOffset = maxLeftOffset;
|
|
620
|
-
}
|
|
621
|
-
if (currentMoveTopOffset > maxTopOffset) {
|
|
622
|
-
// 不允许超过容器的最大高度
|
|
623
|
-
currentMoveTopOffset = maxTopOffset;
|
|
624
|
-
}
|
|
625
|
-
if (currentMoveLeftOffset - options.extraDistance * 2 < minLeftOffset + transformInfo.transformLeft) {
|
|
626
|
-
// 不允许left偏移小于容器最小值
|
|
627
|
-
currentMoveLeftOffset = minLeftOffset + transformInfo.transformLeft;
|
|
628
|
-
// 最左边 +额外距离
|
|
629
|
-
currentMoveLeftOffset += options.extraDistance;
|
|
630
|
-
} else {
|
|
631
|
-
// 最右边 -额外距离
|
|
632
|
-
currentMoveLeftOffset -= options.extraDistance;
|
|
633
|
-
}
|
|
634
|
-
if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformInfo.transformTop) {
|
|
635
|
-
// 不允许top偏移小于容器最小值
|
|
636
|
-
currentMoveTopOffset = minTopOffset + transformInfo.transformTop;
|
|
637
|
-
// 最上面 +额外距离
|
|
638
|
-
currentMoveTopOffset += options.extraDistance;
|
|
639
|
-
} else {
|
|
640
|
-
// 最下面 -额外距离
|
|
641
|
-
currentMoveTopOffset -= options.extraDistance;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
if (typeof options.moveCallBack === "function") {
|
|
645
|
-
options.moveCallBack($move, currentMoveLeftOffset, currentMoveTopOffset);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
popsDOMUtils.css($move, {
|
|
649
|
-
left: currentMoveLeftOffset + "px",
|
|
650
|
-
top: currentMoveTopOffset + "px",
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
// 停止拖拽
|
|
655
|
-
if (event.phase === "end") {
|
|
656
|
-
isMove = false;
|
|
657
|
-
if (typeof resumeMoveElementStyle === "function") {
|
|
658
|
-
resumeMoveElementStyle();
|
|
659
|
-
resumeMoveElementStyle = null;
|
|
660
|
-
}
|
|
661
|
-
if (typeof options.endCallBack === "function") {
|
|
662
|
-
options.endCallBack($move, currentMoveLeftOffset, currentMoveTopOffset);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
if (options.emitClick) {
|
|
667
|
-
// 因为会覆盖上面的点击事件,主动触发一下
|
|
668
|
-
anyTouchElement.on(["tap"], function (event) {
|
|
669
|
-
event.changedPoints.forEach((item) => {
|
|
670
|
-
popsDOMUtils.emit(item.target! as HTMLElement, "click", void 0, true);
|
|
671
|
-
});
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
},
|
|
675
|
-
/**
|
|
676
|
-
* 排序数组
|
|
677
|
-
* @param getBeforeValueFun
|
|
678
|
-
* @param getAfterValueFun
|
|
679
|
-
* @param sortByDesc 排序是否降序,默认降序
|
|
680
|
-
*/
|
|
681
|
-
sortElementListByProperty<T, R>(
|
|
682
|
-
getBeforeValueFun: (value: T) => R,
|
|
683
|
-
getAfterValueFun: (value: T) => R,
|
|
684
|
-
sortByDesc = true
|
|
685
|
-
) {
|
|
686
|
-
if (typeof sortByDesc !== "boolean") {
|
|
687
|
-
throw new TypeError("参数 sortByDesc 必须为boolean类型");
|
|
688
|
-
}
|
|
689
|
-
if (getBeforeValueFun == null || getAfterValueFun == null) {
|
|
690
|
-
throw new Error("获取前面的值或后面的值的方法不能为空");
|
|
691
|
-
}
|
|
692
|
-
return function (after_obj: T, before_obj: T) {
|
|
693
|
-
const beforeValue = getBeforeValueFun(before_obj); // 前
|
|
694
|
-
const afterValue = getAfterValueFun(after_obj); // 后
|
|
695
|
-
if (sortByDesc) {
|
|
696
|
-
if (afterValue > beforeValue) {
|
|
697
|
-
return -1;
|
|
698
|
-
} else if (afterValue < beforeValue) {
|
|
699
|
-
return 1;
|
|
700
|
-
} else {
|
|
701
|
-
return 0;
|
|
702
|
-
}
|
|
703
|
-
} else {
|
|
704
|
-
if (afterValue < beforeValue) {
|
|
705
|
-
return -1;
|
|
706
|
-
} else if (afterValue > beforeValue) {
|
|
707
|
-
return 1;
|
|
708
|
-
} else {
|
|
709
|
-
return 0;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
};
|
|
713
|
-
},
|
|
714
|
-
};
|
|
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
|
+
import { popsDOMUtils } from "./PopsDOMUtils";
|
|
12
|
+
import { popsUtils } from "./PopsUtils";
|
|
13
|
+
import { PopsCore } from "../PopsCore";
|
|
14
|
+
import { PopsInstData } from "../PopsInst";
|
|
15
|
+
import { PopsAnimation } from "../PopsAnimation";
|
|
16
|
+
import type { PopsRightClickMenuConfig } from "../components/rightClickMenu/types";
|
|
17
|
+
import type { PopsToolTipConfig } from "../components/tooltip/types";
|
|
18
|
+
|
|
19
|
+
export const PopsInstanceUtils = {
|
|
20
|
+
/**
|
|
21
|
+
* 获取页面中最大的z-index的元素信息
|
|
22
|
+
* @param deviation 获取最大的z-index值的偏移,默认是+1
|
|
23
|
+
* @param node 进行判断的元素,默认是document
|
|
24
|
+
* @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
|
|
25
|
+
* @example
|
|
26
|
+
* Utils.getMaxZIndexNodeInfo();
|
|
27
|
+
* > {
|
|
28
|
+
* node: ...,
|
|
29
|
+
* zIndex: 1001
|
|
30
|
+
* }
|
|
31
|
+
**/
|
|
32
|
+
getMaxZIndexNodeInfo(
|
|
33
|
+
deviation = 1,
|
|
34
|
+
target: Element | ShadowRoot | Document = PopsCore.document,
|
|
35
|
+
ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
|
|
36
|
+
): {
|
|
37
|
+
node: Element;
|
|
38
|
+
zIndex: number;
|
|
39
|
+
} {
|
|
40
|
+
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
41
|
+
// 最大值 2147483647
|
|
42
|
+
// const maxZIndex = Math.pow(2, 31) - 1;
|
|
43
|
+
// 比较值 2000000000
|
|
44
|
+
const maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
45
|
+
// 当前页面最大的z-index
|
|
46
|
+
let zIndex = 0;
|
|
47
|
+
// 当前的最大z-index的元素,调试使用
|
|
48
|
+
let maxZIndexNode: Element | null = null;
|
|
49
|
+
/**
|
|
50
|
+
* 元素是否可见
|
|
51
|
+
* @param $css
|
|
52
|
+
*/
|
|
53
|
+
function isVisibleNode($css: CSSStyleDeclaration): boolean {
|
|
54
|
+
return $css.position !== "static" && $css.display !== "none";
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 查询元素的z-index
|
|
58
|
+
* 并比较值是否是已获取的最大值
|
|
59
|
+
* @param $ele
|
|
60
|
+
*/
|
|
61
|
+
function queryMaxZIndex($ele: Element) {
|
|
62
|
+
if (typeof ignoreCallBack === "function") {
|
|
63
|
+
const ignoreResult = ignoreCallBack($ele);
|
|
64
|
+
if (typeof ignoreResult === "boolean" && !ignoreResult) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** 元素的样式 */
|
|
69
|
+
const nodeStyle = PopsCore.window.getComputedStyle($ele);
|
|
70
|
+
// 不对position为static和display为none的元素进行获取它们的z-index
|
|
71
|
+
if (isVisibleNode(nodeStyle)) {
|
|
72
|
+
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
73
|
+
if (!isNaN(nodeZIndex)) {
|
|
74
|
+
if (nodeZIndex > zIndex) {
|
|
75
|
+
// 赋值到全局
|
|
76
|
+
zIndex = nodeZIndex;
|
|
77
|
+
maxZIndexNode = $ele;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// 判断shadowRoot
|
|
81
|
+
if ($ele.shadowRoot != null && $ele instanceof ShadowRoot) {
|
|
82
|
+
$ele.shadowRoot.querySelectorAll("*").forEach(($shadowEle) => {
|
|
83
|
+
queryMaxZIndex($shadowEle);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
target.querySelectorAll("*").forEach(($ele) => {
|
|
89
|
+
queryMaxZIndex($ele);
|
|
90
|
+
});
|
|
91
|
+
zIndex += deviation;
|
|
92
|
+
if (zIndex >= maxZIndexCompare) {
|
|
93
|
+
// 最好不要超过最大值
|
|
94
|
+
zIndex = maxZIndexCompare;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
node: maxZIndexNode!,
|
|
98
|
+
zIndex: zIndex,
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* 获取pops所有弹窗中的最大的z-index
|
|
103
|
+
* @param deviation
|
|
104
|
+
*/
|
|
105
|
+
getPopsMaxZIndex(deviation: number = 1) {
|
|
106
|
+
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
107
|
+
// 最大值 2147483647
|
|
108
|
+
// const browserMaxZIndex = Math.pow(2, 31) - 1;
|
|
109
|
+
// 比较值 2000000000
|
|
110
|
+
const maxZIndex = 2 * Math.pow(10, 9);
|
|
111
|
+
// 当前页面最大的z-index
|
|
112
|
+
let zIndex = 0;
|
|
113
|
+
// 当前的最大z-index的元素,调试使用
|
|
114
|
+
let maxZIndexNode = null as HTMLDivElement | null;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 元素是否可见
|
|
118
|
+
* @param $css
|
|
119
|
+
*/
|
|
120
|
+
function isVisibleNode($css: CSSStyleDeclaration): boolean {
|
|
121
|
+
return $css.position !== "static" && $css.display !== "none";
|
|
122
|
+
}
|
|
123
|
+
Object.keys(PopsInstData).forEach((instKeyName) => {
|
|
124
|
+
const instData = PopsInstData[instKeyName as PopsInstStoreType];
|
|
125
|
+
for (let index = 0; index < instData.length; index++) {
|
|
126
|
+
const inst = instData[index];
|
|
127
|
+
const nodeStyle = window.getComputedStyle(inst.$anim);
|
|
128
|
+
// 不对position为static和display为none的元素进行获取它们的z-index
|
|
129
|
+
if (isVisibleNode(nodeStyle)) {
|
|
130
|
+
const nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
131
|
+
if (!isNaN(nodeZIndex)) {
|
|
132
|
+
if (nodeZIndex > zIndex) {
|
|
133
|
+
zIndex = nodeZIndex;
|
|
134
|
+
maxZIndexNode = inst.$anim;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
zIndex += deviation;
|
|
141
|
+
const isOverMaxZIndex = zIndex >= maxZIndex;
|
|
142
|
+
if (isOverMaxZIndex) {
|
|
143
|
+
// 超出z-index最大值
|
|
144
|
+
zIndex = maxZIndex;
|
|
145
|
+
}
|
|
146
|
+
return { zIndex: zIndex, animElement: maxZIndexNode, isOverMaxZIndex };
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* 获取页面中最大的z-index
|
|
150
|
+
* @param deviation 获取最大的z-index值的偏移,默认是+1
|
|
151
|
+
* @example
|
|
152
|
+
* getMaxZIndex();
|
|
153
|
+
* > 1001
|
|
154
|
+
**/
|
|
155
|
+
getMaxZIndex(deviation = 1): number {
|
|
156
|
+
return this.getMaxZIndexNodeInfo(deviation).zIndex;
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* 删除配置中对应的对象
|
|
160
|
+
* @param totalInstConfigList 配置实例列表
|
|
161
|
+
* @param guid 唯一标识
|
|
162
|
+
* @param isAll 是否全部删除
|
|
163
|
+
*/
|
|
164
|
+
async removeInstance(totalInstConfigList: PopsInstGeneralConfig[][], guid?: string, isAll = false) {
|
|
165
|
+
/**
|
|
166
|
+
* 移除元素实例
|
|
167
|
+
* @param instCommonConfig
|
|
168
|
+
*/
|
|
169
|
+
const removeInst = function (instCommonConfig: PopsInstGeneralConfig) {
|
|
170
|
+
if (typeof instCommonConfig.beforeRemoveCallBack === "function") {
|
|
171
|
+
// 调用移除签的回调
|
|
172
|
+
instCommonConfig.beforeRemoveCallBack(instCommonConfig);
|
|
173
|
+
}
|
|
174
|
+
instCommonConfig?.$anim?.remove();
|
|
175
|
+
instCommonConfig?.$pops?.remove();
|
|
176
|
+
instCommonConfig?.$mask?.remove();
|
|
177
|
+
instCommonConfig?.$shadowContainer?.remove();
|
|
178
|
+
};
|
|
179
|
+
const asyncInstTask: Promise<void>[] = [];
|
|
180
|
+
// [ inst[], inst[],...]
|
|
181
|
+
totalInstConfigList.forEach((instConfigList) => {
|
|
182
|
+
// inst[]
|
|
183
|
+
instConfigList.forEach(async (instConfigItem, index) => {
|
|
184
|
+
// 移除全部或者guid相同
|
|
185
|
+
if (isAll || (typeof guid === "string" && instConfigItem.guid === guid)) {
|
|
186
|
+
// 判断是否有动画
|
|
187
|
+
const animName = instConfigItem.$anim.getAttribute("anim")!;
|
|
188
|
+
if (PopsAnimation.hasAnim(animName)) {
|
|
189
|
+
const reverseAnimName = animName + "-reverse";
|
|
190
|
+
popsDOMUtils.css(instConfigItem.$anim, "width", "100%");
|
|
191
|
+
popsDOMUtils.css(instConfigItem.$anim, "height", "100%");
|
|
192
|
+
popsDOMUtils.css(instConfigItem.$anim, "animation-name", reverseAnimName);
|
|
193
|
+
if (PopsAnimation.hasAnim(popsDOMUtils.css(instConfigItem.$anim, "animation-name"))) {
|
|
194
|
+
asyncInstTask.push(
|
|
195
|
+
new Promise<void>((resolve) => {
|
|
196
|
+
popsDOMUtils.on(
|
|
197
|
+
instConfigItem.$anim,
|
|
198
|
+
popsDOMUtils.getAnimationEndNameList(),
|
|
199
|
+
function () {
|
|
200
|
+
removeInst(instConfigItem);
|
|
201
|
+
resolve();
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
capture: true,
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
})
|
|
208
|
+
);
|
|
209
|
+
} else {
|
|
210
|
+
removeInst(instConfigItem);
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
removeInst(instConfigItem);
|
|
214
|
+
}
|
|
215
|
+
instConfigList.splice(index, 1);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
await Promise.all(asyncInstTask);
|
|
220
|
+
return totalInstConfigList;
|
|
221
|
+
},
|
|
222
|
+
/**
|
|
223
|
+
* 隐藏
|
|
224
|
+
* @param popsType
|
|
225
|
+
* @param instConfigList
|
|
226
|
+
* @param guid
|
|
227
|
+
* @param config
|
|
228
|
+
* @param $anim
|
|
229
|
+
* @param $mask
|
|
230
|
+
*/
|
|
231
|
+
hide(
|
|
232
|
+
config:
|
|
233
|
+
| PopsAlertConfig
|
|
234
|
+
| PopsDrawerConfig
|
|
235
|
+
| PopsPromptConfig
|
|
236
|
+
| PopsConfirmConfig
|
|
237
|
+
| PopsIframeConfig
|
|
238
|
+
| PopsLoadingConfig
|
|
239
|
+
| PopsPanelConfig
|
|
240
|
+
| PopsFolderConfig,
|
|
241
|
+
popsType: PopsInstStoreType,
|
|
242
|
+
instConfigList: PopsInstGeneralConfig[],
|
|
243
|
+
guid: string,
|
|
244
|
+
$anim: HTMLElement,
|
|
245
|
+
$mask?: HTMLElement
|
|
246
|
+
) {
|
|
247
|
+
return new Promise<void>((resolve) => {
|
|
248
|
+
const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
|
|
249
|
+
if (popsType === "drawer") {
|
|
250
|
+
const drawerConfig = config as Required<PopsDrawerConfig>;
|
|
251
|
+
popsUtils.setTimeout(() => {
|
|
252
|
+
if ($mask) {
|
|
253
|
+
popsDOMUtils.css($mask, "display", "none");
|
|
254
|
+
}
|
|
255
|
+
if (["top", "bottom"].includes(drawerConfig.direction)) {
|
|
256
|
+
$pops.style.setProperty("height", "0");
|
|
257
|
+
} else if (["left", "right"].includes(drawerConfig.direction)) {
|
|
258
|
+
$pops.style.setProperty("width", "0");
|
|
259
|
+
} else {
|
|
260
|
+
console.error("未知direction:", drawerConfig.direction);
|
|
261
|
+
}
|
|
262
|
+
resolve();
|
|
263
|
+
}, drawerConfig.closeDelay);
|
|
264
|
+
} else {
|
|
265
|
+
const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
|
|
266
|
+
if (fintInst) {
|
|
267
|
+
// 存在动画
|
|
268
|
+
const instConfigItem = fintInst;
|
|
269
|
+
instConfigItem.$anim.style.width = "100%";
|
|
270
|
+
instConfigItem.$anim.style.height = "100%";
|
|
271
|
+
Reflect.set(
|
|
272
|
+
instConfigItem.$anim.style,
|
|
273
|
+
"animation-name",
|
|
274
|
+
instConfigItem.$anim.getAttribute("anim") + "-reverse"
|
|
275
|
+
);
|
|
276
|
+
if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.$anim.style, "animation-name"))) {
|
|
277
|
+
/**
|
|
278
|
+
* 动画结束的回调
|
|
279
|
+
*/
|
|
280
|
+
function animationendCallBack() {
|
|
281
|
+
instConfigItem.$anim.style.display = "none";
|
|
282
|
+
if (instConfigItem.$mask) {
|
|
283
|
+
instConfigItem.$mask.style.display = "none";
|
|
284
|
+
}
|
|
285
|
+
popsDOMUtils.off(instConfigItem.$anim, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
|
|
286
|
+
capture: true,
|
|
287
|
+
});
|
|
288
|
+
resolve();
|
|
289
|
+
}
|
|
290
|
+
popsDOMUtils.on(instConfigItem.$anim, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
|
|
291
|
+
capture: true,
|
|
292
|
+
});
|
|
293
|
+
} else {
|
|
294
|
+
instConfigItem.$anim.style.display = "none";
|
|
295
|
+
if (instConfigItem.$mask) {
|
|
296
|
+
instConfigItem.$mask.style.display = "none";
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
resolve();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
},
|
|
305
|
+
/**
|
|
306
|
+
* 显示
|
|
307
|
+
* @param popsType
|
|
308
|
+
* @param instConfigList
|
|
309
|
+
* @param guid
|
|
310
|
+
* @param config
|
|
311
|
+
* @param $anim
|
|
312
|
+
* @param $mask
|
|
313
|
+
*/
|
|
314
|
+
show(
|
|
315
|
+
config:
|
|
316
|
+
| PopsAlertConfig
|
|
317
|
+
| PopsDrawerConfig
|
|
318
|
+
| PopsPromptConfig
|
|
319
|
+
| PopsConfirmConfig
|
|
320
|
+
| PopsIframeConfig
|
|
321
|
+
| PopsLoadingConfig
|
|
322
|
+
| PopsPanelConfig
|
|
323
|
+
| PopsFolderConfig,
|
|
324
|
+
popsType: PopsInstStoreType,
|
|
325
|
+
instConfigList: PopsInstGeneralConfig[],
|
|
326
|
+
guid: string,
|
|
327
|
+
$anim: HTMLElement,
|
|
328
|
+
$mask?: HTMLElement
|
|
329
|
+
) {
|
|
330
|
+
return new Promise<void>((resolve) => {
|
|
331
|
+
const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
|
|
332
|
+
if (popsType === "drawer") {
|
|
333
|
+
const drawerConfig = config as PopsDrawerConfig;
|
|
334
|
+
popsUtils.setTimeout(() => {
|
|
335
|
+
if ($mask) {
|
|
336
|
+
popsDOMUtils.css($mask, "display", "");
|
|
337
|
+
}
|
|
338
|
+
const direction = drawerConfig.direction!;
|
|
339
|
+
const size = drawerConfig.size!.toString();
|
|
340
|
+
if (["top", "bottom"].includes(direction)) {
|
|
341
|
+
$pops.style.setProperty("height", size);
|
|
342
|
+
} else if (["left", "right"].includes(direction)) {
|
|
343
|
+
$pops.style.setProperty("width", size);
|
|
344
|
+
} else {
|
|
345
|
+
console.error("未知direction:", direction);
|
|
346
|
+
}
|
|
347
|
+
resolve();
|
|
348
|
+
}, drawerConfig.openDelay ?? 0);
|
|
349
|
+
} else {
|
|
350
|
+
const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
|
|
351
|
+
if (fintInst) {
|
|
352
|
+
const instConfigItem = fintInst;
|
|
353
|
+
instConfigItem.$anim.style.width = "";
|
|
354
|
+
instConfigItem.$anim.style.height = "";
|
|
355
|
+
Reflect.set(
|
|
356
|
+
instConfigItem.$anim.style,
|
|
357
|
+
"animation-name",
|
|
358
|
+
instConfigItem.$anim!.getAttribute("anim")!.replace("-reverse", "")
|
|
359
|
+
);
|
|
360
|
+
if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.$anim.style, "animation-name"))) {
|
|
361
|
+
/**
|
|
362
|
+
* 动画结束的回调
|
|
363
|
+
*/
|
|
364
|
+
function animationendCallBack() {
|
|
365
|
+
popsDOMUtils.off(instConfigItem.$anim, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
|
|
366
|
+
capture: true,
|
|
367
|
+
});
|
|
368
|
+
resolve();
|
|
369
|
+
}
|
|
370
|
+
instConfigItem.$anim.style.display = "";
|
|
371
|
+
if (instConfigItem.$mask) {
|
|
372
|
+
instConfigItem.$mask.style.display = "";
|
|
373
|
+
}
|
|
374
|
+
popsDOMUtils.on(instConfigItem.$anim, popsDOMUtils.getAnimationEndNameList(), animationendCallBack, {
|
|
375
|
+
capture: true,
|
|
376
|
+
});
|
|
377
|
+
} else {
|
|
378
|
+
instConfigItem.$anim.style.display = "";
|
|
379
|
+
if (instConfigItem.$mask) {
|
|
380
|
+
instConfigItem.$mask.style.display = "";
|
|
381
|
+
}
|
|
382
|
+
resolve();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
},
|
|
388
|
+
/**
|
|
389
|
+
* 关闭
|
|
390
|
+
* @param popsType
|
|
391
|
+
* @param instConfigList
|
|
392
|
+
* @param guid
|
|
393
|
+
* @param config
|
|
394
|
+
* @param $anim
|
|
395
|
+
*/
|
|
396
|
+
async close(
|
|
397
|
+
config:
|
|
398
|
+
| PopsAlertConfig
|
|
399
|
+
| PopsDrawerConfig
|
|
400
|
+
| PopsPromptConfig
|
|
401
|
+
| PopsConfirmConfig
|
|
402
|
+
| PopsIframeConfig
|
|
403
|
+
| PopsLoadingConfig
|
|
404
|
+
| PopsPanelConfig
|
|
405
|
+
| PopsFolderConfig,
|
|
406
|
+
popsType: string,
|
|
407
|
+
instConfigList: PopsInstGeneralConfig[],
|
|
408
|
+
guid: string,
|
|
409
|
+
$anim: HTMLElement
|
|
410
|
+
) {
|
|
411
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
412
|
+
await new Promise<void>(async (resolve) => {
|
|
413
|
+
const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
|
|
414
|
+
const drawerConfig = config as Required<PopsDrawerConfig>;
|
|
415
|
+
/**
|
|
416
|
+
* 动画结束事件
|
|
417
|
+
*/
|
|
418
|
+
function transitionendEvent() {
|
|
419
|
+
/**
|
|
420
|
+
* 弹窗已关闭的回调
|
|
421
|
+
*/
|
|
422
|
+
async function closeCallBack(event: Event) {
|
|
423
|
+
if ((event as TransitionEvent).propertyName !== "transform") {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
popsDOMUtils.off($pops, popsDOMUtils.getTransitionEndNameList(), closeCallBack);
|
|
427
|
+
await PopsInstanceUtils.removeInstance([instConfigList], guid);
|
|
428
|
+
resolve();
|
|
429
|
+
}
|
|
430
|
+
// 监听过渡结束
|
|
431
|
+
popsDOMUtils.on($pops, popsDOMUtils.getTransitionEndNameList(), closeCallBack);
|
|
432
|
+
const popsTransForm = getComputedStyle($pops).transform;
|
|
433
|
+
if (popsTransForm !== "none") {
|
|
434
|
+
popsDOMUtils.emit($pops, popsDOMUtils.getTransitionEndNameList(), void 0, true);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (["top"].includes(drawerConfig.direction)) {
|
|
438
|
+
$pops.style.setProperty("transform", "translateY(-100%)");
|
|
439
|
+
} else if (["bottom"].includes(drawerConfig.direction)) {
|
|
440
|
+
$pops.style.setProperty("transform", "translateY(100%)");
|
|
441
|
+
} else if (["left"].includes(drawerConfig.direction)) {
|
|
442
|
+
$pops.style.setProperty("transform", "translateX(-100%)");
|
|
443
|
+
} else if (["right"].includes(drawerConfig.direction)) {
|
|
444
|
+
$pops.style.setProperty("transform", "translateX(100%)");
|
|
445
|
+
} else {
|
|
446
|
+
console.error("未知direction:", drawerConfig.direction);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (popsType === "drawer") {
|
|
451
|
+
popsUtils.setTimeout(() => {
|
|
452
|
+
transitionendEvent();
|
|
453
|
+
}, drawerConfig.closeDelay);
|
|
454
|
+
} else {
|
|
455
|
+
await PopsInstanceUtils.removeInstance([instConfigList], guid);
|
|
456
|
+
resolve();
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// 判断组件内是否有rightClickMenu、tooltip、searchSuggestion组件
|
|
461
|
+
// 有的话也需要关闭
|
|
462
|
+
PopsInstData.rightClickMenu.forEach((itemConfig) => {
|
|
463
|
+
const config = itemConfig.config as PopsRightClickMenuConfig;
|
|
464
|
+
if (config.$target instanceof HTMLElement) {
|
|
465
|
+
const $root = config.$target.getRootNode();
|
|
466
|
+
if ($root instanceof HTMLElement && $root.parentElement == null) {
|
|
467
|
+
// 触发销毁元素
|
|
468
|
+
itemConfig.destory();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
PopsInstData.tooltip.forEach((itemConfig) => {
|
|
473
|
+
const config = itemConfig.config as PopsToolTipConfig;
|
|
474
|
+
if (config.$target instanceof HTMLElement) {
|
|
475
|
+
const $root = config.$target.getRootNode();
|
|
476
|
+
if ($root instanceof HTMLElement && $root.parentElement == null) {
|
|
477
|
+
// 触发销毁元素
|
|
478
|
+
itemConfig.destory();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
/**
|
|
484
|
+
* 拖拽元素
|
|
485
|
+
* 说明:
|
|
486
|
+
* + 元素的position为absolute或者fixed
|
|
487
|
+
* + 会为元素的
|
|
488
|
+
* @param $move 需要拖拽的元素
|
|
489
|
+
* @param options 配置
|
|
490
|
+
*/
|
|
491
|
+
drag(
|
|
492
|
+
$move: HTMLElement,
|
|
493
|
+
options: {
|
|
494
|
+
dragElement: HTMLElement;
|
|
495
|
+
limit: boolean;
|
|
496
|
+
emitClick?: boolean;
|
|
497
|
+
extraDistance: number;
|
|
498
|
+
container?: Window | typeof globalThis | HTMLElement;
|
|
499
|
+
moveCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
|
|
500
|
+
endCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
|
|
501
|
+
preventEvent?: (event: TouchEvent | PointerEvent) => boolean;
|
|
502
|
+
}
|
|
503
|
+
) {
|
|
504
|
+
options = Object.assign(
|
|
505
|
+
{
|
|
506
|
+
limit: true,
|
|
507
|
+
extraDistance: 3,
|
|
508
|
+
container: PopsCore.globalThis,
|
|
509
|
+
emitClick: true,
|
|
510
|
+
},
|
|
511
|
+
options
|
|
512
|
+
);
|
|
513
|
+
let isMove = false;
|
|
514
|
+
// 点击元素,left偏移
|
|
515
|
+
let clickElementLeftOffset = 0;
|
|
516
|
+
// 点击元素,top偏移
|
|
517
|
+
let clickElementTopOffset = 0;
|
|
518
|
+
const AnyTouch = popsUtils.AnyTouch();
|
|
519
|
+
const anyTouchElement = new AnyTouch(options.dragElement, {
|
|
520
|
+
preventDefault(event: Event) {
|
|
521
|
+
if (typeof options.preventEvent === "function") {
|
|
522
|
+
return options.preventEvent(event as any);
|
|
523
|
+
} else {
|
|
524
|
+
// 返回true阻止滑动
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
popsDOMUtils.css(options.dragElement, {
|
|
530
|
+
cursor: "move",
|
|
531
|
+
});
|
|
532
|
+
/**
|
|
533
|
+
* 修改移动的元素的style
|
|
534
|
+
*/
|
|
535
|
+
function changeMoveElementStyle(element: HTMLElement) {
|
|
536
|
+
const old_transitionDuration = element.style.transitionDuration;
|
|
537
|
+
if (globalThis.getComputedStyle(element).transitionDuration !== "0s") {
|
|
538
|
+
element.style.transitionDuration = "0s";
|
|
539
|
+
}
|
|
540
|
+
return () => {
|
|
541
|
+
element.style.transitionDuration = old_transitionDuration;
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* 获取容器的高度、宽度,一般是window为容器
|
|
546
|
+
*/
|
|
547
|
+
function getContainerWidthOrHeight(container: HTMLElement | Window | typeof globalThis) {
|
|
548
|
+
container = container ?? globalThis;
|
|
549
|
+
return {
|
|
550
|
+
width: popsDOMUtils.width(container),
|
|
551
|
+
height: popsDOMUtils.height(container),
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* 获取容器的最小left、top偏移
|
|
556
|
+
*/
|
|
557
|
+
|
|
558
|
+
function getContainerTopOrLeft(container: HTMLElement | Window | typeof globalThis) {
|
|
559
|
+
container = container ?? globalThis;
|
|
560
|
+
if (popsUtils.isWin(container)) {
|
|
561
|
+
return {
|
|
562
|
+
left: 0,
|
|
563
|
+
top: 0,
|
|
564
|
+
};
|
|
565
|
+
} else {
|
|
566
|
+
const rect = (container as HTMLElement).getBoundingClientRect();
|
|
567
|
+
return {
|
|
568
|
+
left: rect.left,
|
|
569
|
+
top: rect.top,
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
// 获取transform偏移
|
|
574
|
+
let transformInfo = popsDOMUtils.getTransform($move);
|
|
575
|
+
|
|
576
|
+
let resumeMoveElementStyle: ((...args: any[]) => any) | null = null;
|
|
577
|
+
|
|
578
|
+
anyTouchElement.on("pan", function (event) {
|
|
579
|
+
if (!isMove) {
|
|
580
|
+
isMove = true;
|
|
581
|
+
const rect = options.dragElement.getBoundingClientRect();
|
|
582
|
+
clickElementLeftOffset = event.x - rect.left;
|
|
583
|
+
clickElementTopOffset = event.y - rect.top;
|
|
584
|
+
transformInfo = popsDOMUtils.getTransform($move);
|
|
585
|
+
//if (event.nativeEvent.offsetX) {
|
|
586
|
+
// clickElementLeftOffset = parseInt(event.nativeEvent.offsetX);
|
|
587
|
+
//} else {
|
|
588
|
+
// clickElementLeftOffset = parseInt(event.getOffset().x);
|
|
589
|
+
//}
|
|
590
|
+
//if (event.nativeEvent.offsetY) {
|
|
591
|
+
// clickElementTopOffset = parseInt(event.nativeEvent.offsetY);
|
|
592
|
+
//} else {
|
|
593
|
+
// clickElementTopOffset = parseInt(event.getOffset().y);
|
|
594
|
+
//}
|
|
595
|
+
resumeMoveElementStyle = changeMoveElementStyle($move);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** 当前移动的left偏移 */
|
|
599
|
+
let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformInfo.transformLeft;
|
|
600
|
+
/** 当前移动的top偏移 */
|
|
601
|
+
let currentMoveTopOffset = event.y - clickElementTopOffset + transformInfo.transformTop;
|
|
602
|
+
// 拖拽移动
|
|
603
|
+
if (event.phase === "move") {
|
|
604
|
+
if (options.limit) {
|
|
605
|
+
// 限制在容器内移动
|
|
606
|
+
// left偏移最大值
|
|
607
|
+
const maxLeftOffset =
|
|
608
|
+
getContainerWidthOrHeight(options.container!).width -
|
|
609
|
+
popsDOMUtils.width($move) +
|
|
610
|
+
transformInfo.transformLeft;
|
|
611
|
+
const { left: minLeftOffset, top: minTopOffset } = getContainerTopOrLeft(options.container!);
|
|
612
|
+
// top偏移的最大值
|
|
613
|
+
const maxTopOffset =
|
|
614
|
+
getContainerWidthOrHeight(options.container!).height -
|
|
615
|
+
popsDOMUtils.height($move) +
|
|
616
|
+
transformInfo.transformTop;
|
|
617
|
+
if (currentMoveLeftOffset > maxLeftOffset) {
|
|
618
|
+
// 不允许超过容器的最大宽度
|
|
619
|
+
currentMoveLeftOffset = maxLeftOffset;
|
|
620
|
+
}
|
|
621
|
+
if (currentMoveTopOffset > maxTopOffset) {
|
|
622
|
+
// 不允许超过容器的最大高度
|
|
623
|
+
currentMoveTopOffset = maxTopOffset;
|
|
624
|
+
}
|
|
625
|
+
if (currentMoveLeftOffset - options.extraDistance * 2 < minLeftOffset + transformInfo.transformLeft) {
|
|
626
|
+
// 不允许left偏移小于容器最小值
|
|
627
|
+
currentMoveLeftOffset = minLeftOffset + transformInfo.transformLeft;
|
|
628
|
+
// 最左边 +额外距离
|
|
629
|
+
currentMoveLeftOffset += options.extraDistance;
|
|
630
|
+
} else {
|
|
631
|
+
// 最右边 -额外距离
|
|
632
|
+
currentMoveLeftOffset -= options.extraDistance;
|
|
633
|
+
}
|
|
634
|
+
if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformInfo.transformTop) {
|
|
635
|
+
// 不允许top偏移小于容器最小值
|
|
636
|
+
currentMoveTopOffset = minTopOffset + transformInfo.transformTop;
|
|
637
|
+
// 最上面 +额外距离
|
|
638
|
+
currentMoveTopOffset += options.extraDistance;
|
|
639
|
+
} else {
|
|
640
|
+
// 最下面 -额外距离
|
|
641
|
+
currentMoveTopOffset -= options.extraDistance;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (typeof options.moveCallBack === "function") {
|
|
645
|
+
options.moveCallBack($move, currentMoveLeftOffset, currentMoveTopOffset);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
popsDOMUtils.css($move, {
|
|
649
|
+
left: currentMoveLeftOffset + "px",
|
|
650
|
+
top: currentMoveTopOffset + "px",
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// 停止拖拽
|
|
655
|
+
if (event.phase === "end") {
|
|
656
|
+
isMove = false;
|
|
657
|
+
if (typeof resumeMoveElementStyle === "function") {
|
|
658
|
+
resumeMoveElementStyle();
|
|
659
|
+
resumeMoveElementStyle = null;
|
|
660
|
+
}
|
|
661
|
+
if (typeof options.endCallBack === "function") {
|
|
662
|
+
options.endCallBack($move, currentMoveLeftOffset, currentMoveTopOffset);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
if (options.emitClick) {
|
|
667
|
+
// 因为会覆盖上面的点击事件,主动触发一下
|
|
668
|
+
anyTouchElement.on(["tap"], function (event) {
|
|
669
|
+
event.changedPoints.forEach((item) => {
|
|
670
|
+
popsDOMUtils.emit(item.target! as HTMLElement, "click", void 0, true);
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
/**
|
|
676
|
+
* 排序数组
|
|
677
|
+
* @param getBeforeValueFun
|
|
678
|
+
* @param getAfterValueFun
|
|
679
|
+
* @param sortByDesc 排序是否降序,默认降序
|
|
680
|
+
*/
|
|
681
|
+
sortElementListByProperty<T, R>(
|
|
682
|
+
getBeforeValueFun: (value: T) => R,
|
|
683
|
+
getAfterValueFun: (value: T) => R,
|
|
684
|
+
sortByDesc = true
|
|
685
|
+
) {
|
|
686
|
+
if (typeof sortByDesc !== "boolean") {
|
|
687
|
+
throw new TypeError("参数 sortByDesc 必须为boolean类型");
|
|
688
|
+
}
|
|
689
|
+
if (getBeforeValueFun == null || getAfterValueFun == null) {
|
|
690
|
+
throw new Error("获取前面的值或后面的值的方法不能为空");
|
|
691
|
+
}
|
|
692
|
+
return function (after_obj: T, before_obj: T) {
|
|
693
|
+
const beforeValue = getBeforeValueFun(before_obj); // 前
|
|
694
|
+
const afterValue = getAfterValueFun(after_obj); // 后
|
|
695
|
+
if (sortByDesc) {
|
|
696
|
+
if (afterValue > beforeValue) {
|
|
697
|
+
return -1;
|
|
698
|
+
} else if (afterValue < beforeValue) {
|
|
699
|
+
return 1;
|
|
700
|
+
} else {
|
|
701
|
+
return 0;
|
|
702
|
+
}
|
|
703
|
+
} else {
|
|
704
|
+
if (afterValue < beforeValue) {
|
|
705
|
+
return -1;
|
|
706
|
+
} else if (afterValue > beforeValue) {
|
|
707
|
+
return 1;
|
|
708
|
+
} else {
|
|
709
|
+
return 0;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
},
|
|
714
|
+
};
|