@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,331 +1,331 @@
|
|
|
1
|
-
import { PopsCore } from "../../PopsCore";
|
|
2
|
-
import { GlobalConfig } from "../../config/GlobalConfig";
|
|
3
|
-
import { PopsElementHandler } from "../../handler/PopsElementHandler";
|
|
4
|
-
import { PopsHandler } from "../../handler/PopsHandler";
|
|
5
|
-
import { PopsCSS } from "../../PopsCSS";
|
|
6
|
-
import { PopsInstData } from "../../PopsInst";
|
|
7
|
-
import { popsDOMUtils } from "../../utils/PopsDOMUtils";
|
|
8
|
-
import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
|
|
9
|
-
import { popsUtils } from "../../utils/PopsUtils";
|
|
10
|
-
import { PopsIframeDefaultConfig } from "./defaultConfig";
|
|
11
|
-
import type { PopsIframeClickEventConfig, PopsIframeConfig } from "./types";
|
|
12
|
-
import type { PopsType } from "../../types/main";
|
|
13
|
-
|
|
14
|
-
export const PopsIframe = {
|
|
15
|
-
init(__config__: PopsIframeConfig) {
|
|
16
|
-
const guid = popsUtils.getRandomGUID();
|
|
17
|
-
// 设置当前类型
|
|
18
|
-
const popsType: PopsType = "iframe";
|
|
19
|
-
|
|
20
|
-
let config = PopsIframeDefaultConfig();
|
|
21
|
-
config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
|
|
22
|
-
config = popsUtils.assign(config, __config__);
|
|
23
|
-
if (config.url == null) {
|
|
24
|
-
throw new TypeError("config.url must not be null.");
|
|
25
|
-
}
|
|
26
|
-
config = PopsHandler.handleOnly(popsType, config);
|
|
27
|
-
|
|
28
|
-
const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
|
|
29
|
-
PopsHandler.handleInit($shadowRoot, [
|
|
30
|
-
{
|
|
31
|
-
name: "index",
|
|
32
|
-
css: PopsCSS.index,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: "ninePalaceGridPosition",
|
|
36
|
-
css: PopsCSS.ninePalaceGridPosition,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: "scrollbar",
|
|
40
|
-
css: PopsCSS.scrollbar,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "anim",
|
|
44
|
-
css: PopsCSS.anim,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: "common",
|
|
48
|
-
css: PopsCSS.common,
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: "iframeCSS",
|
|
52
|
-
css: PopsCSS.iframeCSS,
|
|
53
|
-
},
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
const maskExtraStyle = config.animation != null && <string>config.animation != "" ? "position:absolute;" : "";
|
|
57
|
-
|
|
58
|
-
// 先把z-index提取出来
|
|
59
|
-
const zIndex = PopsHandler.handleZIndex(config.zIndex);
|
|
60
|
-
const maskHTML = PopsElementHandler.createMask(guid, zIndex, maskExtraStyle);
|
|
61
|
-
|
|
62
|
-
const headerBtnHTML = PopsElementHandler.createHeader(popsType, config);
|
|
63
|
-
const iframeLoadingHTML = /*html*/ '<div class="pops-loading"></div>';
|
|
64
|
-
const titleText = config.title!.text!.trim() !== "" ? config.title.text : config.url;
|
|
65
|
-
const { headerStyle, headerPStyle } = PopsElementHandler.createHeaderStyle(popsType, config);
|
|
66
|
-
const animHTML = PopsElementHandler.createAnim(
|
|
67
|
-
guid,
|
|
68
|
-
popsType,
|
|
69
|
-
config,
|
|
70
|
-
/*html*/ `
|
|
71
|
-
<div class="pops-title pops-${popsType}-title" style="text-align: ${
|
|
72
|
-
config.title.position
|
|
73
|
-
};${headerStyle}">${
|
|
74
|
-
config.title.html
|
|
75
|
-
? titleText
|
|
76
|
-
: `<p pops class="pops-${popsType}-title-text" style="${headerPStyle}">${titleText}</p>`
|
|
77
|
-
}${headerBtnHTML}</div>
|
|
78
|
-
<div class="pops-content pops-${popsType}-content">
|
|
79
|
-
<div class="pops-${popsType}-content-global-loading"></div>
|
|
80
|
-
<iframe src="${config.url}" pops ${
|
|
81
|
-
config.sandbox ? "sandbox='allow-forms allow-same-origin allow-scripts'" : ""
|
|
82
|
-
}>
|
|
83
|
-
</iframe>
|
|
84
|
-
</div>${config.loading.enable ? iframeLoadingHTML : ""}`,
|
|
85
|
-
"",
|
|
86
|
-
zIndex
|
|
87
|
-
);
|
|
88
|
-
/**
|
|
89
|
-
* 弹窗的主元素,包括动画层
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
const $anim = PopsElementHandler.parseElement<HTMLDivElement>(animHTML);
|
|
93
|
-
const {
|
|
94
|
-
$pops: $pops,
|
|
95
|
-
$headerBtnClose: headerCloseBtnElement,
|
|
96
|
-
$headerControls: headerControlsElement,
|
|
97
|
-
$title: $title,
|
|
98
|
-
$iframe: $iframe,
|
|
99
|
-
$loading: loadingElement,
|
|
100
|
-
$contentLoading: $contentLoading,
|
|
101
|
-
$headerBtnMin: headerMinBtnElement,
|
|
102
|
-
$headerBtnMax: headerMaxBtnElement,
|
|
103
|
-
$headerBtnMise: headerMiseBtnElement,
|
|
104
|
-
} = PopsHandler.handleQueryElement($anim, popsType);
|
|
105
|
-
let $iframeContainer = PopsCore.document.querySelector<HTMLDivElement>(".pops-iframe-container");
|
|
106
|
-
if (!$iframeContainer) {
|
|
107
|
-
$iframeContainer = popsDOMUtils.createElement("div", {
|
|
108
|
-
className: "pops-iframe-container",
|
|
109
|
-
});
|
|
110
|
-
$iframeContainer.style.cssText =
|
|
111
|
-
"display: flex;position: fixed;bottom: 0px;flex-flow: wrap-reverse;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;";
|
|
112
|
-
popsDOMUtils.appendBody($iframeContainer);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* 遮罩层元素
|
|
116
|
-
*/
|
|
117
|
-
let $mask: HTMLDivElement | undefined = void 0;
|
|
118
|
-
/**
|
|
119
|
-
* 已创建的元素列表
|
|
120
|
-
*/
|
|
121
|
-
const $elList: HTMLElement[] = [$anim];
|
|
122
|
-
|
|
123
|
-
if (config.mask.enable) {
|
|
124
|
-
const handleMask = PopsHandler.handleMask({
|
|
125
|
-
type: popsType,
|
|
126
|
-
guid: guid,
|
|
127
|
-
|
|
128
|
-
config: config,
|
|
129
|
-
animElement: $anim,
|
|
130
|
-
maskHTML: maskHTML,
|
|
131
|
-
});
|
|
132
|
-
$mask = handleMask.maskElement;
|
|
133
|
-
$elList.push($mask);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const evtConfig = PopsHandler.handleEventConfig(
|
|
137
|
-
config,
|
|
138
|
-
guid,
|
|
139
|
-
$shadowContainer,
|
|
140
|
-
$shadowRoot,
|
|
141
|
-
popsType,
|
|
142
|
-
$anim,
|
|
143
|
-
$pops,
|
|
144
|
-
$mask
|
|
145
|
-
) as PopsIframeClickEventConfig;
|
|
146
|
-
// 赋值额外的$iframe参数
|
|
147
|
-
evtConfig.$iframe = $iframe!;
|
|
148
|
-
|
|
149
|
-
const result = PopsHandler.handleResultConfig(evtConfig);
|
|
150
|
-
|
|
151
|
-
popsDOMUtils.on($anim, popsDOMUtils.getAnimationEndNameList(), function () {
|
|
152
|
-
// 动画加载完毕
|
|
153
|
-
$anim.style.width = "0%";
|
|
154
|
-
$anim.style.height = "0%";
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
popsDOMUtils.on($iframe, "load", () => {
|
|
158
|
-
// iframe加载中...
|
|
159
|
-
loadingElement?.remove();
|
|
160
|
-
$contentLoading!.style.animation = "iframeLoadingChange_85 0.3s forwards";
|
|
161
|
-
popsDOMUtils.on($contentLoading, popsDOMUtils.getAnimationEndNameList(), () => {
|
|
162
|
-
// 动画加载完毕就移除
|
|
163
|
-
$contentLoading!.remove();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
if (config.title!.text!.trim() === "" && $iframe!.contentDocument) {
|
|
167
|
-
// 同域名下的才可以获取网页标题
|
|
168
|
-
$title!.querySelector<HTMLElement>("p")!.innerText = $iframe!.contentDocument.title;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
config.loadEndCallBack(evtConfig);
|
|
172
|
-
});
|
|
173
|
-
// 创建到页面中
|
|
174
|
-
|
|
175
|
-
popsDOMUtils.append($shadowRoot, $elList);
|
|
176
|
-
if (typeof config.beforeAppendToPageCallBack === "function") {
|
|
177
|
-
config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
$iframeContainer.appendChild($shadowContainer);
|
|
181
|
-
if ($mask != null) {
|
|
182
|
-
$anim.after($mask);
|
|
183
|
-
}
|
|
184
|
-
// 拖拽
|
|
185
|
-
if (config.drag) {
|
|
186
|
-
PopsInstanceUtils.drag($pops!, {
|
|
187
|
-
dragElement: $title!,
|
|
188
|
-
limit: config.dragLimit,
|
|
189
|
-
extraDistance: config.dragExtraDistance,
|
|
190
|
-
moveCallBack: config.dragMoveCallBack,
|
|
191
|
-
endCallBack: config.dragEndCallBack,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
const TYPE_MODULE = "type-module";
|
|
195
|
-
// 最小化按钮点击事件
|
|
196
|
-
let origin_left = "";
|
|
197
|
-
let origin_top = "";
|
|
198
|
-
let origin_is_max = false;
|
|
199
|
-
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
200
|
-
headerMinBtnElement,
|
|
201
|
-
"click",
|
|
202
|
-
(event) => {
|
|
203
|
-
event.preventDefault();
|
|
204
|
-
event.stopPropagation();
|
|
205
|
-
origin_left = $pops.style.left;
|
|
206
|
-
origin_top = $pops.style.top;
|
|
207
|
-
$pops.classList.add("pops-iframe-unset-top");
|
|
208
|
-
$pops.classList.add("pops-iframe-unset-left");
|
|
209
|
-
$pops.classList.add("pops-iframe-unset-transform");
|
|
210
|
-
$pops.style.transitionDuration = "";
|
|
211
|
-
|
|
212
|
-
$pops.setAttribute(TYPE_MODULE, "min");
|
|
213
|
-
headerControlsElement.setAttribute("type", "min");
|
|
214
|
-
// 隐藏放大图标
|
|
215
|
-
headerMaxBtnElement.style.setProperty("display", "none");
|
|
216
|
-
// 显示复位图标
|
|
217
|
-
headerMiseBtnElement.style.setProperty("display", "");
|
|
218
|
-
if (typeof config?.btn?.min?.callback === "function") {
|
|
219
|
-
config.btn.min.callback(evtConfig, event);
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
capture: true,
|
|
224
|
-
}
|
|
225
|
-
);
|
|
226
|
-
// 最大化按钮点击事件
|
|
227
|
-
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
228
|
-
headerMaxBtnElement,
|
|
229
|
-
"click",
|
|
230
|
-
(event) => {
|
|
231
|
-
event.preventDefault();
|
|
232
|
-
event.stopPropagation();
|
|
233
|
-
if ($pops.getAttribute(TYPE_MODULE) !== "min") {
|
|
234
|
-
origin_left = $pops.style.left;
|
|
235
|
-
origin_top = $pops.style.top;
|
|
236
|
-
}
|
|
237
|
-
origin_is_max = true;
|
|
238
|
-
$pops.style.transitionDuration = "";
|
|
239
|
-
$pops.style.transform = "";
|
|
240
|
-
$pops.removeAttribute(TYPE_MODULE);
|
|
241
|
-
$pops.classList.add("pops-iframe-unset-transition");
|
|
242
|
-
$pops.classList.add("pops-iframe-unset-left");
|
|
243
|
-
$pops.classList.add("pops-iframe-unset-top");
|
|
244
|
-
$pops.classList.add("pops-iframe-unset-transform");
|
|
245
|
-
$pops.classList.remove("pops-iframe-unset-transition");
|
|
246
|
-
$pops.setAttribute(TYPE_MODULE, "max");
|
|
247
|
-
headerControlsElement.setAttribute("type", "max");
|
|
248
|
-
// 隐藏放大图标
|
|
249
|
-
headerMaxBtnElement.style.setProperty("display", "none");
|
|
250
|
-
// 显示复位图标
|
|
251
|
-
headerMiseBtnElement.style.setProperty("display", "");
|
|
252
|
-
if (typeof config?.btn?.max?.callback === "function") {
|
|
253
|
-
config.btn.max.callback(evtConfig, event);
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
capture: true,
|
|
258
|
-
}
|
|
259
|
-
);
|
|
260
|
-
// 先隐藏窗口化按钮
|
|
261
|
-
headerMiseBtnElement?.style?.setProperty("display", "none");
|
|
262
|
-
// 复位按钮点击事件
|
|
263
|
-
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
264
|
-
headerMiseBtnElement,
|
|
265
|
-
"click",
|
|
266
|
-
(event) => {
|
|
267
|
-
event.preventDefault();
|
|
268
|
-
event.stopPropagation();
|
|
269
|
-
if (origin_is_max && $pops.getAttribute(TYPE_MODULE) === "min") {
|
|
270
|
-
$pops.classList.add("pops-iframe-unset-transition");
|
|
271
|
-
$pops.classList.add("pops-iframe-unset-left");
|
|
272
|
-
$pops.classList.add("pops-iframe-unset-top");
|
|
273
|
-
$pops.classList.add("pops-iframe-unset-transform");
|
|
274
|
-
$pops.classList.remove("pops-iframe-unset-transition");
|
|
275
|
-
$pops.setAttribute(TYPE_MODULE, "max");
|
|
276
|
-
headerControlsElement.setAttribute("type", "max");
|
|
277
|
-
} else {
|
|
278
|
-
origin_is_max = false;
|
|
279
|
-
$pops.style.left = origin_left;
|
|
280
|
-
$pops.style.top = origin_top;
|
|
281
|
-
$pops.style.transitionDuration = "";
|
|
282
|
-
$pops.style.transform = "";
|
|
283
|
-
headerControlsElement.removeAttribute("type");
|
|
284
|
-
$pops.removeAttribute(TYPE_MODULE);
|
|
285
|
-
$pops.classList.remove("pops-iframe-unset-top");
|
|
286
|
-
$pops.classList.remove("pops-iframe-unset-left");
|
|
287
|
-
$pops.classList.remove("pops-iframe-unset-transform");
|
|
288
|
-
|
|
289
|
-
// 显示放大图标
|
|
290
|
-
headerMaxBtnElement.style.setProperty("display", "");
|
|
291
|
-
// 隐藏复位图标
|
|
292
|
-
headerMiseBtnElement.style.setProperty("display", "none");
|
|
293
|
-
}
|
|
294
|
-
if (typeof config?.btn?.mise?.callback === "function") {
|
|
295
|
-
config.btn.mise.callback(evtConfig, event);
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
capture: true,
|
|
300
|
-
}
|
|
301
|
-
);
|
|
302
|
-
// 关闭按钮点击事件
|
|
303
|
-
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
304
|
-
headerCloseBtnElement,
|
|
305
|
-
"click",
|
|
306
|
-
async (event) => {
|
|
307
|
-
event.preventDefault();
|
|
308
|
-
event.stopPropagation();
|
|
309
|
-
await PopsInstanceUtils.removeInstance([PopsInstData.iframe], guid, false);
|
|
310
|
-
if (typeof config?.btn?.close?.callback === "function") {
|
|
311
|
-
config.btn.close.callback(evtConfig, event);
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
capture: true,
|
|
316
|
-
}
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
PopsHandler.handlePush(popsType, {
|
|
320
|
-
guid: guid,
|
|
321
|
-
$anim: $anim,
|
|
322
|
-
$pops: $pops!,
|
|
323
|
-
$mask: $mask!,
|
|
324
|
-
$shadowContainer: $shadowContainer,
|
|
325
|
-
$shadowRoot: $shadowRoot,
|
|
326
|
-
config: config,
|
|
327
|
-
destory: result.close,
|
|
328
|
-
});
|
|
329
|
-
return result;
|
|
330
|
-
},
|
|
331
|
-
};
|
|
1
|
+
import { PopsCore } from "../../PopsCore";
|
|
2
|
+
import { GlobalConfig } from "../../config/GlobalConfig";
|
|
3
|
+
import { PopsElementHandler } from "../../handler/PopsElementHandler";
|
|
4
|
+
import { PopsHandler } from "../../handler/PopsHandler";
|
|
5
|
+
import { PopsCSS } from "../../PopsCSS";
|
|
6
|
+
import { PopsInstData } from "../../PopsInst";
|
|
7
|
+
import { popsDOMUtils } from "../../utils/PopsDOMUtils";
|
|
8
|
+
import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
|
|
9
|
+
import { popsUtils } from "../../utils/PopsUtils";
|
|
10
|
+
import { PopsIframeDefaultConfig } from "./defaultConfig";
|
|
11
|
+
import type { PopsIframeClickEventConfig, PopsIframeConfig } from "./types";
|
|
12
|
+
import type { PopsType } from "../../types/main";
|
|
13
|
+
|
|
14
|
+
export const PopsIframe = {
|
|
15
|
+
init(__config__: PopsIframeConfig) {
|
|
16
|
+
const guid = popsUtils.getRandomGUID();
|
|
17
|
+
// 设置当前类型
|
|
18
|
+
const popsType: PopsType = "iframe";
|
|
19
|
+
|
|
20
|
+
let config = PopsIframeDefaultConfig();
|
|
21
|
+
config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
|
|
22
|
+
config = popsUtils.assign(config, __config__);
|
|
23
|
+
if (config.url == null) {
|
|
24
|
+
throw new TypeError("config.url must not be null.");
|
|
25
|
+
}
|
|
26
|
+
config = PopsHandler.handleOnly(popsType, config);
|
|
27
|
+
|
|
28
|
+
const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
|
|
29
|
+
PopsHandler.handleInit($shadowRoot, [
|
|
30
|
+
{
|
|
31
|
+
name: "index",
|
|
32
|
+
css: PopsCSS.index,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "ninePalaceGridPosition",
|
|
36
|
+
css: PopsCSS.ninePalaceGridPosition,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "scrollbar",
|
|
40
|
+
css: PopsCSS.scrollbar,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "anim",
|
|
44
|
+
css: PopsCSS.anim,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "common",
|
|
48
|
+
css: PopsCSS.common,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "iframeCSS",
|
|
52
|
+
css: PopsCSS.iframeCSS,
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const maskExtraStyle = config.animation != null && <string>config.animation != "" ? "position:absolute;" : "";
|
|
57
|
+
|
|
58
|
+
// 先把z-index提取出来
|
|
59
|
+
const zIndex = PopsHandler.handleZIndex(config.zIndex);
|
|
60
|
+
const maskHTML = PopsElementHandler.createMask(guid, zIndex, maskExtraStyle);
|
|
61
|
+
|
|
62
|
+
const headerBtnHTML = PopsElementHandler.createHeader(popsType, config);
|
|
63
|
+
const iframeLoadingHTML = /*html*/ '<div class="pops-loading"></div>';
|
|
64
|
+
const titleText = config.title!.text!.trim() !== "" ? config.title.text : config.url;
|
|
65
|
+
const { headerStyle, headerPStyle } = PopsElementHandler.createHeaderStyle(popsType, config);
|
|
66
|
+
const animHTML = PopsElementHandler.createAnim(
|
|
67
|
+
guid,
|
|
68
|
+
popsType,
|
|
69
|
+
config,
|
|
70
|
+
/*html*/ `
|
|
71
|
+
<div class="pops-title pops-${popsType}-title" style="text-align: ${
|
|
72
|
+
config.title.position
|
|
73
|
+
};${headerStyle}">${
|
|
74
|
+
config.title.html
|
|
75
|
+
? titleText
|
|
76
|
+
: `<p pops class="pops-${popsType}-title-text" style="${headerPStyle}">${titleText}</p>`
|
|
77
|
+
}${headerBtnHTML}</div>
|
|
78
|
+
<div class="pops-content pops-${popsType}-content">
|
|
79
|
+
<div class="pops-${popsType}-content-global-loading"></div>
|
|
80
|
+
<iframe src="${config.url}" pops ${
|
|
81
|
+
config.sandbox ? "sandbox='allow-forms allow-same-origin allow-scripts'" : ""
|
|
82
|
+
}>
|
|
83
|
+
</iframe>
|
|
84
|
+
</div>${config.loading.enable ? iframeLoadingHTML : ""}`,
|
|
85
|
+
"",
|
|
86
|
+
zIndex
|
|
87
|
+
);
|
|
88
|
+
/**
|
|
89
|
+
* 弹窗的主元素,包括动画层
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
const $anim = PopsElementHandler.parseElement<HTMLDivElement>(animHTML);
|
|
93
|
+
const {
|
|
94
|
+
$pops: $pops,
|
|
95
|
+
$headerBtnClose: headerCloseBtnElement,
|
|
96
|
+
$headerControls: headerControlsElement,
|
|
97
|
+
$title: $title,
|
|
98
|
+
$iframe: $iframe,
|
|
99
|
+
$loading: loadingElement,
|
|
100
|
+
$contentLoading: $contentLoading,
|
|
101
|
+
$headerBtnMin: headerMinBtnElement,
|
|
102
|
+
$headerBtnMax: headerMaxBtnElement,
|
|
103
|
+
$headerBtnMise: headerMiseBtnElement,
|
|
104
|
+
} = PopsHandler.handleQueryElement($anim, popsType);
|
|
105
|
+
let $iframeContainer = PopsCore.document.querySelector<HTMLDivElement>(".pops-iframe-container");
|
|
106
|
+
if (!$iframeContainer) {
|
|
107
|
+
$iframeContainer = popsDOMUtils.createElement("div", {
|
|
108
|
+
className: "pops-iframe-container",
|
|
109
|
+
});
|
|
110
|
+
$iframeContainer.style.cssText =
|
|
111
|
+
"display: flex;position: fixed;bottom: 0px;flex-flow: wrap-reverse;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;";
|
|
112
|
+
popsDOMUtils.appendBody($iframeContainer);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 遮罩层元素
|
|
116
|
+
*/
|
|
117
|
+
let $mask: HTMLDivElement | undefined = void 0;
|
|
118
|
+
/**
|
|
119
|
+
* 已创建的元素列表
|
|
120
|
+
*/
|
|
121
|
+
const $elList: HTMLElement[] = [$anim];
|
|
122
|
+
|
|
123
|
+
if (config.mask.enable) {
|
|
124
|
+
const handleMask = PopsHandler.handleMask({
|
|
125
|
+
type: popsType,
|
|
126
|
+
guid: guid,
|
|
127
|
+
|
|
128
|
+
config: config,
|
|
129
|
+
animElement: $anim,
|
|
130
|
+
maskHTML: maskHTML,
|
|
131
|
+
});
|
|
132
|
+
$mask = handleMask.maskElement;
|
|
133
|
+
$elList.push($mask);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const evtConfig = PopsHandler.handleEventConfig(
|
|
137
|
+
config,
|
|
138
|
+
guid,
|
|
139
|
+
$shadowContainer,
|
|
140
|
+
$shadowRoot,
|
|
141
|
+
popsType,
|
|
142
|
+
$anim,
|
|
143
|
+
$pops,
|
|
144
|
+
$mask
|
|
145
|
+
) as PopsIframeClickEventConfig;
|
|
146
|
+
// 赋值额外的$iframe参数
|
|
147
|
+
evtConfig.$iframe = $iframe!;
|
|
148
|
+
|
|
149
|
+
const result = PopsHandler.handleResultConfig(evtConfig);
|
|
150
|
+
|
|
151
|
+
popsDOMUtils.on($anim, popsDOMUtils.getAnimationEndNameList(), function () {
|
|
152
|
+
// 动画加载完毕
|
|
153
|
+
$anim.style.width = "0%";
|
|
154
|
+
$anim.style.height = "0%";
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
popsDOMUtils.on($iframe, "load", () => {
|
|
158
|
+
// iframe加载中...
|
|
159
|
+
loadingElement?.remove();
|
|
160
|
+
$contentLoading!.style.animation = "iframeLoadingChange_85 0.3s forwards";
|
|
161
|
+
popsDOMUtils.on($contentLoading, popsDOMUtils.getAnimationEndNameList(), () => {
|
|
162
|
+
// 动画加载完毕就移除
|
|
163
|
+
$contentLoading!.remove();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
if (config.title!.text!.trim() === "" && $iframe!.contentDocument) {
|
|
167
|
+
// 同域名下的才可以获取网页标题
|
|
168
|
+
$title!.querySelector<HTMLElement>("p")!.innerText = $iframe!.contentDocument.title;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
config.loadEndCallBack(evtConfig);
|
|
172
|
+
});
|
|
173
|
+
// 创建到页面中
|
|
174
|
+
|
|
175
|
+
popsDOMUtils.append($shadowRoot, $elList);
|
|
176
|
+
if (typeof config.beforeAppendToPageCallBack === "function") {
|
|
177
|
+
config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
$iframeContainer.appendChild($shadowContainer);
|
|
181
|
+
if ($mask != null) {
|
|
182
|
+
$anim.after($mask);
|
|
183
|
+
}
|
|
184
|
+
// 拖拽
|
|
185
|
+
if (config.drag) {
|
|
186
|
+
PopsInstanceUtils.drag($pops!, {
|
|
187
|
+
dragElement: $title!,
|
|
188
|
+
limit: config.dragLimit,
|
|
189
|
+
extraDistance: config.dragExtraDistance,
|
|
190
|
+
moveCallBack: config.dragMoveCallBack,
|
|
191
|
+
endCallBack: config.dragEndCallBack,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const TYPE_MODULE = "type-module";
|
|
195
|
+
// 最小化按钮点击事件
|
|
196
|
+
let origin_left = "";
|
|
197
|
+
let origin_top = "";
|
|
198
|
+
let origin_is_max = false;
|
|
199
|
+
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
200
|
+
headerMinBtnElement,
|
|
201
|
+
"click",
|
|
202
|
+
(event) => {
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
event.stopPropagation();
|
|
205
|
+
origin_left = $pops.style.left;
|
|
206
|
+
origin_top = $pops.style.top;
|
|
207
|
+
$pops.classList.add("pops-iframe-unset-top");
|
|
208
|
+
$pops.classList.add("pops-iframe-unset-left");
|
|
209
|
+
$pops.classList.add("pops-iframe-unset-transform");
|
|
210
|
+
$pops.style.transitionDuration = "";
|
|
211
|
+
|
|
212
|
+
$pops.setAttribute(TYPE_MODULE, "min");
|
|
213
|
+
headerControlsElement.setAttribute("type", "min");
|
|
214
|
+
// 隐藏放大图标
|
|
215
|
+
headerMaxBtnElement.style.setProperty("display", "none");
|
|
216
|
+
// 显示复位图标
|
|
217
|
+
headerMiseBtnElement.style.setProperty("display", "");
|
|
218
|
+
if (typeof config?.btn?.min?.callback === "function") {
|
|
219
|
+
config.btn.min.callback(evtConfig, event);
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
capture: true,
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
// 最大化按钮点击事件
|
|
227
|
+
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
228
|
+
headerMaxBtnElement,
|
|
229
|
+
"click",
|
|
230
|
+
(event) => {
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
event.stopPropagation();
|
|
233
|
+
if ($pops.getAttribute(TYPE_MODULE) !== "min") {
|
|
234
|
+
origin_left = $pops.style.left;
|
|
235
|
+
origin_top = $pops.style.top;
|
|
236
|
+
}
|
|
237
|
+
origin_is_max = true;
|
|
238
|
+
$pops.style.transitionDuration = "";
|
|
239
|
+
$pops.style.transform = "";
|
|
240
|
+
$pops.removeAttribute(TYPE_MODULE);
|
|
241
|
+
$pops.classList.add("pops-iframe-unset-transition");
|
|
242
|
+
$pops.classList.add("pops-iframe-unset-left");
|
|
243
|
+
$pops.classList.add("pops-iframe-unset-top");
|
|
244
|
+
$pops.classList.add("pops-iframe-unset-transform");
|
|
245
|
+
$pops.classList.remove("pops-iframe-unset-transition");
|
|
246
|
+
$pops.setAttribute(TYPE_MODULE, "max");
|
|
247
|
+
headerControlsElement.setAttribute("type", "max");
|
|
248
|
+
// 隐藏放大图标
|
|
249
|
+
headerMaxBtnElement.style.setProperty("display", "none");
|
|
250
|
+
// 显示复位图标
|
|
251
|
+
headerMiseBtnElement.style.setProperty("display", "");
|
|
252
|
+
if (typeof config?.btn?.max?.callback === "function") {
|
|
253
|
+
config.btn.max.callback(evtConfig, event);
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
capture: true,
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
// 先隐藏窗口化按钮
|
|
261
|
+
headerMiseBtnElement?.style?.setProperty("display", "none");
|
|
262
|
+
// 复位按钮点击事件
|
|
263
|
+
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
264
|
+
headerMiseBtnElement,
|
|
265
|
+
"click",
|
|
266
|
+
(event) => {
|
|
267
|
+
event.preventDefault();
|
|
268
|
+
event.stopPropagation();
|
|
269
|
+
if (origin_is_max && $pops.getAttribute(TYPE_MODULE) === "min") {
|
|
270
|
+
$pops.classList.add("pops-iframe-unset-transition");
|
|
271
|
+
$pops.classList.add("pops-iframe-unset-left");
|
|
272
|
+
$pops.classList.add("pops-iframe-unset-top");
|
|
273
|
+
$pops.classList.add("pops-iframe-unset-transform");
|
|
274
|
+
$pops.classList.remove("pops-iframe-unset-transition");
|
|
275
|
+
$pops.setAttribute(TYPE_MODULE, "max");
|
|
276
|
+
headerControlsElement.setAttribute("type", "max");
|
|
277
|
+
} else {
|
|
278
|
+
origin_is_max = false;
|
|
279
|
+
$pops.style.left = origin_left;
|
|
280
|
+
$pops.style.top = origin_top;
|
|
281
|
+
$pops.style.transitionDuration = "";
|
|
282
|
+
$pops.style.transform = "";
|
|
283
|
+
headerControlsElement.removeAttribute("type");
|
|
284
|
+
$pops.removeAttribute(TYPE_MODULE);
|
|
285
|
+
$pops.classList.remove("pops-iframe-unset-top");
|
|
286
|
+
$pops.classList.remove("pops-iframe-unset-left");
|
|
287
|
+
$pops.classList.remove("pops-iframe-unset-transform");
|
|
288
|
+
|
|
289
|
+
// 显示放大图标
|
|
290
|
+
headerMaxBtnElement.style.setProperty("display", "");
|
|
291
|
+
// 隐藏复位图标
|
|
292
|
+
headerMiseBtnElement.style.setProperty("display", "none");
|
|
293
|
+
}
|
|
294
|
+
if (typeof config?.btn?.mise?.callback === "function") {
|
|
295
|
+
config.btn.mise.callback(evtConfig, event);
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
capture: true,
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
// 关闭按钮点击事件
|
|
303
|
+
popsDOMUtils.on<MouseEvent | PointerEvent>(
|
|
304
|
+
headerCloseBtnElement,
|
|
305
|
+
"click",
|
|
306
|
+
async (event) => {
|
|
307
|
+
event.preventDefault();
|
|
308
|
+
event.stopPropagation();
|
|
309
|
+
await PopsInstanceUtils.removeInstance([PopsInstData.iframe], guid, false);
|
|
310
|
+
if (typeof config?.btn?.close?.callback === "function") {
|
|
311
|
+
config.btn.close.callback(evtConfig, event);
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
capture: true,
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
PopsHandler.handlePush(popsType, {
|
|
320
|
+
guid: guid,
|
|
321
|
+
$anim: $anim,
|
|
322
|
+
$pops: $pops!,
|
|
323
|
+
$mask: $mask!,
|
|
324
|
+
$shadowContainer: $shadowContainer,
|
|
325
|
+
$shadowRoot: $shadowRoot,
|
|
326
|
+
config: config,
|
|
327
|
+
destory: result.close,
|
|
328
|
+
});
|
|
329
|
+
return result;
|
|
330
|
+
},
|
|
331
|
+
};
|