@whitesev/pops 3.2.1 → 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 -1403
- 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,611 +1,611 @@
|
|
|
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 { PopsCore } from "../PopsCore";
|
|
10
|
-
import { PopsAnimation } from "../PopsAnimation";
|
|
11
|
-
import { PopsInstData } from "../PopsInst";
|
|
12
|
-
import type { PopsGeneralConfig } from "../types/components";
|
|
13
|
-
import type { PopsEventConfig, PopsHandlerEventConfig } from "../types/event";
|
|
14
|
-
import type { PopsInstGeneralConfig } from "../types/inst";
|
|
15
|
-
import type { PopsInstStoreType, PopsType, PopsSupportAnimConfigType, PopsSupportOnlyConfig } from "../types/main";
|
|
16
|
-
import { popsDOMUtils } from "../utils/PopsDOMUtils";
|
|
17
|
-
import { PopsInstanceUtils } from "../utils/PopsInstanceUtils";
|
|
18
|
-
import { popsUtils } from "../utils/PopsUtils";
|
|
19
|
-
|
|
20
|
-
export const PopsHandler = {
|
|
21
|
-
/**
|
|
22
|
-
* 创建shadow
|
|
23
|
-
*/
|
|
24
|
-
handlerShadow(config: Pick<PopsGeneralConfig, "useShadowRoot">) {
|
|
25
|
-
const $shadowContainer = popsDOMUtils.createElement("div", {
|
|
26
|
-
className: "pops-shadow-container",
|
|
27
|
-
});
|
|
28
|
-
if (config.useShadowRoot) {
|
|
29
|
-
const $shadowRoot = $shadowContainer.attachShadow({ mode: "open" });
|
|
30
|
-
return {
|
|
31
|
-
$shadowContainer,
|
|
32
|
-
$shadowRoot,
|
|
33
|
-
};
|
|
34
|
-
} else {
|
|
35
|
-
return {
|
|
36
|
-
$shadowContainer,
|
|
37
|
-
$shadowRoot: $shadowContainer,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* 处理初始化
|
|
43
|
-
* @param $styleParent style元素的父元素
|
|
44
|
-
* @param css 添加进ShadowRoot的CSS
|
|
45
|
-
*/
|
|
46
|
-
handleInit(
|
|
47
|
-
$styleParent?: ShadowRoot | HTMLElement,
|
|
48
|
-
css?:
|
|
49
|
-
| string
|
|
50
|
-
| string[]
|
|
51
|
-
| {
|
|
52
|
-
name?: string;
|
|
53
|
-
css: string;
|
|
54
|
-
}[]
|
|
55
|
-
) {
|
|
56
|
-
PopsAnimation.init();
|
|
57
|
-
if (!arguments.length) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if ($styleParent == null) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (css == null) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (typeof css === "string") {
|
|
68
|
-
if (css.trim() === "") {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
css = [
|
|
72
|
-
{
|
|
73
|
-
css: css,
|
|
74
|
-
},
|
|
75
|
-
];
|
|
76
|
-
} else {
|
|
77
|
-
css = css.map((item) => {
|
|
78
|
-
if (typeof item === "string") {
|
|
79
|
-
return {
|
|
80
|
-
css: item,
|
|
81
|
-
};
|
|
82
|
-
} else {
|
|
83
|
-
return item;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
for (const cssItem of css) {
|
|
88
|
-
const $css = popsDOMUtils.createElement(
|
|
89
|
-
"style",
|
|
90
|
-
{},
|
|
91
|
-
{
|
|
92
|
-
"data-type": "PopsHandler.handleInit",
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
$css.textContent = cssItem.css;
|
|
96
|
-
if (typeof cssItem.name === "string") {
|
|
97
|
-
$css.setAttribute("data-name", cssItem.name);
|
|
98
|
-
}
|
|
99
|
-
$styleParent.appendChild($css);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
/**
|
|
103
|
-
* 处理遮罩层
|
|
104
|
-
*
|
|
105
|
-
* + 设置遮罩层的点击事件
|
|
106
|
-
* @param config 传递的配置
|
|
107
|
-
*/
|
|
108
|
-
handleMask(
|
|
109
|
-
config = {} as {
|
|
110
|
-
type: "alert" | "confirm" | "prompt" | "loading" | "iframe" | "drawer" | "folder" | "panel";
|
|
111
|
-
guid: string;
|
|
112
|
-
config:
|
|
113
|
-
| Required<PopsAlertConfig>
|
|
114
|
-
| Required<PopsLoadingConfig>
|
|
115
|
-
| Required<PopsIframeConfig>
|
|
116
|
-
| Required<PopsDrawerConfig>
|
|
117
|
-
| Required<PopsPanelConfig>
|
|
118
|
-
| Required<PopsFolderConfig>;
|
|
119
|
-
animElement: HTMLElement;
|
|
120
|
-
maskHTML: string;
|
|
121
|
-
}
|
|
122
|
-
) {
|
|
123
|
-
const result = {
|
|
124
|
-
maskElement: popsDOMUtils.parseTextToDOM<HTMLDivElement>(config.maskHTML),
|
|
125
|
-
};
|
|
126
|
-
let isMaskClick = false;
|
|
127
|
-
/**
|
|
128
|
-
* 点击其它区域的事件
|
|
129
|
-
* @param event
|
|
130
|
-
*/
|
|
131
|
-
function clickEvent(event: MouseEvent | PointerEvent) {
|
|
132
|
-
popsDOMUtils.preventEvent(event);
|
|
133
|
-
// 获取该类型实例存储列表
|
|
134
|
-
const targetInst = PopsInstData[config.type];
|
|
135
|
-
function originalRun() {
|
|
136
|
-
if (config.config.mask!.clickEvent!.toClose) {
|
|
137
|
-
// 关闭
|
|
138
|
-
return PopsInstanceUtils.close(config.config, config.type, targetInst, config.guid, config.animElement);
|
|
139
|
-
} else if (config.config.mask!.clickEvent!.toHide) {
|
|
140
|
-
// 隐藏
|
|
141
|
-
return PopsInstanceUtils.hide(
|
|
142
|
-
config.config,
|
|
143
|
-
config.type,
|
|
144
|
-
targetInst,
|
|
145
|
-
config.guid,
|
|
146
|
-
config.animElement,
|
|
147
|
-
result.maskElement
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (typeof config.config.mask.clickCallBack === "function") {
|
|
152
|
-
config.config.mask.clickCallBack(originalRun, config.config);
|
|
153
|
-
} else {
|
|
154
|
-
originalRun();
|
|
155
|
-
}
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
// 判断是否启用了遮罩层点击动作
|
|
159
|
-
if (config.config.mask.clickEvent!.toClose || config.config.mask.clickEvent!.toHide) {
|
|
160
|
-
/**
|
|
161
|
-
* 判断点击的元素是否是动画层的元素
|
|
162
|
-
* @param element
|
|
163
|
-
* @returns
|
|
164
|
-
*/
|
|
165
|
-
function isAnimElement(element: HTMLElement) {
|
|
166
|
-
return Boolean(
|
|
167
|
-
element?.localName?.toLowerCase() === "div" &&
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
// 判断按下的元素是否是pops-anim
|
|
174
|
-
popsDOMUtils.on(config.animElement, ["touchstart", "mousedown"], (event) => {
|
|
175
|
-
const $click = event.composedPath()[0] as HTMLElement;
|
|
176
|
-
isMaskClick = isAnimElement($click);
|
|
177
|
-
});
|
|
178
|
-
// 如果有动画层,在动画层上监听点击事件
|
|
179
|
-
popsDOMUtils.on<MouseEvent | PointerEvent>(config.animElement, "click", (event) => {
|
|
180
|
-
const $click = event.composedPath()[0] as HTMLElement;
|
|
181
|
-
if (isAnimElement($click) && isMaskClick) {
|
|
182
|
-
return clickEvent(event);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
// 在遮罩层监听点击事件
|
|
186
|
-
// 如果有动画层,那么该点击事件触发不了
|
|
187
|
-
popsDOMUtils.on<MouseEvent | PointerEvent>(result.maskElement, "click", (event) => {
|
|
188
|
-
isMaskClick = true;
|
|
189
|
-
clickEvent(event);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
},
|
|
194
|
-
/**
|
|
195
|
-
* 处理获取元素
|
|
196
|
-
* @param animElement
|
|
197
|
-
* @param type
|
|
198
|
-
*/
|
|
199
|
-
handleQueryElement(animElement: HTMLDivElement, type: PopsSupportAnimConfigType) {
|
|
200
|
-
return {
|
|
201
|
-
/**
|
|
202
|
-
* 主元素
|
|
203
|
-
*/
|
|
204
|
-
$pops: animElement.querySelector<HTMLDivElement>(".pops[type-value")!,
|
|
205
|
-
/**
|
|
206
|
-
* 确认按钮
|
|
207
|
-
*/
|
|
208
|
-
$btnOk: animElement.querySelector<HTMLDivElement>(`.pops-${type}-btn-ok`)!,
|
|
209
|
-
/**
|
|
210
|
-
* 取消按钮
|
|
211
|
-
*/
|
|
212
|
-
$btnCancel: animElement.querySelector<HTMLDivElement>(`.pops-${type}-btn-cancel`)!,
|
|
213
|
-
/**
|
|
214
|
-
* 其它按钮
|
|
215
|
-
*/
|
|
216
|
-
$btnOther: animElement.querySelector<HTMLDivElement>(`.pops-${type}-btn-other`)!,
|
|
217
|
-
/**
|
|
218
|
-
* 标题元素
|
|
219
|
-
*/
|
|
220
|
-
$title: animElement.querySelector<HTMLDivElement>(`.pops-${type}-title`)!,
|
|
221
|
-
/**
|
|
222
|
-
* 输入框元素
|
|
223
|
-
*/
|
|
224
|
-
$input: animElement.querySelector<HTMLTextAreaElement>(`.pops-${type}-content textarea[pops]`)
|
|
225
|
-
? animElement.querySelector<HTMLTextAreaElement>(`.pops-${type}-content textarea[pops]`)!
|
|
226
|
-
: animElement.querySelector<HTMLInputElement>(`.pops-${type}-content input[pops]`)!,
|
|
227
|
-
/**
|
|
228
|
-
* 顶部按钮控制层元素
|
|
229
|
-
*/
|
|
230
|
-
$headerControls: animElement.querySelector<HTMLDivElement>(".pops-header-controls")!,
|
|
231
|
-
/**
|
|
232
|
-
* iframe元素
|
|
233
|
-
*/
|
|
234
|
-
$iframe: animElement.querySelector<HTMLIFrameElement>("iframe[pops]")!,
|
|
235
|
-
/**
|
|
236
|
-
* 加载中元素
|
|
237
|
-
*/
|
|
238
|
-
$loading: animElement.querySelector<HTMLDivElement>(".pops-loading")!,
|
|
239
|
-
/**
|
|
240
|
-
* 内容元素
|
|
241
|
-
*/
|
|
242
|
-
$content: animElement.querySelector<HTMLDivElement>(`.pops-${type}-content`)!,
|
|
243
|
-
/**
|
|
244
|
-
* panel的右侧容器元素
|
|
245
|
-
*/
|
|
246
|
-
$panelRightSectionWrapper: animElement.querySelector<HTMLDivElement>(`.pops-${type}-section-wrapper`)!,
|
|
247
|
-
/**
|
|
248
|
-
* panel侧边栏容器元素
|
|
249
|
-
*/
|
|
250
|
-
$panelLeftAside: animElement.querySelector<HTMLDivElement>(`.pops-${type}-content aside.pops-${type}-aside`)!,
|
|
251
|
-
/**
|
|
252
|
-
* panel主要区域容器元素
|
|
253
|
-
*/
|
|
254
|
-
$panelContentSectionContainer: animElement.querySelector<HTMLDivElement>(
|
|
255
|
-
`.pops-${type}-content section.pops-${type}-container`
|
|
256
|
-
)!,
|
|
257
|
-
/**
|
|
258
|
-
* panel底部区域
|
|
259
|
-
*/
|
|
260
|
-
$panelBottomWrapper: animElement.querySelector<HTMLElement>(`.pops-${type}-bottom-wrapper`)!,
|
|
261
|
-
/**
|
|
262
|
-
* panel底部区域容器
|
|
263
|
-
*/
|
|
264
|
-
$panelBottomContainer: animElement.querySelector<HTMLElement>(`.pops-${type}-bottom-container`)!,
|
|
265
|
-
/**
|
|
266
|
-
* panel底部区域左侧容器
|
|
267
|
-
*/
|
|
268
|
-
$panelBottomLeftContainer: animElement.querySelector<HTMLElement>(`.pops-${type}-bottom-left-container`)!,
|
|
269
|
-
/**
|
|
270
|
-
* panel底部区域右侧容器
|
|
271
|
-
*/
|
|
272
|
-
$panelBottomRightContainer: animElement.querySelector<HTMLElement>(`.pops-${type}-bottom-right-container`)!,
|
|
273
|
-
/**
|
|
274
|
-
* 内容加载中元素
|
|
275
|
-
*/
|
|
276
|
-
$contentLoading: animElement.querySelector<HTMLDivElement>(`.pops-${type}-content-global-loading`)!,
|
|
277
|
-
/**
|
|
278
|
-
* 顶部缩小按钮
|
|
279
|
-
*/
|
|
280
|
-
$headerBtnMin: animElement.querySelector<HTMLDivElement>(".pops-header-control[data-type='min']")!,
|
|
281
|
-
/**
|
|
282
|
-
* 顶部放大按钮
|
|
283
|
-
*/
|
|
284
|
-
$headerBtnMax: animElement.querySelector<HTMLDivElement>(".pops-header-control[data-type='max']")!,
|
|
285
|
-
/**
|
|
286
|
-
* 顶部恢复原样按钮
|
|
287
|
-
*/
|
|
288
|
-
$headerBtnMise: animElement.querySelector<HTMLDivElement>(".pops-header-control[data-type='mise']")!,
|
|
289
|
-
/**
|
|
290
|
-
* 顶部关闭按钮
|
|
291
|
-
*/
|
|
292
|
-
$headerBtnClose: animElement.querySelector<HTMLDivElement>(".pops-header-control[data-type='close']")!,
|
|
293
|
-
/**
|
|
294
|
-
* 文件夹列表元素
|
|
295
|
-
*/
|
|
296
|
-
$folderList: animElement.querySelector<HTMLDivElement>(".pops-folder-list")!,
|
|
297
|
-
/**
|
|
298
|
-
* 文件夹列表顶部元素
|
|
299
|
-
*/
|
|
300
|
-
$folderHeaderNav: animElement.querySelector<HTMLDivElement>(
|
|
301
|
-
".pops-folder-list .pops-folder-list-table__header-div"
|
|
302
|
-
)!,
|
|
303
|
-
/**
|
|
304
|
-
* 文件夹列表行元素
|
|
305
|
-
*/
|
|
306
|
-
$folderHeaderRow: animElement.querySelector<HTMLTableRowElement>(
|
|
307
|
-
".pops-folder-list .pops-folder-list-table__header-div .pops-folder-list-table__header-row"
|
|
308
|
-
)!,
|
|
309
|
-
/**
|
|
310
|
-
* 文件夹列表tbody元素
|
|
311
|
-
*/
|
|
312
|
-
$folderTbody: animElement.querySelector<HTMLTableElement>(
|
|
313
|
-
".pops-folder-list .pops-folder-list-table__body-div tbody"
|
|
314
|
-
)!,
|
|
315
|
-
/**
|
|
316
|
-
* 文件夹列表primary元素
|
|
317
|
-
*/
|
|
318
|
-
$folderHeaderBreadcrumbPrimary: animElement.querySelector<HTMLDivElement>(
|
|
319
|
-
".pops-folder-list .pops-folder-file-list-breadcrumb-primary"
|
|
320
|
-
)!,
|
|
321
|
-
/**
|
|
322
|
-
* 文件夹排序按钮-文件名
|
|
323
|
-
*/
|
|
324
|
-
$folderSortFileName: animElement.querySelector<HTMLDivElement>(
|
|
325
|
-
'.pops-folder-list-table__sort[data-sort="fileName"]'
|
|
326
|
-
)!,
|
|
327
|
-
/**
|
|
328
|
-
* 文件夹排序按钮-修改时间
|
|
329
|
-
*/
|
|
330
|
-
$folderSortLatestTime: animElement.querySelector<HTMLDivElement>(
|
|
331
|
-
'.pops-folder-list-table__sort[data-sort="latestTime"]'
|
|
332
|
-
)!,
|
|
333
|
-
/**
|
|
334
|
-
* 文件夹排序按钮-文件大小
|
|
335
|
-
*/
|
|
336
|
-
$folderSortFileSize: animElement.querySelector<HTMLDivElement>(
|
|
337
|
-
'.pops-folder-list-table__sort[data-sort="fileSize"]'
|
|
338
|
-
)!,
|
|
339
|
-
};
|
|
340
|
-
},
|
|
341
|
-
/**
|
|
342
|
-
* 获取事件配置
|
|
343
|
-
* @param guid
|
|
344
|
-
* @param $shadowContainer
|
|
345
|
-
* @param $shadowRoot
|
|
346
|
-
* @param type 当前弹窗类型
|
|
347
|
-
* @param $anim 动画层
|
|
348
|
-
* @param $pops 主元素
|
|
349
|
-
* @param $mask 遮罩层
|
|
350
|
-
* @param config 当前配置
|
|
351
|
-
*/
|
|
352
|
-
handleEventConfig(
|
|
353
|
-
config:
|
|
354
|
-
| PopsAlertConfig
|
|
355
|
-
| PopsDrawerConfig
|
|
356
|
-
| PopsPromptConfig
|
|
357
|
-
| PopsConfirmConfig
|
|
358
|
-
| PopsIframeConfig
|
|
359
|
-
| PopsLoadingConfig
|
|
360
|
-
| PopsPanelConfig
|
|
361
|
-
| PopsFolderConfig,
|
|
362
|
-
guid: string,
|
|
363
|
-
$shadowContainer: HTMLDivElement,
|
|
364
|
-
$shadowRoot: ShadowRoot | HTMLElement,
|
|
365
|
-
type: PopsInstStoreType,
|
|
366
|
-
$anim: HTMLDivElement,
|
|
367
|
-
$pops: HTMLDivElement,
|
|
368
|
-
$mask?: HTMLDivElement
|
|
369
|
-
): PopsEventConfig {
|
|
370
|
-
return {
|
|
371
|
-
$shadowContainer: $shadowContainer,
|
|
372
|
-
$shadowRoot: $shadowRoot,
|
|
373
|
-
$el: $anim,
|
|
374
|
-
$anim: $anim,
|
|
375
|
-
$pops: $pops,
|
|
376
|
-
$mask: $mask,
|
|
377
|
-
mode: type,
|
|
378
|
-
guid: guid,
|
|
379
|
-
close() {
|
|
380
|
-
return PopsInstanceUtils.close(config, type, PopsInstData[type], guid, $anim);
|
|
381
|
-
},
|
|
382
|
-
hide() {
|
|
383
|
-
return PopsInstanceUtils.hide(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
384
|
-
},
|
|
385
|
-
show($parent?: HTMLElement | Document | ShadowRoot) {
|
|
386
|
-
if ($parent) {
|
|
387
|
-
$parent.appendChild(PopsInstData[type][0].$shadowRoot);
|
|
388
|
-
}
|
|
389
|
-
return PopsInstanceUtils.show(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
390
|
-
},
|
|
391
|
-
};
|
|
392
|
-
},
|
|
393
|
-
/**
|
|
394
|
-
* 获取loading的事件配置
|
|
395
|
-
* @param guid
|
|
396
|
-
* @param type 当前弹窗类型
|
|
397
|
-
* @param $anim 动画层
|
|
398
|
-
* @param $pops 主元素
|
|
399
|
-
* @param $mask 遮罩层
|
|
400
|
-
* @param config 当前配置
|
|
401
|
-
*/
|
|
402
|
-
handleLoadingEventConfig(
|
|
403
|
-
config:
|
|
404
|
-
| PopsAlertConfig
|
|
405
|
-
| PopsDrawerConfig
|
|
406
|
-
| PopsPromptConfig
|
|
407
|
-
| PopsConfirmConfig
|
|
408
|
-
| PopsIframeConfig
|
|
409
|
-
| PopsLoadingConfig
|
|
410
|
-
| PopsPanelConfig
|
|
411
|
-
| PopsFolderConfig,
|
|
412
|
-
guid: string,
|
|
413
|
-
type: "loading",
|
|
414
|
-
$anim: HTMLDivElement,
|
|
415
|
-
$pops: HTMLDivElement,
|
|
416
|
-
$mask?: HTMLDivElement
|
|
417
|
-
): Omit<PopsEventConfig, "$shadowContainer" | "$shadowRoot"> {
|
|
418
|
-
return {
|
|
419
|
-
$el: $anim,
|
|
420
|
-
$anim: $anim,
|
|
421
|
-
$pops: $pops,
|
|
422
|
-
$mask: $mask,
|
|
423
|
-
mode: type,
|
|
424
|
-
guid: guid,
|
|
425
|
-
close() {
|
|
426
|
-
return PopsInstanceUtils.close(config, type, PopsInstData[type], guid, $anim);
|
|
427
|
-
},
|
|
428
|
-
hide() {
|
|
429
|
-
return PopsInstanceUtils.hide(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
430
|
-
},
|
|
431
|
-
show() {
|
|
432
|
-
return PopsInstanceUtils.show(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
433
|
-
},
|
|
434
|
-
};
|
|
435
|
-
},
|
|
436
|
-
/**
|
|
437
|
-
* 处理返回的配置,针对popsHandler.handleEventConfig
|
|
438
|
-
* @param config 配置
|
|
439
|
-
*/
|
|
440
|
-
handleResultConfig<T>(config: T): Omit<T, "type" | "function"> {
|
|
441
|
-
const resultDetails = Object.assign({}, config);
|
|
442
|
-
popsUtils.delete(resultDetails, "type");
|
|
443
|
-
popsUtils.delete(resultDetails, "function");
|
|
444
|
-
return resultDetails;
|
|
445
|
-
},
|
|
446
|
-
/**
|
|
447
|
-
* 处理点击事件
|
|
448
|
-
* @param type 当前按钮类型
|
|
449
|
-
* @param $btn 按钮元素
|
|
450
|
-
* @param eventConfig 事件配置,由popsHandler.handleEventConfig创建的
|
|
451
|
-
* @param callback 点击回调
|
|
452
|
-
*/
|
|
453
|
-
handleClickEvent(
|
|
454
|
-
type: PopsHandlerEventConfig["type"],
|
|
455
|
-
$btn: HTMLElement,
|
|
456
|
-
eventConfig: PopsEventConfig,
|
|
457
|
-
callback?: (details: PopsHandlerEventConfig, event: PointerEvent | MouseEvent) => void
|
|
458
|
-
) {
|
|
459
|
-
if (typeof callback !== "function") return;
|
|
460
|
-
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
461
|
-
$btn,
|
|
462
|
-
"click",
|
|
463
|
-
(event) => {
|
|
464
|
-
const extraParam = {
|
|
465
|
-
type: type,
|
|
466
|
-
};
|
|
467
|
-
callback(Object.assign(eventConfig, extraParam), event);
|
|
468
|
-
},
|
|
469
|
-
{
|
|
470
|
-
capture: true,
|
|
471
|
-
}
|
|
472
|
-
);
|
|
473
|
-
},
|
|
474
|
-
/**
|
|
475
|
-
* 全局监听键盘事件
|
|
476
|
-
* @param keyName 键名|键值
|
|
477
|
-
* @param otherKeyList 组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
|
|
478
|
-
* @param callback 回调函数
|
|
479
|
-
*/
|
|
480
|
-
handleKeyboardEvent(keyName: string | number, otherKeyList: string[] = [], callback: (event: KeyboardEvent) => void) {
|
|
481
|
-
const keyboardEvent = function (event: KeyboardEvent) {
|
|
482
|
-
const _keyName = event.code || event.key;
|
|
483
|
-
const _keyValue = event.charCode || event.keyCode || event.which;
|
|
484
|
-
if (otherKeyList.includes("ctrl") && !event.ctrlKey) {
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
if (otherKeyList.includes("alt") && !event.altKey) {
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
if (otherKeyList.includes("meta") && !event.metaKey) {
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
if (otherKeyList.includes("shift") && !event.shiftKey) {
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
if (typeof keyName === "string" && keyName === _keyName) {
|
|
497
|
-
callback && callback(event);
|
|
498
|
-
} else if (typeof keyName === "number" && keyName === _keyValue) {
|
|
499
|
-
callback && callback(event);
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
popsDOMUtils.on(PopsCore.globalThis, "keydown", keyboardEvent, {
|
|
503
|
-
capture: true,
|
|
504
|
-
});
|
|
505
|
-
return {
|
|
506
|
-
removeKeyboardEvent() {
|
|
507
|
-
popsDOMUtils.off(globalThis, "keydown", keyboardEvent, {
|
|
508
|
-
capture: true,
|
|
509
|
-
});
|
|
510
|
-
},
|
|
511
|
-
};
|
|
512
|
-
},
|
|
513
|
-
/**
|
|
514
|
-
* 处理prompt的点击事件
|
|
515
|
-
* @param type 触发事件类型
|
|
516
|
-
* @param inputElement 输入框
|
|
517
|
-
* @param $btn 按钮元素
|
|
518
|
-
* @param eventConfig 事件配置,由popsHandler.handleEventConfig创建的
|
|
519
|
-
* @param callback 点击回调
|
|
520
|
-
*/
|
|
521
|
-
handlePromptClickEvent(
|
|
522
|
-
type: PopsHandlerEventConfig["type"],
|
|
523
|
-
inputElement: HTMLInputElement | HTMLTextAreaElement,
|
|
524
|
-
$btn: HTMLElement,
|
|
525
|
-
eventConfig: PopsEventConfig,
|
|
526
|
-
callback: (
|
|
527
|
-
details: PopsEventConfig & {
|
|
528
|
-
type: any;
|
|
529
|
-
text: string;
|
|
530
|
-
},
|
|
531
|
-
event: MouseEvent | PointerEvent
|
|
532
|
-
) => void
|
|
533
|
-
) {
|
|
534
|
-
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
535
|
-
$btn,
|
|
536
|
-
"click",
|
|
537
|
-
(event) => {
|
|
538
|
-
// 额外参数
|
|
539
|
-
const extraParam = {
|
|
540
|
-
type: type,
|
|
541
|
-
text: inputElement.value,
|
|
542
|
-
};
|
|
543
|
-
callback(Object.assign(eventConfig, extraParam), event);
|
|
544
|
-
},
|
|
545
|
-
{
|
|
546
|
-
capture: true,
|
|
547
|
-
}
|
|
548
|
-
);
|
|
549
|
-
},
|
|
550
|
-
/**
|
|
551
|
-
* 把配置的z-index配置转为数字
|
|
552
|
-
* @param zIndex
|
|
553
|
-
*/
|
|
554
|
-
handleZIndex(zIndex: number | (() => number)): number {
|
|
555
|
-
if (typeof zIndex === "function") {
|
|
556
|
-
return zIndex();
|
|
557
|
-
} else {
|
|
558
|
-
return zIndex;
|
|
559
|
-
}
|
|
560
|
-
},
|
|
561
|
-
/**
|
|
562
|
-
* 处理config.only
|
|
563
|
-
* @param type 当前弹窗类型
|
|
564
|
-
* @param config 配置
|
|
565
|
-
*/
|
|
566
|
-
handleOnly<T extends Required<PopsSupportOnlyConfig[keyof PopsSupportOnlyConfig]>>(type: PopsType, config: T): T {
|
|
567
|
-
if (config.only) {
|
|
568
|
-
// .loading
|
|
569
|
-
// .rightClickMenu
|
|
570
|
-
// .tooltip
|
|
571
|
-
// 单独处理
|
|
572
|
-
if (type === "loading" || type === "tooltip" || type === "rightClickMenu") {
|
|
573
|
-
const inst = PopsInstData[type as keyof typeof PopsInstData];
|
|
574
|
-
if (inst) {
|
|
575
|
-
PopsInstanceUtils.removeInstance([inst], "", true);
|
|
576
|
-
}
|
|
577
|
-
} else {
|
|
578
|
-
PopsInstanceUtils.removeInstance(
|
|
579
|
-
[
|
|
580
|
-
PopsInstData.alert,
|
|
581
|
-
PopsInstData.confirm,
|
|
582
|
-
PopsInstData.drawer,
|
|
583
|
-
PopsInstData.folder,
|
|
584
|
-
PopsInstData.iframe,
|
|
585
|
-
PopsInstData.panel,
|
|
586
|
-
PopsInstData.prompt,
|
|
587
|
-
],
|
|
588
|
-
"",
|
|
589
|
-
true
|
|
590
|
-
);
|
|
591
|
-
}
|
|
592
|
-
} else {
|
|
593
|
-
// 对配置进行处理
|
|
594
|
-
// 选择配置的z-index和已有的pops实例的最大z-index值
|
|
595
|
-
const originZIndex = config.zIndex;
|
|
596
|
-
config.zIndex = () => {
|
|
597
|
-
const { zIndex: maxZIndex } = PopsInstanceUtils.getPopsMaxZIndex(PopsHandler.handleZIndex(originZIndex) + 100);
|
|
598
|
-
return maxZIndex;
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
return config;
|
|
602
|
-
},
|
|
603
|
-
/**
|
|
604
|
-
* 处理把已创建的元素保存到内部环境中
|
|
605
|
-
* @param type 当前弹窗类型
|
|
606
|
-
* @param value
|
|
607
|
-
*/
|
|
608
|
-
handlePush(type: PopsInstStoreType, value: PopsInstGeneralConfig) {
|
|
609
|
-
PopsInstData[type].push(value);
|
|
610
|
-
},
|
|
611
|
-
};
|
|
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 { PopsCore } from "../PopsCore";
|
|
10
|
+
import { PopsAnimation } from "../PopsAnimation";
|
|
11
|
+
import { PopsInstData } from "../PopsInst";
|
|
12
|
+
import type { PopsGeneralConfig } from "../types/components";
|
|
13
|
+
import type { PopsEventConfig, PopsHandlerEventConfig } from "../types/event";
|
|
14
|
+
import type { PopsInstGeneralConfig } from "../types/inst";
|
|
15
|
+
import type { PopsInstStoreType, PopsType, PopsSupportAnimConfigType, PopsSupportOnlyConfig } from "../types/main";
|
|
16
|
+
import { popsDOMUtils } from "../utils/PopsDOMUtils";
|
|
17
|
+
import { PopsInstanceUtils } from "../utils/PopsInstanceUtils";
|
|
18
|
+
import { popsUtils } from "../utils/PopsUtils";
|
|
19
|
+
|
|
20
|
+
export const PopsHandler = {
|
|
21
|
+
/**
|
|
22
|
+
* 创建shadow
|
|
23
|
+
*/
|
|
24
|
+
handlerShadow(config: Pick<PopsGeneralConfig, "useShadowRoot">) {
|
|
25
|
+
const $shadowContainer = popsDOMUtils.createElement("div", {
|
|
26
|
+
className: "pops-shadow-container",
|
|
27
|
+
});
|
|
28
|
+
if (config.useShadowRoot) {
|
|
29
|
+
const $shadowRoot = $shadowContainer.attachShadow({ mode: "open" });
|
|
30
|
+
return {
|
|
31
|
+
$shadowContainer,
|
|
32
|
+
$shadowRoot,
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
return {
|
|
36
|
+
$shadowContainer,
|
|
37
|
+
$shadowRoot: $shadowContainer,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* 处理初始化
|
|
43
|
+
* @param $styleParent style元素的父元素
|
|
44
|
+
* @param css 添加进ShadowRoot的CSS
|
|
45
|
+
*/
|
|
46
|
+
handleInit(
|
|
47
|
+
$styleParent?: ShadowRoot | HTMLElement,
|
|
48
|
+
css?:
|
|
49
|
+
| string
|
|
50
|
+
| string[]
|
|
51
|
+
| {
|
|
52
|
+
name?: string;
|
|
53
|
+
css: string;
|
|
54
|
+
}[]
|
|
55
|
+
) {
|
|
56
|
+
PopsAnimation.init();
|
|
57
|
+
if (!arguments.length) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if ($styleParent == null) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (css == null) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof css === "string") {
|
|
68
|
+
if (css.trim() === "") {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
css = [
|
|
72
|
+
{
|
|
73
|
+
css: css,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
} else {
|
|
77
|
+
css = css.map((item) => {
|
|
78
|
+
if (typeof item === "string") {
|
|
79
|
+
return {
|
|
80
|
+
css: item,
|
|
81
|
+
};
|
|
82
|
+
} else {
|
|
83
|
+
return item;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
for (const cssItem of css) {
|
|
88
|
+
const $css = popsDOMUtils.createElement(
|
|
89
|
+
"style",
|
|
90
|
+
{},
|
|
91
|
+
{
|
|
92
|
+
"data-type": "PopsHandler.handleInit",
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
$css.textContent = cssItem.css;
|
|
96
|
+
if (typeof cssItem.name === "string") {
|
|
97
|
+
$css.setAttribute("data-name", cssItem.name);
|
|
98
|
+
}
|
|
99
|
+
$styleParent.appendChild($css);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* 处理遮罩层
|
|
104
|
+
*
|
|
105
|
+
* + 设置遮罩层的点击事件
|
|
106
|
+
* @param config 传递的配置
|
|
107
|
+
*/
|
|
108
|
+
handleMask(
|
|
109
|
+
config = {} as {
|
|
110
|
+
type: "alert" | "confirm" | "prompt" | "loading" | "iframe" | "drawer" | "folder" | "panel";
|
|
111
|
+
guid: string;
|
|
112
|
+
config:
|
|
113
|
+
| Required<PopsAlertConfig>
|
|
114
|
+
| Required<PopsLoadingConfig>
|
|
115
|
+
| Required<PopsIframeConfig>
|
|
116
|
+
| Required<PopsDrawerConfig>
|
|
117
|
+
| Required<PopsPanelConfig>
|
|
118
|
+
| Required<PopsFolderConfig>;
|
|
119
|
+
animElement: HTMLElement;
|
|
120
|
+
maskHTML: string;
|
|
121
|
+
}
|
|
122
|
+
) {
|
|
123
|
+
const result = {
|
|
124
|
+
maskElement: popsDOMUtils.parseTextToDOM<HTMLDivElement>(config.maskHTML),
|
|
125
|
+
};
|
|
126
|
+
let isMaskClick = false;
|
|
127
|
+
/**
|
|
128
|
+
* 点击其它区域的事件
|
|
129
|
+
* @param event
|
|
130
|
+
*/
|
|
131
|
+
function clickEvent(event: MouseEvent | PointerEvent) {
|
|
132
|
+
popsDOMUtils.preventEvent(event);
|
|
133
|
+
// 获取该类型实例存储列表
|
|
134
|
+
const targetInst = PopsInstData[config.type];
|
|
135
|
+
function originalRun() {
|
|
136
|
+
if (config.config.mask!.clickEvent!.toClose) {
|
|
137
|
+
// 关闭
|
|
138
|
+
return PopsInstanceUtils.close(config.config, config.type, targetInst, config.guid, config.animElement);
|
|
139
|
+
} else if (config.config.mask!.clickEvent!.toHide) {
|
|
140
|
+
// 隐藏
|
|
141
|
+
return PopsInstanceUtils.hide(
|
|
142
|
+
config.config,
|
|
143
|
+
config.type,
|
|
144
|
+
targetInst,
|
|
145
|
+
config.guid,
|
|
146
|
+
config.animElement,
|
|
147
|
+
result.maskElement
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (typeof config.config.mask.clickCallBack === "function") {
|
|
152
|
+
config.config.mask.clickCallBack(originalRun, config.config);
|
|
153
|
+
} else {
|
|
154
|
+
originalRun();
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
// 判断是否启用了遮罩层点击动作
|
|
159
|
+
if (config.config.mask.clickEvent!.toClose || config.config.mask.clickEvent!.toHide) {
|
|
160
|
+
/**
|
|
161
|
+
* 判断点击的元素是否是动画层的元素
|
|
162
|
+
* @param element
|
|
163
|
+
* @returns
|
|
164
|
+
*/
|
|
165
|
+
function isAnimElement(element: HTMLElement) {
|
|
166
|
+
return Boolean(
|
|
167
|
+
element?.localName?.toLowerCase() === "div" &&
|
|
168
|
+
element.className &&
|
|
169
|
+
element.className === "pops-anim" &&
|
|
170
|
+
element.hasAttribute("anim")
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
// 判断按下的元素是否是pops-anim
|
|
174
|
+
popsDOMUtils.on(config.animElement, ["touchstart", "mousedown"], (event) => {
|
|
175
|
+
const $click = event.composedPath()[0] as HTMLElement;
|
|
176
|
+
isMaskClick = isAnimElement($click);
|
|
177
|
+
});
|
|
178
|
+
// 如果有动画层,在动画层上监听点击事件
|
|
179
|
+
popsDOMUtils.on<MouseEvent | PointerEvent>(config.animElement, "click", (event) => {
|
|
180
|
+
const $click = event.composedPath()[0] as HTMLElement;
|
|
181
|
+
if (isAnimElement($click) && isMaskClick) {
|
|
182
|
+
return clickEvent(event);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
// 在遮罩层监听点击事件
|
|
186
|
+
// 如果有动画层,那么该点击事件触发不了
|
|
187
|
+
popsDOMUtils.on<MouseEvent | PointerEvent>(result.maskElement, "click", (event) => {
|
|
188
|
+
isMaskClick = true;
|
|
189
|
+
clickEvent(event);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
},
|
|
194
|
+
/**
|
|
195
|
+
* 处理获取元素
|
|
196
|
+
* @param animElement
|
|
197
|
+
* @param type
|
|
198
|
+
*/
|
|
199
|
+
handleQueryElement(animElement: HTMLDivElement, type: PopsSupportAnimConfigType) {
|
|
200
|
+
return {
|
|
201
|
+
/**
|
|
202
|
+
* 主元素
|
|
203
|
+
*/
|
|
204
|
+
$pops: animElement.querySelector<HTMLDivElement>(".pops[type-value")!,
|
|
205
|
+
/**
|
|
206
|
+
* 确认按钮
|
|
207
|
+
*/
|
|
208
|
+
$btnOk: animElement.querySelector<HTMLDivElement>(`.pops-${type}-btn-ok`)!,
|
|
209
|
+
/**
|
|
210
|
+
* 取消按钮
|
|
211
|
+
*/
|
|
212
|
+
$btnCancel: animElement.querySelector<HTMLDivElement>(`.pops-${type}-btn-cancel`)!,
|
|
213
|
+
/**
|
|
214
|
+
* 其它按钮
|
|
215
|
+
*/
|
|
216
|
+
$btnOther: animElement.querySelector<HTMLDivElement>(`.pops-${type}-btn-other`)!,
|
|
217
|
+
/**
|
|
218
|
+
* 标题元素
|
|
219
|
+
*/
|
|
220
|
+
$title: animElement.querySelector<HTMLDivElement>(`.pops-${type}-title`)!,
|
|
221
|
+
/**
|
|
222
|
+
* 输入框元素
|
|
223
|
+
*/
|
|
224
|
+
$input: animElement.querySelector<HTMLTextAreaElement>(`.pops-${type}-content textarea[pops]`)
|
|
225
|
+
? animElement.querySelector<HTMLTextAreaElement>(`.pops-${type}-content textarea[pops]`)!
|
|
226
|
+
: animElement.querySelector<HTMLInputElement>(`.pops-${type}-content input[pops]`)!,
|
|
227
|
+
/**
|
|
228
|
+
* 顶部按钮控制层元素
|
|
229
|
+
*/
|
|
230
|
+
$headerControls: animElement.querySelector<HTMLDivElement>(".pops-header-controls")!,
|
|
231
|
+
/**
|
|
232
|
+
* iframe元素
|
|
233
|
+
*/
|
|
234
|
+
$iframe: animElement.querySelector<HTMLIFrameElement>("iframe[pops]")!,
|
|
235
|
+
/**
|
|
236
|
+
* 加载中元素
|
|
237
|
+
*/
|
|
238
|
+
$loading: animElement.querySelector<HTMLDivElement>(".pops-loading")!,
|
|
239
|
+
/**
|
|
240
|
+
* 内容元素
|
|
241
|
+
*/
|
|
242
|
+
$content: animElement.querySelector<HTMLDivElement>(`.pops-${type}-content`)!,
|
|
243
|
+
/**
|
|
244
|
+
* panel的右侧容器元素
|
|
245
|
+
*/
|
|
246
|
+
$panelRightSectionWrapper: animElement.querySelector<HTMLDivElement>(`.pops-${type}-section-wrapper`)!,
|
|
247
|
+
/**
|
|
248
|
+
* panel侧边栏容器元素
|
|
249
|
+
*/
|
|
250
|
+
$panelLeftAside: animElement.querySelector<HTMLDivElement>(`.pops-${type}-content aside.pops-${type}-aside`)!,
|
|
251
|
+
/**
|
|
252
|
+
* panel主要区域容器元素
|
|
253
|
+
*/
|
|
254
|
+
$panelContentSectionContainer: animElement.querySelector<HTMLDivElement>(
|
|
255
|
+
`.pops-${type}-content section.pops-${type}-container`
|
|
256
|
+
)!,
|
|
257
|
+
/**
|
|
258
|
+
* panel底部区域
|
|
259
|
+
*/
|
|
260
|
+
$panelBottomWrapper: animElement.querySelector<HTMLElement>(`.pops-${type}-bottom-wrapper`)!,
|
|
261
|
+
/**
|
|
262
|
+
* panel底部区域容器
|
|
263
|
+
*/
|
|
264
|
+
$panelBottomContainer: animElement.querySelector<HTMLElement>(`.pops-${type}-bottom-container`)!,
|
|
265
|
+
/**
|
|
266
|
+
* panel底部区域左侧容器
|
|
267
|
+
*/
|
|
268
|
+
$panelBottomLeftContainer: animElement.querySelector<HTMLElement>(`.pops-${type}-bottom-left-container`)!,
|
|
269
|
+
/**
|
|
270
|
+
* panel底部区域右侧容器
|
|
271
|
+
*/
|
|
272
|
+
$panelBottomRightContainer: animElement.querySelector<HTMLElement>(`.pops-${type}-bottom-right-container`)!,
|
|
273
|
+
/**
|
|
274
|
+
* 内容加载中元素
|
|
275
|
+
*/
|
|
276
|
+
$contentLoading: animElement.querySelector<HTMLDivElement>(`.pops-${type}-content-global-loading`)!,
|
|
277
|
+
/**
|
|
278
|
+
* 顶部缩小按钮
|
|
279
|
+
*/
|
|
280
|
+
$headerBtnMin: animElement.querySelector<HTMLDivElement>(".pops-header-control[data-type='min']")!,
|
|
281
|
+
/**
|
|
282
|
+
* 顶部放大按钮
|
|
283
|
+
*/
|
|
284
|
+
$headerBtnMax: animElement.querySelector<HTMLDivElement>(".pops-header-control[data-type='max']")!,
|
|
285
|
+
/**
|
|
286
|
+
* 顶部恢复原样按钮
|
|
287
|
+
*/
|
|
288
|
+
$headerBtnMise: animElement.querySelector<HTMLDivElement>(".pops-header-control[data-type='mise']")!,
|
|
289
|
+
/**
|
|
290
|
+
* 顶部关闭按钮
|
|
291
|
+
*/
|
|
292
|
+
$headerBtnClose: animElement.querySelector<HTMLDivElement>(".pops-header-control[data-type='close']")!,
|
|
293
|
+
/**
|
|
294
|
+
* 文件夹列表元素
|
|
295
|
+
*/
|
|
296
|
+
$folderList: animElement.querySelector<HTMLDivElement>(".pops-folder-list")!,
|
|
297
|
+
/**
|
|
298
|
+
* 文件夹列表顶部元素
|
|
299
|
+
*/
|
|
300
|
+
$folderHeaderNav: animElement.querySelector<HTMLDivElement>(
|
|
301
|
+
".pops-folder-list .pops-folder-list-table__header-div"
|
|
302
|
+
)!,
|
|
303
|
+
/**
|
|
304
|
+
* 文件夹列表行元素
|
|
305
|
+
*/
|
|
306
|
+
$folderHeaderRow: animElement.querySelector<HTMLTableRowElement>(
|
|
307
|
+
".pops-folder-list .pops-folder-list-table__header-div .pops-folder-list-table__header-row"
|
|
308
|
+
)!,
|
|
309
|
+
/**
|
|
310
|
+
* 文件夹列表tbody元素
|
|
311
|
+
*/
|
|
312
|
+
$folderTbody: animElement.querySelector<HTMLTableElement>(
|
|
313
|
+
".pops-folder-list .pops-folder-list-table__body-div tbody"
|
|
314
|
+
)!,
|
|
315
|
+
/**
|
|
316
|
+
* 文件夹列表primary元素
|
|
317
|
+
*/
|
|
318
|
+
$folderHeaderBreadcrumbPrimary: animElement.querySelector<HTMLDivElement>(
|
|
319
|
+
".pops-folder-list .pops-folder-file-list-breadcrumb-primary"
|
|
320
|
+
)!,
|
|
321
|
+
/**
|
|
322
|
+
* 文件夹排序按钮-文件名
|
|
323
|
+
*/
|
|
324
|
+
$folderSortFileName: animElement.querySelector<HTMLDivElement>(
|
|
325
|
+
'.pops-folder-list-table__sort[data-sort="fileName"]'
|
|
326
|
+
)!,
|
|
327
|
+
/**
|
|
328
|
+
* 文件夹排序按钮-修改时间
|
|
329
|
+
*/
|
|
330
|
+
$folderSortLatestTime: animElement.querySelector<HTMLDivElement>(
|
|
331
|
+
'.pops-folder-list-table__sort[data-sort="latestTime"]'
|
|
332
|
+
)!,
|
|
333
|
+
/**
|
|
334
|
+
* 文件夹排序按钮-文件大小
|
|
335
|
+
*/
|
|
336
|
+
$folderSortFileSize: animElement.querySelector<HTMLDivElement>(
|
|
337
|
+
'.pops-folder-list-table__sort[data-sort="fileSize"]'
|
|
338
|
+
)!,
|
|
339
|
+
};
|
|
340
|
+
},
|
|
341
|
+
/**
|
|
342
|
+
* 获取事件配置
|
|
343
|
+
* @param guid
|
|
344
|
+
* @param $shadowContainer
|
|
345
|
+
* @param $shadowRoot
|
|
346
|
+
* @param type 当前弹窗类型
|
|
347
|
+
* @param $anim 动画层
|
|
348
|
+
* @param $pops 主元素
|
|
349
|
+
* @param $mask 遮罩层
|
|
350
|
+
* @param config 当前配置
|
|
351
|
+
*/
|
|
352
|
+
handleEventConfig(
|
|
353
|
+
config:
|
|
354
|
+
| PopsAlertConfig
|
|
355
|
+
| PopsDrawerConfig
|
|
356
|
+
| PopsPromptConfig
|
|
357
|
+
| PopsConfirmConfig
|
|
358
|
+
| PopsIframeConfig
|
|
359
|
+
| PopsLoadingConfig
|
|
360
|
+
| PopsPanelConfig
|
|
361
|
+
| PopsFolderConfig,
|
|
362
|
+
guid: string,
|
|
363
|
+
$shadowContainer: HTMLDivElement,
|
|
364
|
+
$shadowRoot: ShadowRoot | HTMLElement,
|
|
365
|
+
type: PopsInstStoreType,
|
|
366
|
+
$anim: HTMLDivElement,
|
|
367
|
+
$pops: HTMLDivElement,
|
|
368
|
+
$mask?: HTMLDivElement
|
|
369
|
+
): PopsEventConfig {
|
|
370
|
+
return {
|
|
371
|
+
$shadowContainer: $shadowContainer,
|
|
372
|
+
$shadowRoot: $shadowRoot,
|
|
373
|
+
$el: $anim,
|
|
374
|
+
$anim: $anim,
|
|
375
|
+
$pops: $pops,
|
|
376
|
+
$mask: $mask,
|
|
377
|
+
mode: type,
|
|
378
|
+
guid: guid,
|
|
379
|
+
close() {
|
|
380
|
+
return PopsInstanceUtils.close(config, type, PopsInstData[type], guid, $anim);
|
|
381
|
+
},
|
|
382
|
+
hide() {
|
|
383
|
+
return PopsInstanceUtils.hide(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
384
|
+
},
|
|
385
|
+
show($parent?: HTMLElement | Document | ShadowRoot) {
|
|
386
|
+
if ($parent) {
|
|
387
|
+
$parent.appendChild(PopsInstData[type][0].$shadowRoot);
|
|
388
|
+
}
|
|
389
|
+
return PopsInstanceUtils.show(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
},
|
|
393
|
+
/**
|
|
394
|
+
* 获取loading的事件配置
|
|
395
|
+
* @param guid
|
|
396
|
+
* @param type 当前弹窗类型
|
|
397
|
+
* @param $anim 动画层
|
|
398
|
+
* @param $pops 主元素
|
|
399
|
+
* @param $mask 遮罩层
|
|
400
|
+
* @param config 当前配置
|
|
401
|
+
*/
|
|
402
|
+
handleLoadingEventConfig(
|
|
403
|
+
config:
|
|
404
|
+
| PopsAlertConfig
|
|
405
|
+
| PopsDrawerConfig
|
|
406
|
+
| PopsPromptConfig
|
|
407
|
+
| PopsConfirmConfig
|
|
408
|
+
| PopsIframeConfig
|
|
409
|
+
| PopsLoadingConfig
|
|
410
|
+
| PopsPanelConfig
|
|
411
|
+
| PopsFolderConfig,
|
|
412
|
+
guid: string,
|
|
413
|
+
type: "loading",
|
|
414
|
+
$anim: HTMLDivElement,
|
|
415
|
+
$pops: HTMLDivElement,
|
|
416
|
+
$mask?: HTMLDivElement
|
|
417
|
+
): Omit<PopsEventConfig, "$shadowContainer" | "$shadowRoot"> {
|
|
418
|
+
return {
|
|
419
|
+
$el: $anim,
|
|
420
|
+
$anim: $anim,
|
|
421
|
+
$pops: $pops,
|
|
422
|
+
$mask: $mask,
|
|
423
|
+
mode: type,
|
|
424
|
+
guid: guid,
|
|
425
|
+
close() {
|
|
426
|
+
return PopsInstanceUtils.close(config, type, PopsInstData[type], guid, $anim);
|
|
427
|
+
},
|
|
428
|
+
hide() {
|
|
429
|
+
return PopsInstanceUtils.hide(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
430
|
+
},
|
|
431
|
+
show() {
|
|
432
|
+
return PopsInstanceUtils.show(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
},
|
|
436
|
+
/**
|
|
437
|
+
* 处理返回的配置,针对popsHandler.handleEventConfig
|
|
438
|
+
* @param config 配置
|
|
439
|
+
*/
|
|
440
|
+
handleResultConfig<T>(config: T): Omit<T, "type" | "function"> {
|
|
441
|
+
const resultDetails = Object.assign({}, config);
|
|
442
|
+
popsUtils.delete(resultDetails, "type");
|
|
443
|
+
popsUtils.delete(resultDetails, "function");
|
|
444
|
+
return resultDetails;
|
|
445
|
+
},
|
|
446
|
+
/**
|
|
447
|
+
* 处理点击事件
|
|
448
|
+
* @param type 当前按钮类型
|
|
449
|
+
* @param $btn 按钮元素
|
|
450
|
+
* @param eventConfig 事件配置,由popsHandler.handleEventConfig创建的
|
|
451
|
+
* @param callback 点击回调
|
|
452
|
+
*/
|
|
453
|
+
handleClickEvent(
|
|
454
|
+
type: PopsHandlerEventConfig["type"],
|
|
455
|
+
$btn: HTMLElement,
|
|
456
|
+
eventConfig: PopsEventConfig,
|
|
457
|
+
callback?: (details: PopsHandlerEventConfig, event: PointerEvent | MouseEvent) => void
|
|
458
|
+
) {
|
|
459
|
+
if (typeof callback !== "function") return;
|
|
460
|
+
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
461
|
+
$btn,
|
|
462
|
+
"click",
|
|
463
|
+
(event) => {
|
|
464
|
+
const extraParam = {
|
|
465
|
+
type: type,
|
|
466
|
+
};
|
|
467
|
+
callback(Object.assign(eventConfig, extraParam), event);
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
capture: true,
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
},
|
|
474
|
+
/**
|
|
475
|
+
* 全局监听键盘事件
|
|
476
|
+
* @param keyName 键名|键值
|
|
477
|
+
* @param otherKeyList 组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
|
|
478
|
+
* @param callback 回调函数
|
|
479
|
+
*/
|
|
480
|
+
handleKeyboardEvent(keyName: string | number, otherKeyList: string[] = [], callback: (event: KeyboardEvent) => void) {
|
|
481
|
+
const keyboardEvent = function (event: KeyboardEvent) {
|
|
482
|
+
const _keyName = event.code || event.key;
|
|
483
|
+
const _keyValue = event.charCode || event.keyCode || event.which;
|
|
484
|
+
if (otherKeyList.includes("ctrl") && !event.ctrlKey) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (otherKeyList.includes("alt") && !event.altKey) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (otherKeyList.includes("meta") && !event.metaKey) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
if (otherKeyList.includes("shift") && !event.shiftKey) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (typeof keyName === "string" && keyName === _keyName) {
|
|
497
|
+
callback && callback(event);
|
|
498
|
+
} else if (typeof keyName === "number" && keyName === _keyValue) {
|
|
499
|
+
callback && callback(event);
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
popsDOMUtils.on(PopsCore.globalThis, "keydown", keyboardEvent, {
|
|
503
|
+
capture: true,
|
|
504
|
+
});
|
|
505
|
+
return {
|
|
506
|
+
removeKeyboardEvent() {
|
|
507
|
+
popsDOMUtils.off(globalThis, "keydown", keyboardEvent, {
|
|
508
|
+
capture: true,
|
|
509
|
+
});
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
},
|
|
513
|
+
/**
|
|
514
|
+
* 处理prompt的点击事件
|
|
515
|
+
* @param type 触发事件类型
|
|
516
|
+
* @param inputElement 输入框
|
|
517
|
+
* @param $btn 按钮元素
|
|
518
|
+
* @param eventConfig 事件配置,由popsHandler.handleEventConfig创建的
|
|
519
|
+
* @param callback 点击回调
|
|
520
|
+
*/
|
|
521
|
+
handlePromptClickEvent(
|
|
522
|
+
type: PopsHandlerEventConfig["type"],
|
|
523
|
+
inputElement: HTMLInputElement | HTMLTextAreaElement,
|
|
524
|
+
$btn: HTMLElement,
|
|
525
|
+
eventConfig: PopsEventConfig,
|
|
526
|
+
callback: (
|
|
527
|
+
details: PopsEventConfig & {
|
|
528
|
+
type: any;
|
|
529
|
+
text: string;
|
|
530
|
+
},
|
|
531
|
+
event: MouseEvent | PointerEvent
|
|
532
|
+
) => void
|
|
533
|
+
) {
|
|
534
|
+
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
535
|
+
$btn,
|
|
536
|
+
"click",
|
|
537
|
+
(event) => {
|
|
538
|
+
// 额外参数
|
|
539
|
+
const extraParam = {
|
|
540
|
+
type: type,
|
|
541
|
+
text: inputElement.value,
|
|
542
|
+
};
|
|
543
|
+
callback(Object.assign(eventConfig, extraParam), event);
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
capture: true,
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
},
|
|
550
|
+
/**
|
|
551
|
+
* 把配置的z-index配置转为数字
|
|
552
|
+
* @param zIndex
|
|
553
|
+
*/
|
|
554
|
+
handleZIndex(zIndex: number | (() => number)): number {
|
|
555
|
+
if (typeof zIndex === "function") {
|
|
556
|
+
return zIndex();
|
|
557
|
+
} else {
|
|
558
|
+
return zIndex;
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
/**
|
|
562
|
+
* 处理config.only
|
|
563
|
+
* @param type 当前弹窗类型
|
|
564
|
+
* @param config 配置
|
|
565
|
+
*/
|
|
566
|
+
handleOnly<T extends Required<PopsSupportOnlyConfig[keyof PopsSupportOnlyConfig]>>(type: PopsType, config: T): T {
|
|
567
|
+
if (config.only) {
|
|
568
|
+
// .loading
|
|
569
|
+
// .rightClickMenu
|
|
570
|
+
// .tooltip
|
|
571
|
+
// 单独处理
|
|
572
|
+
if (type === "loading" || type === "tooltip" || type === "rightClickMenu") {
|
|
573
|
+
const inst = PopsInstData[type as keyof typeof PopsInstData];
|
|
574
|
+
if (inst) {
|
|
575
|
+
PopsInstanceUtils.removeInstance([inst], "", true);
|
|
576
|
+
}
|
|
577
|
+
} else {
|
|
578
|
+
PopsInstanceUtils.removeInstance(
|
|
579
|
+
[
|
|
580
|
+
PopsInstData.alert,
|
|
581
|
+
PopsInstData.confirm,
|
|
582
|
+
PopsInstData.drawer,
|
|
583
|
+
PopsInstData.folder,
|
|
584
|
+
PopsInstData.iframe,
|
|
585
|
+
PopsInstData.panel,
|
|
586
|
+
PopsInstData.prompt,
|
|
587
|
+
],
|
|
588
|
+
"",
|
|
589
|
+
true
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
} else {
|
|
593
|
+
// 对配置进行处理
|
|
594
|
+
// 选择配置的z-index和已有的pops实例的最大z-index值
|
|
595
|
+
const originZIndex = config.zIndex;
|
|
596
|
+
config.zIndex = () => {
|
|
597
|
+
const { zIndex: maxZIndex } = PopsInstanceUtils.getPopsMaxZIndex(PopsHandler.handleZIndex(originZIndex) + 100);
|
|
598
|
+
return maxZIndex;
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
return config;
|
|
602
|
+
},
|
|
603
|
+
/**
|
|
604
|
+
* 处理把已创建的元素保存到内部环境中
|
|
605
|
+
* @param type 当前弹窗类型
|
|
606
|
+
* @param value
|
|
607
|
+
*/
|
|
608
|
+
handlePush(type: PopsInstStoreType, value: PopsInstGeneralConfig) {
|
|
609
|
+
PopsInstData[type].push(value);
|
|
610
|
+
},
|
|
611
|
+
};
|