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