@whitesev/pops 3.3.5 → 4.0.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 +13118 -12932
- 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 +761 -575
- 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 +761 -575
- 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 +13119 -12933
- 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 +13122 -12936
- 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 +13121 -12935
- 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/Pops.d.ts +66 -52
- package/dist/types/src/PopsAnimation.d.ts +33 -0
- package/dist/types/src/PopsIcon.d.ts +1 -1
- package/dist/types/src/components/alert/index.d.ts +3 -1
- package/dist/types/src/components/confirm/index.d.ts +3 -1
- package/dist/types/src/components/drawer/index.d.ts +3 -1
- package/dist/types/src/components/folder/index.d.ts +3 -1
- package/dist/types/src/components/iframe/index.d.ts +6 -1
- package/dist/types/src/components/iframe/types/index.d.ts +4 -2
- package/dist/types/src/components/loading/index.d.ts +3 -1
- package/dist/types/src/components/panel/handlerComponents.d.ts +4 -1
- package/dist/types/src/components/panel/index.d.ts +2 -16
- package/dist/types/src/components/panel/types/index.d.ts +7 -2
- package/dist/types/src/components/prompt/index.d.ts +3 -1
- package/dist/types/src/components/searchSuggestion/index.d.ts +4 -1
- package/dist/types/src/components/tooltip/index.d.ts +5 -1
- package/dist/types/src/event/EventEmiter.d.ts +33 -0
- package/dist/types/src/handler/PopsHandler.d.ts +16 -11
- package/dist/types/src/handler/PopsInstHandler.d.ts +67 -0
- package/dist/types/src/types/EventEmitter.d.ts +18 -0
- package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +4 -0
- package/dist/types/src/types/button.d.ts +2 -1
- package/dist/types/src/types/event.d.ts +6 -2
- package/dist/types/src/types/inst.d.ts +4 -4
- package/dist/types/src/utils/PopsDOMUtils.d.ts +0 -16
- package/dist/types/src/utils/PopsInstanceUtils.d.ts +0 -88
- package/dist/types/src/utils/PopsUtils.d.ts +57 -0
- package/package.json +3 -3
- package/src/Pops.ts +7 -2
- package/src/PopsAnimation.ts +126 -0
- package/src/components/alert/index.ts +9 -9
- package/src/components/confirm/index.ts +9 -9
- package/src/components/drawer/index.ts +12 -9
- package/src/components/folder/index.ts +9 -8
- package/src/components/iframe/index.ts +18 -12
- package/src/components/iframe/types/index.ts +10 -8
- package/src/components/loading/index.ts +12 -6
- package/src/components/panel/defaultConfig.ts +1 -0
- package/src/components/panel/handlerComponents.ts +41 -111
- package/src/components/panel/index.ts +34 -28
- package/src/components/panel/types/index.ts +7 -2
- package/src/components/prompt/index.ts +9 -8
- package/src/components/rightClickMenu/index.ts +17 -14
- package/src/components/searchSuggestion/index.ts +5 -1
- package/src/components/tooltip/index.ts +20 -10
- package/src/event/EventEmiter.ts +95 -0
- package/src/handler/PopsElementHandler.ts +6 -4
- package/src/handler/PopsHandler.ts +66 -48
- package/src/handler/PopsInstHandler.ts +557 -0
- package/src/types/EventEmitter.d.ts +18 -0
- package/src/types/PopsDOMUtilsEventType.d.ts +4 -0
- package/src/types/button.d.ts +2 -1
- package/src/types/event.d.ts +6 -2
- package/src/types/inst.d.ts +4 -4
- package/src/utils/PopsDOMUtils.ts +1 -40
- package/src/utils/PopsInstanceUtils.ts +19 -627
- package/src/utils/PopsUtils.ts +194 -0
|
@@ -36,12 +36,12 @@ export type PopsPanelEventType = {
|
|
|
36
36
|
/**
|
|
37
37
|
* 该事件在右侧容器内的元素改变时触发
|
|
38
38
|
*/
|
|
39
|
-
"pops:renderRightContainer": {
|
|
39
|
+
"pops:renderRightContainer": (data: {
|
|
40
40
|
/**
|
|
41
41
|
* 视图配置
|
|
42
42
|
*/
|
|
43
43
|
viewConfig: PopsPanelContentConfig[] | PopsPanelDeepViewConfig;
|
|
44
|
-
};
|
|
44
|
+
}) => void;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -241,4 +241,9 @@ export interface PopsPanelConfig extends PopsTitleConfig, PopsDragConfig, PopsGe
|
|
|
241
241
|
* @default true
|
|
242
242
|
*/
|
|
243
243
|
useDeepMenuSwtichAnimation?: true;
|
|
244
|
+
/**
|
|
245
|
+
* 监听按键按下Esc来退出内部菜单
|
|
246
|
+
* @default true
|
|
247
|
+
*/
|
|
248
|
+
listenEscapeKeyUpToExitDeepMenu?: boolean;
|
|
244
249
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { GlobalConfig } from "../../config/GlobalConfig";
|
|
2
|
+
import { EventEmiter } from "../../event/EventEmiter";
|
|
2
3
|
import { PopsElementHandler } from "../../handler/PopsElementHandler";
|
|
3
4
|
import { PopsHandler } from "../../handler/PopsHandler";
|
|
5
|
+
import { PopsInstHandler } from "../../handler/PopsInstHandler";
|
|
4
6
|
import { PopsCSS } from "../../PopsCSS";
|
|
7
|
+
import type { EventMap } from "../../types/EventEmitter";
|
|
5
8
|
import type { PopsType } from "../../types/main";
|
|
6
9
|
import { popsDOMUtils } from "../../utils/PopsDOMUtils";
|
|
7
|
-
import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
|
|
8
10
|
import { popsUtils } from "../../utils/PopsUtils";
|
|
9
11
|
import { PopsPromptDefaultConfig } from "./defaultConfig";
|
|
10
12
|
import type { PopsPromptConfig } from "./types/index";
|
|
@@ -14,6 +16,7 @@ export const PopsPrompt = {
|
|
|
14
16
|
const guid = popsUtils.getRandomGUID();
|
|
15
17
|
// 设置当前类型
|
|
16
18
|
const popsType: PopsType = "prompt";
|
|
19
|
+
const emitter = new EventEmiter<EventMap>(popsType);
|
|
17
20
|
|
|
18
21
|
let config = PopsPromptDefaultConfig();
|
|
19
22
|
config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
|
|
@@ -53,7 +56,7 @@ export const PopsPrompt = {
|
|
|
53
56
|
]);
|
|
54
57
|
|
|
55
58
|
// 先把z-index提取出来
|
|
56
|
-
const zIndex = PopsHandler.
|
|
59
|
+
const zIndex = PopsHandler.getTargerOrFunctionValue(config.zIndex);
|
|
57
60
|
const maskHTML = PopsElementHandler.createMask(guid, zIndex);
|
|
58
61
|
|
|
59
62
|
const headerBtnHTML = PopsElementHandler.createHeader(popsType, config);
|
|
@@ -131,6 +134,7 @@ export const PopsPrompt = {
|
|
|
131
134
|
popsType,
|
|
132
135
|
$anim,
|
|
133
136
|
$pops,
|
|
137
|
+
emitter,
|
|
134
138
|
$mask
|
|
135
139
|
);
|
|
136
140
|
const result = PopsHandler.handleResultConfig(evtConfig);
|
|
@@ -146,10 +150,7 @@ export const PopsPrompt = {
|
|
|
146
150
|
// 创建到页面中
|
|
147
151
|
|
|
148
152
|
popsDOMUtils.append($shadowRoot, $elList);
|
|
149
|
-
|
|
150
|
-
config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
+
emitter.emit("pops:before-append-to-page", $shadowRoot, $shadowContainer);
|
|
153
154
|
popsDOMUtils.appendBody($shadowContainer);
|
|
154
155
|
if ($mask != null) {
|
|
155
156
|
$anim.after($mask);
|
|
@@ -162,11 +163,11 @@ export const PopsPrompt = {
|
|
|
162
163
|
$shadowContainer: $shadowContainer,
|
|
163
164
|
$shadowRoot: $shadowRoot,
|
|
164
165
|
config: config,
|
|
165
|
-
|
|
166
|
+
emitter,
|
|
166
167
|
});
|
|
167
168
|
// 拖拽
|
|
168
169
|
if (config.drag) {
|
|
169
|
-
|
|
170
|
+
PopsInstHandler.drag($pops!, {
|
|
170
171
|
dragElement: $title!,
|
|
171
172
|
limit: config.dragLimit,
|
|
172
173
|
extraDistance: config.dragExtraDistance,
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { PopsCSS } from "../../PopsCSS";
|
|
1
2
|
import { OriginPrototype } from "../../PopsCore";
|
|
3
|
+
import { PopsIcon } from "../../PopsIcon";
|
|
2
4
|
import { GlobalConfig } from "../../config/GlobalConfig";
|
|
5
|
+
import { EventEmiter } from "../../event/EventEmiter";
|
|
6
|
+
import { PopsElementHandler } from "../../handler/PopsElementHandler";
|
|
3
7
|
import { PopsHandler } from "../../handler/PopsHandler";
|
|
8
|
+
import type { EventMap } from "../../types/EventEmitter";
|
|
9
|
+
import type { PopsType } from "../../types/main";
|
|
4
10
|
import { popsDOMUtils } from "../../utils/PopsDOMUtils";
|
|
5
11
|
import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
|
|
6
12
|
import { popsUtils } from "../../utils/PopsUtils";
|
|
@@ -12,16 +18,13 @@ import type {
|
|
|
12
18
|
PopsRightClickMenuItemStoreNodeValue,
|
|
13
19
|
PopsRightClickMenuRootStoreNodeValue,
|
|
14
20
|
} from "./types";
|
|
15
|
-
import { PopsCSS } from "../../PopsCSS";
|
|
16
|
-
import { PopsIcon } from "../../PopsIcon";
|
|
17
|
-
import type { PopsType } from "../../types/main";
|
|
18
|
-
import { PopsElementHandler } from "../../handler/PopsElementHandler";
|
|
19
21
|
|
|
20
22
|
export const PopsRightClickMenu = {
|
|
21
23
|
init(__config__: PopsRightClickMenuConfig) {
|
|
22
24
|
const guid = popsUtils.getRandomGUID();
|
|
23
25
|
// 设置当前类型
|
|
24
26
|
const popsType: PopsType = "rightClickMenu";
|
|
27
|
+
const emitter = new EventEmiter<EventMap>(popsType);
|
|
25
28
|
|
|
26
29
|
let config = PopsRightClickMenuDefaultConfig();
|
|
27
30
|
config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
|
|
@@ -154,13 +157,14 @@ export const PopsRightClickMenu = {
|
|
|
154
157
|
guid: guid,
|
|
155
158
|
$anim: rootElement,
|
|
156
159
|
$pops: rootElement,
|
|
157
|
-
beforeRemoveCallBack(instCommonConfig) {
|
|
158
|
-
PopsContextMenu.closeAllMenu(instCommonConfig.$pops);
|
|
159
|
-
},
|
|
160
160
|
config: config,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
emitter,
|
|
162
|
+
});
|
|
163
|
+
emitter.on("pops:before-destory", () => {
|
|
164
|
+
PopsContextMenu.closeAllMenu(rootElement);
|
|
165
|
+
});
|
|
166
|
+
emitter.on("pops:destory", () => {
|
|
167
|
+
PopsContextMenu.closeAllMenu(rootElement);
|
|
164
168
|
});
|
|
165
169
|
}
|
|
166
170
|
},
|
|
@@ -254,6 +258,7 @@ export const PopsRightClickMenu = {
|
|
|
254
258
|
);
|
|
255
259
|
const zIndex = this.getMenuZIndex();
|
|
256
260
|
if (zIndex > 10000) {
|
|
261
|
+
// 大于默认值
|
|
257
262
|
$menu.style.zIndex = zIndex.toString();
|
|
258
263
|
}
|
|
259
264
|
if (isChildren) {
|
|
@@ -274,7 +279,7 @@ export const PopsRightClickMenu = {
|
|
|
274
279
|
* 动态获取配的z-index
|
|
275
280
|
*/
|
|
276
281
|
getMenuZIndex() {
|
|
277
|
-
return PopsHandler.
|
|
282
|
+
return PopsHandler.getTargerOrFunctionValue(config.zIndex);
|
|
278
283
|
},
|
|
279
284
|
/**
|
|
280
285
|
* 获取left、top偏移
|
|
@@ -395,9 +400,7 @@ export const PopsRightClickMenu = {
|
|
|
395
400
|
popsDOMUtils.append($shadowRoot, menuElement);
|
|
396
401
|
// 判断容器是否存在
|
|
397
402
|
if (!document.contains($shadowContainer)) {
|
|
398
|
-
|
|
399
|
-
config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
|
|
400
|
-
}
|
|
403
|
+
emitter.emit("pops:before-append-to-page", $shadowRoot, $shadowContainer);
|
|
401
404
|
popsDOMUtils.appendBody($shadowContainer);
|
|
402
405
|
}
|
|
403
406
|
this.handlerShowMenuCSS(menuElement, menuEvent);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { PopsCommonCSSClassName } from "../../config/CommonCSSClassName";
|
|
2
2
|
import { GlobalConfig } from "../../config/GlobalConfig";
|
|
3
|
+
import { EventEmiter } from "../../event/EventEmiter";
|
|
3
4
|
import { PopsElementHandler } from "../../handler/PopsElementHandler";
|
|
4
5
|
import { PopsHandler } from "../../handler/PopsHandler";
|
|
5
6
|
import { PopsCSS } from "../../PopsCSS";
|
|
7
|
+
import type { EventMap } from "../../types/EventEmitter";
|
|
6
8
|
import type { PopsType } from "../../types/main";
|
|
7
9
|
import { popsDOMUtils } from "../../utils/PopsDOMUtils";
|
|
8
10
|
import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
|
|
@@ -15,6 +17,7 @@ export const PopsSearchSuggestion = {
|
|
|
15
17
|
const guid = popsUtils.getRandomGUID();
|
|
16
18
|
// 设置当前类型
|
|
17
19
|
const popsType: PopsType = "searchSuggestion";
|
|
20
|
+
const emitter = new EventEmiter<EventMap>(popsType);
|
|
18
21
|
|
|
19
22
|
let config = PopsSearchSuggestionDefaultConfig();
|
|
20
23
|
config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
|
|
@@ -54,6 +57,7 @@ export const PopsSearchSuggestion = {
|
|
|
54
57
|
passive: true,
|
|
55
58
|
};
|
|
56
59
|
const SearchSuggestion = {
|
|
60
|
+
emitter: emitter,
|
|
57
61
|
/**
|
|
58
62
|
* 当前的环境,可以是document,可以是shadowroot,默认是document
|
|
59
63
|
*/
|
|
@@ -282,7 +286,7 @@ export const PopsSearchSuggestion = {
|
|
|
282
286
|
border: initial;
|
|
283
287
|
overflow: initial;
|
|
284
288
|
position: ${config.isAbsolute ? "absolute" : "fixed"};
|
|
285
|
-
z-index: ${PopsHandler.
|
|
289
|
+
z-index: ${PopsHandler.getTargerOrFunctionValue(config.zIndex)};
|
|
286
290
|
}
|
|
287
291
|
.pops-${popsType}-search-suggestion-dropdown-wrapper{
|
|
288
292
|
max-height: ${config.maxHeight};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { GlobalConfig } from "../../config/GlobalConfig";
|
|
2
|
+
import { EventEmiter } from "../../event/EventEmiter";
|
|
2
3
|
import { PopsElementHandler } from "../../handler/PopsElementHandler";
|
|
3
4
|
import { PopsHandler } from "../../handler/PopsHandler";
|
|
4
5
|
import { PopsCSS } from "../../PopsCSS";
|
|
6
|
+
import type { EventMap } from "../../types/EventEmitter";
|
|
5
7
|
import type { PopsType } from "../../types/main";
|
|
6
8
|
import { popsDOMUtils } from "../../utils/PopsDOMUtils";
|
|
7
9
|
import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
|
|
@@ -19,6 +21,7 @@ export class ToolTip {
|
|
|
19
21
|
$content: null as unknown as HTMLElement,
|
|
20
22
|
$arrow: null as unknown as HTMLElement,
|
|
21
23
|
};
|
|
24
|
+
emitter: EventEmiter<EventMap>;
|
|
22
25
|
$data = {
|
|
23
26
|
config: null as any as Required<PopsToolTipConfig>,
|
|
24
27
|
guid: null as any as string,
|
|
@@ -31,8 +34,10 @@ export class ToolTip {
|
|
|
31
34
|
ShadowInfo: {
|
|
32
35
|
$shadowContainer: HTMLDivElement;
|
|
33
36
|
$shadowRoot: ShadowRoot | HTMLElement;
|
|
34
|
-
}
|
|
37
|
+
},
|
|
38
|
+
emitter: EventEmiter<EventMap>
|
|
35
39
|
) {
|
|
40
|
+
this.emitter = emitter;
|
|
36
41
|
this.$data.config = config;
|
|
37
42
|
this.$data.guid = guid;
|
|
38
43
|
this.$el.$shadowContainer = ShadowInfo.$shadowContainer;
|
|
@@ -85,7 +90,7 @@ export class ToolTip {
|
|
|
85
90
|
// 处理className
|
|
86
91
|
popsDOMUtils.addClassName($toolTipContainer, this.$data.config.className);
|
|
87
92
|
// 添加z-index
|
|
88
|
-
$toolTipContainer.style.zIndex = PopsHandler.
|
|
93
|
+
$toolTipContainer.style.zIndex = PopsHandler.getTargerOrFunctionValue(this.$data.config.zIndex).toString();
|
|
89
94
|
// 添加自定义style
|
|
90
95
|
PopsElementHandler.addStyle($toolTipContainer, this.$data.config.style);
|
|
91
96
|
// 添加自定义浅色style
|
|
@@ -133,7 +138,7 @@ export class ToolTip {
|
|
|
133
138
|
* 获取z-index
|
|
134
139
|
*/
|
|
135
140
|
getZIndex() {
|
|
136
|
-
const zIndex = PopsHandler.
|
|
141
|
+
const zIndex = PopsHandler.getTargerOrFunctionValue(this.$data.config.zIndex);
|
|
137
142
|
return zIndex;
|
|
138
143
|
}
|
|
139
144
|
/**
|
|
@@ -328,9 +333,7 @@ export class ToolTip {
|
|
|
328
333
|
|
|
329
334
|
if (!popsUtils.contains(this.$el.$shadowContainer)) {
|
|
330
335
|
// 页面不存在Shadow,添加
|
|
331
|
-
|
|
332
|
-
this.$data.config.beforeAppendToPageCallBack(this.$el.$shadowRoot, this.$el.$shadowContainer);
|
|
333
|
-
}
|
|
336
|
+
this.emitter.emit("pops:before-append-to-page", this.$el.$shadowRoot, this.$el.$shadowContainer);
|
|
334
337
|
popsDOMUtils.append(document.body, this.$el.$shadowContainer);
|
|
335
338
|
}
|
|
336
339
|
|
|
@@ -555,6 +558,7 @@ export const PopsTooltip = {
|
|
|
555
558
|
const guid = popsUtils.getRandomGUID();
|
|
556
559
|
// 设置当前类型
|
|
557
560
|
const popsType: PopsType = "tooltip";
|
|
561
|
+
const emitter = new EventEmiter<EventMap>(popsType);
|
|
558
562
|
|
|
559
563
|
let config = PopsTooltipDefaultConfig();
|
|
560
564
|
config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
|
|
@@ -593,10 +597,15 @@ export const PopsTooltip = {
|
|
|
593
597
|
},
|
|
594
598
|
]);
|
|
595
599
|
|
|
596
|
-
const toolTip = new ToolTip(
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
+
const toolTip = new ToolTip(
|
|
601
|
+
config,
|
|
602
|
+
guid,
|
|
603
|
+
{
|
|
604
|
+
$shadowContainer,
|
|
605
|
+
$shadowRoot,
|
|
606
|
+
},
|
|
607
|
+
emitter
|
|
608
|
+
);
|
|
600
609
|
if (config.alwaysShow) {
|
|
601
610
|
// 总是显示
|
|
602
611
|
// 直接显示
|
|
@@ -611,6 +620,7 @@ export const PopsTooltip = {
|
|
|
611
620
|
$shadowContainer,
|
|
612
621
|
$shadowRoot,
|
|
613
622
|
toolTip,
|
|
623
|
+
emitter,
|
|
614
624
|
};
|
|
615
625
|
},
|
|
616
626
|
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { EventMap, CustomEventMap } from "../types/EventEmitter";
|
|
2
|
+
import type { PopsType } from "../types/main";
|
|
3
|
+
|
|
4
|
+
class EventEmiter<T extends CustomEventMap = CustomEventMap> {
|
|
5
|
+
#type: PopsType;
|
|
6
|
+
#data = new Map<
|
|
7
|
+
string,
|
|
8
|
+
{
|
|
9
|
+
type: PopsType;
|
|
10
|
+
time: number;
|
|
11
|
+
callback: (...args: any[]) => IPromise<void>;
|
|
12
|
+
}[]
|
|
13
|
+
>();
|
|
14
|
+
constructor(type: PopsType) {
|
|
15
|
+
this.#type = type;
|
|
16
|
+
document.addEventListener;
|
|
17
|
+
}
|
|
18
|
+
on<P extends keyof EventMap>(
|
|
19
|
+
eventName: P,
|
|
20
|
+
callback: EventMap[P]
|
|
21
|
+
): {
|
|
22
|
+
off: () => IPromise<void>;
|
|
23
|
+
emit: (...args: Parameters<T[P]>) => IPromise<void>;
|
|
24
|
+
};
|
|
25
|
+
on<P extends keyof T>(
|
|
26
|
+
eventName: P,
|
|
27
|
+
callback: T[P]
|
|
28
|
+
): {
|
|
29
|
+
off: () => IPromise<void>;
|
|
30
|
+
emit: (...args: Parameters<T[P]>) => IPromise<void>;
|
|
31
|
+
};
|
|
32
|
+
on<P extends keyof EventMap | keyof CustomEventMap>(eventName: P, callback: (EventMap & CustomEventMap)[P]) {
|
|
33
|
+
const eventList = this.#data.get(eventName) ?? [];
|
|
34
|
+
eventList.push({ type: this.#type, time: Date.now(), callback: callback });
|
|
35
|
+
this.#data.set(eventName, eventList);
|
|
36
|
+
return {
|
|
37
|
+
off: () => {
|
|
38
|
+
this.off(eventName as keyof EventMap, callback);
|
|
39
|
+
},
|
|
40
|
+
emit: (...args: Parameters<T[P]>) => {
|
|
41
|
+
this.emit(eventName, ...args);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
off<P extends keyof EventMap>(eventName: P, callback: EventMap[P]): IPromise<void>;
|
|
46
|
+
off<P extends keyof T>(eventName: P, callback: T[P]): IPromise<void>;
|
|
47
|
+
off<P extends keyof EventMap | keyof CustomEventMap>(eventName: P, callback: (EventMap & CustomEventMap)[P]) {
|
|
48
|
+
const eventList = this.#data.get(eventName) ?? [];
|
|
49
|
+
let isOffSuccess = false;
|
|
50
|
+
for (let index = eventList.length - 1; index >= 0; index--) {
|
|
51
|
+
if (eventList[index].callback === callback) {
|
|
52
|
+
isOffSuccess = true;
|
|
53
|
+
eventList.splice(index, 1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (eventList.length === 0) {
|
|
57
|
+
// empty
|
|
58
|
+
this.#data.delete(eventName);
|
|
59
|
+
} else {
|
|
60
|
+
if (isOffSuccess) {
|
|
61
|
+
// update
|
|
62
|
+
this.#data.set(eventName, eventList);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
emit<P extends keyof T>(eventName: P, ...args: Parameters<T[P]>): IPromise<void>;
|
|
67
|
+
emit<P extends keyof EventMap>(eventName: P, ...args: Parameters<EventMap[P]>): IPromise<void>;
|
|
68
|
+
async emit<P extends keyof EventMap | keyof CustomEventMap>(eventName: P, ...args: Parameters<T[P]>) {
|
|
69
|
+
const eventList = this.#data.get(eventName) ?? [];
|
|
70
|
+
for (const item of eventList) {
|
|
71
|
+
await item.callback(...args);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
offAll<P extends keyof EventMap>(eventName?: P): IPromise<void>;
|
|
75
|
+
offAll<P extends keyof T>(eventName?: P): IPromise<void>;
|
|
76
|
+
offAll<P extends keyof EventMap | keyof CustomEventMap>(eventName?: P) {
|
|
77
|
+
if (typeof eventName === "string") {
|
|
78
|
+
this.#data.delete(eventName);
|
|
79
|
+
} else {
|
|
80
|
+
this.#data.clear();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 获取所有添加的事件
|
|
85
|
+
*/
|
|
86
|
+
getAllEvents(eventName?: string) {
|
|
87
|
+
if (typeof eventName === "string") {
|
|
88
|
+
return this.#data.get(eventName);
|
|
89
|
+
} else {
|
|
90
|
+
return Array.from(this.#data.values());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { EventEmiter };
|
|
@@ -52,7 +52,7 @@ export const PopsElementHandler = {
|
|
|
52
52
|
const popsPosition = __config__.position || "";
|
|
53
53
|
if (config.zIndex != null) {
|
|
54
54
|
popsAnimStyle += `z-index: ${zIndex};`;
|
|
55
|
-
popsStyle += `z-index: ${zIndex};`;
|
|
55
|
+
// popsStyle += `z-index: ${zIndex};`;
|
|
56
56
|
}
|
|
57
57
|
if (__config__.width != null) {
|
|
58
58
|
popsStyle += `width: ${__config__.width};`;
|
|
@@ -61,15 +61,17 @@ export const PopsElementHandler = {
|
|
|
61
61
|
popsStyle += `height: ${__config__.height};`;
|
|
62
62
|
}
|
|
63
63
|
const hasBottomBtn = bottomBtnHTML.trim() === "" ? false : true;
|
|
64
|
+
const popsClassNameList = ["pops"];
|
|
65
|
+
if (config.class) {
|
|
66
|
+
popsClassNameList.push(...config.class.split(" "));
|
|
67
|
+
}
|
|
64
68
|
return /*html*/ `
|
|
65
69
|
<div class="pops-anim" anim="${__config__.animation || ""}" style="${popsAnimStyle}" data-guid="${guid}">${
|
|
66
70
|
config.style != null ? /*html*/ `<style tyle="text/css" data-name="style">${config.style}</style>` : ""
|
|
67
71
|
}
|
|
68
72
|
${config.lightStyle != null ? /*html*/ `<style tyle="text/css" data-name="lightStyle">@media (prefers-color-scheme: light) {${config.lightStyle}}</style>` : ""}
|
|
69
73
|
${config.darkStyle != null ? /*html*/ `<style tyle="text/css" data-name="darkStyle">@media (prefers-color-scheme: dark) {${config.darkStyle}}</style>` : ""}
|
|
70
|
-
<div class="
|
|
71
|
-
config.class || ""
|
|
72
|
-
}" data-bottom-btn="${hasBottomBtn}" type-value="${type}" style="${popsStyle}" position="${popsPosition}" data-guid="${guid}">${html}</div>
|
|
74
|
+
<div class="${popsClassNameList.join(" ")}" data-bottom-btn="${hasBottomBtn}" type-value="${type}" style="${popsStyle}" position="${popsPosition}" data-guid="${guid}">${html}</div>
|
|
73
75
|
</div>`;
|
|
74
76
|
},
|
|
75
77
|
/**
|
|
@@ -6,16 +6,18 @@ import type { PopsIframeConfig } from "../components/iframe/types";
|
|
|
6
6
|
import type { PopsLoadingConfig } from "../components/loading/types";
|
|
7
7
|
import type { PopsPanelConfig } from "../components/panel/types";
|
|
8
8
|
import type { PopsPromptConfig } from "../components/prompt/types/index";
|
|
9
|
-
import {
|
|
9
|
+
import type { EventEmiter } from "../event/EventEmiter";
|
|
10
10
|
import { PopsAnimation } from "../PopsAnimation";
|
|
11
|
+
import { PopsCore } from "../PopsCore";
|
|
11
12
|
import { PopsInstData } from "../PopsInst";
|
|
12
13
|
import type { PopsGeneralConfig } from "../types/components";
|
|
13
14
|
import type { PopsEventConfig, PopsHandlerEventConfig } from "../types/event";
|
|
15
|
+
import type { CustomEventMap } from "../types/EventEmitter";
|
|
14
16
|
import type { PopsInstGeneralConfig } from "../types/inst";
|
|
15
|
-
import type { PopsInstStoreType,
|
|
17
|
+
import type { PopsInstStoreType, PopsSupportAnimConfigType, PopsSupportOnlyConfig, PopsType } from "../types/main";
|
|
16
18
|
import { popsDOMUtils } from "../utils/PopsDOMUtils";
|
|
17
|
-
import { PopsInstanceUtils } from "../utils/PopsInstanceUtils";
|
|
18
19
|
import { popsUtils } from "../utils/PopsUtils";
|
|
20
|
+
import { PopsInstHandler } from "./PopsInstHandler";
|
|
19
21
|
|
|
20
22
|
export const PopsHandler = {
|
|
21
23
|
/**
|
|
@@ -159,10 +161,10 @@ export const PopsHandler = {
|
|
|
159
161
|
function originalRun() {
|
|
160
162
|
if (config.config.mask!.clickEvent!.toClose) {
|
|
161
163
|
// 关闭
|
|
162
|
-
return
|
|
164
|
+
return PopsInstHandler.close(config.config, config.type, targetInst, config.guid, config.animElement);
|
|
163
165
|
} else if (config.config.mask!.clickEvent!.toHide) {
|
|
164
166
|
// 隐藏
|
|
165
|
-
return
|
|
167
|
+
return PopsInstHandler.hide(
|
|
166
168
|
config.config,
|
|
167
169
|
config.type,
|
|
168
170
|
targetInst,
|
|
@@ -373,7 +375,7 @@ export const PopsHandler = {
|
|
|
373
375
|
* @param $mask 遮罩层
|
|
374
376
|
* @param config 当前配置
|
|
375
377
|
*/
|
|
376
|
-
handleEventConfig(
|
|
378
|
+
handleEventConfig<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>>(
|
|
377
379
|
config:
|
|
378
380
|
| PopsAlertConfig
|
|
379
381
|
| PopsDrawerConfig
|
|
@@ -389,8 +391,9 @@ export const PopsHandler = {
|
|
|
389
391
|
type: PopsInstStoreType,
|
|
390
392
|
$anim: HTMLDivElement,
|
|
391
393
|
$pops: HTMLDivElement,
|
|
394
|
+
emitter: E,
|
|
392
395
|
$mask?: HTMLDivElement
|
|
393
|
-
): PopsEventConfig {
|
|
396
|
+
): PopsEventConfig<E> {
|
|
394
397
|
return {
|
|
395
398
|
$shadowContainer: $shadowContainer,
|
|
396
399
|
$shadowRoot: $shadowRoot,
|
|
@@ -400,17 +403,18 @@ export const PopsHandler = {
|
|
|
400
403
|
$mask: $mask,
|
|
401
404
|
mode: type,
|
|
402
405
|
guid: guid,
|
|
406
|
+
emitter: emitter,
|
|
403
407
|
close() {
|
|
404
|
-
return
|
|
408
|
+
return PopsInstHandler.close(config, type, PopsInstData[type], guid, $anim);
|
|
405
409
|
},
|
|
406
410
|
hide() {
|
|
407
|
-
return
|
|
411
|
+
return PopsInstHandler.hide(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
408
412
|
},
|
|
409
413
|
show($parent?: HTMLElement | Document | ShadowRoot) {
|
|
410
414
|
if ($parent) {
|
|
411
415
|
$parent.appendChild(PopsInstData[type][0].$shadowRoot);
|
|
412
416
|
}
|
|
413
|
-
return
|
|
417
|
+
return PopsInstHandler.show(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
414
418
|
},
|
|
415
419
|
};
|
|
416
420
|
},
|
|
@@ -423,7 +427,7 @@ export const PopsHandler = {
|
|
|
423
427
|
* @param $mask 遮罩层
|
|
424
428
|
* @param config 当前配置
|
|
425
429
|
*/
|
|
426
|
-
handleLoadingEventConfig(
|
|
430
|
+
handleLoadingEventConfig<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>>(
|
|
427
431
|
config:
|
|
428
432
|
| PopsAlertConfig
|
|
429
433
|
| PopsDrawerConfig
|
|
@@ -437,8 +441,9 @@ export const PopsHandler = {
|
|
|
437
441
|
type: "loading",
|
|
438
442
|
$anim: HTMLDivElement,
|
|
439
443
|
$pops: HTMLDivElement,
|
|
444
|
+
emitter: E,
|
|
440
445
|
$mask?: HTMLDivElement
|
|
441
|
-
): Omit<PopsEventConfig
|
|
446
|
+
): Omit<PopsEventConfig<E>, "$shadowContainer" | "$shadowRoot"> {
|
|
442
447
|
return {
|
|
443
448
|
$el: $anim,
|
|
444
449
|
$anim: $anim,
|
|
@@ -446,14 +451,15 @@ export const PopsHandler = {
|
|
|
446
451
|
$mask: $mask,
|
|
447
452
|
mode: type,
|
|
448
453
|
guid: guid,
|
|
454
|
+
emitter,
|
|
449
455
|
close() {
|
|
450
|
-
return
|
|
456
|
+
return PopsInstHandler.close(config, type, PopsInstData[type], guid, $anim);
|
|
451
457
|
},
|
|
452
458
|
hide() {
|
|
453
|
-
return
|
|
459
|
+
return PopsInstHandler.hide(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
454
460
|
},
|
|
455
461
|
show() {
|
|
456
|
-
return
|
|
462
|
+
return PopsInstHandler.show(config, type, PopsInstData[type], guid, $anim, $mask);
|
|
457
463
|
},
|
|
458
464
|
};
|
|
459
465
|
},
|
|
@@ -474,14 +480,14 @@ export const PopsHandler = {
|
|
|
474
480
|
* @param eventConfig 事件配置,由popsHandler.handleEventConfig创建的
|
|
475
481
|
* @param callback 点击回调
|
|
476
482
|
*/
|
|
477
|
-
handleClickEvent(
|
|
478
|
-
type: PopsHandlerEventConfig["type"],
|
|
483
|
+
handleClickEvent<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>>(
|
|
484
|
+
type: PopsHandlerEventConfig<E>["type"],
|
|
479
485
|
$btn: HTMLElement,
|
|
480
|
-
eventConfig: PopsEventConfig
|
|
481
|
-
callback?: (details: PopsHandlerEventConfig
|
|
486
|
+
eventConfig: PopsEventConfig<E>,
|
|
487
|
+
callback?: (details: PopsHandlerEventConfig<E>, event: PointerEvent | MouseEvent) => void
|
|
482
488
|
) {
|
|
483
489
|
if (typeof callback !== "function") return;
|
|
484
|
-
popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
490
|
+
return popsDOMUtils.on<PointerEvent | MouseEvent>(
|
|
485
491
|
$btn,
|
|
486
492
|
"click",
|
|
487
493
|
(event) => {
|
|
@@ -523,16 +529,10 @@ export const PopsHandler = {
|
|
|
523
529
|
callback && callback(event);
|
|
524
530
|
}
|
|
525
531
|
};
|
|
526
|
-
popsDOMUtils.on(PopsCore.globalThis, "keydown", keyboardEvent, {
|
|
532
|
+
const listener = popsDOMUtils.on(PopsCore.globalThis, "keydown", keyboardEvent, {
|
|
527
533
|
capture: true,
|
|
528
534
|
});
|
|
529
|
-
return
|
|
530
|
-
removeKeyboardEvent() {
|
|
531
|
-
popsDOMUtils.off(globalThis, "keydown", keyboardEvent, {
|
|
532
|
-
capture: true,
|
|
533
|
-
});
|
|
534
|
-
},
|
|
535
|
-
};
|
|
535
|
+
return listener;
|
|
536
536
|
},
|
|
537
537
|
/**
|
|
538
538
|
* 处理prompt的点击事件
|
|
@@ -542,13 +542,13 @@ export const PopsHandler = {
|
|
|
542
542
|
* @param eventConfig 事件配置,由popsHandler.handleEventConfig创建的
|
|
543
543
|
* @param callback 点击回调
|
|
544
544
|
*/
|
|
545
|
-
handlePromptClickEvent(
|
|
546
|
-
type: PopsHandlerEventConfig["type"],
|
|
545
|
+
handlePromptClickEvent<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>>(
|
|
546
|
+
type: PopsHandlerEventConfig<E>["type"],
|
|
547
547
|
inputElement: HTMLInputElement | HTMLTextAreaElement,
|
|
548
548
|
$btn: HTMLElement,
|
|
549
|
-
eventConfig: PopsEventConfig
|
|
549
|
+
eventConfig: PopsEventConfig<E>,
|
|
550
550
|
callback: (
|
|
551
|
-
details: PopsEventConfig & {
|
|
551
|
+
details: PopsEventConfig<E> & {
|
|
552
552
|
type: any;
|
|
553
553
|
text: string;
|
|
554
554
|
},
|
|
@@ -572,14 +572,15 @@ export const PopsHandler = {
|
|
|
572
572
|
);
|
|
573
573
|
},
|
|
574
574
|
/**
|
|
575
|
-
*
|
|
576
|
-
* @param
|
|
575
|
+
* 获取数值
|
|
576
|
+
* @param target
|
|
577
577
|
*/
|
|
578
|
-
|
|
579
|
-
if (typeof
|
|
580
|
-
|
|
578
|
+
getTargerOrFunctionValue<T>(target: T | (() => T)): T {
|
|
579
|
+
if (typeof target === "function") {
|
|
580
|
+
const result = (target as () => T)();
|
|
581
|
+
return result;
|
|
581
582
|
} else {
|
|
582
|
-
return
|
|
583
|
+
return target;
|
|
583
584
|
}
|
|
584
585
|
},
|
|
585
586
|
/**
|
|
@@ -596,10 +597,10 @@ export const PopsHandler = {
|
|
|
596
597
|
if (type === "loading" || type === "tooltip" || type === "rightClickMenu") {
|
|
597
598
|
const inst = PopsInstData[type as keyof typeof PopsInstData];
|
|
598
599
|
if (inst) {
|
|
599
|
-
|
|
600
|
+
PopsInstHandler.removeInstance([inst], "", true);
|
|
600
601
|
}
|
|
601
602
|
} else {
|
|
602
|
-
|
|
603
|
+
PopsInstHandler.removeInstance(
|
|
603
604
|
[
|
|
604
605
|
PopsInstData.alert,
|
|
605
606
|
PopsInstData.confirm,
|
|
@@ -613,15 +614,32 @@ export const PopsHandler = {
|
|
|
613
614
|
true
|
|
614
615
|
);
|
|
615
616
|
}
|
|
616
|
-
} else {
|
|
617
|
-
// 对配置进行处理
|
|
618
|
-
// 选择配置的z-index和已有的pops实例的最大z-index值
|
|
619
|
-
const originZIndex = config.zIndex;
|
|
620
|
-
config.zIndex = () => {
|
|
621
|
-
const { zIndex: maxZIndex } = PopsInstanceUtils.getPopsMaxZIndex(PopsHandler.handleZIndex(originZIndex) + 100);
|
|
622
|
-
return maxZIndex;
|
|
623
|
-
};
|
|
624
617
|
}
|
|
618
|
+
config = this.handleZIndex(config);
|
|
619
|
+
|
|
620
|
+
return config;
|
|
621
|
+
},
|
|
622
|
+
/**
|
|
623
|
+
* 处理z-index
|
|
624
|
+
* @param config 配置
|
|
625
|
+
*/
|
|
626
|
+
handleZIndex<T extends Required<PopsSupportOnlyConfig[keyof PopsSupportOnlyConfig]>>(config: T): T {
|
|
627
|
+
// 对配置进行处理
|
|
628
|
+
// 选择配置的z-index和已有的pops实例的最大z-index值
|
|
629
|
+
const originZIndex = config.zIndex;
|
|
630
|
+
const handler = () => {
|
|
631
|
+
let deviation = 100;
|
|
632
|
+
if (originZIndex.toString() !== handler.toString()) {
|
|
633
|
+
// 避免叠加覆盖
|
|
634
|
+
deviation += PopsHandler.getTargerOrFunctionValue(originZIndex) ?? 0;
|
|
635
|
+
}
|
|
636
|
+
let maxZIndex = deviation;
|
|
637
|
+
const pointZIndexInfoList = popsUtils.getMaxZIndexNodeInfoFromPoint(deviation);
|
|
638
|
+
const pointZIndexInfo = pointZIndexInfoList[0];
|
|
639
|
+
maxZIndex = Math.max(maxZIndex, pointZIndexInfo?.zIndex ?? deviation);
|
|
640
|
+
return maxZIndex;
|
|
641
|
+
};
|
|
642
|
+
config.zIndex = handler;
|
|
625
643
|
return config;
|
|
626
644
|
},
|
|
627
645
|
/**
|