@whitesev/pops 3.3.5 → 4.0.1

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.
Files changed (84) hide show
  1. package/dist/index.amd.js +13099 -12934
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.amd.min.js +1 -1
  4. package/dist/index.amd.min.js.map +1 -1
  5. package/dist/index.cjs.js +752 -587
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/index.cjs.min.js +1 -1
  8. package/dist/index.cjs.min.js.map +1 -1
  9. package/dist/index.esm.js +752 -587
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.esm.min.js +1 -1
  12. package/dist/index.esm.min.js.map +1 -1
  13. package/dist/index.iife.js +13100 -12935
  14. package/dist/index.iife.js.map +1 -1
  15. package/dist/index.iife.min.js +1 -1
  16. package/dist/index.iife.min.js.map +1 -1
  17. package/dist/index.system.js +13103 -12938
  18. package/dist/index.system.js.map +1 -1
  19. package/dist/index.system.min.js +1 -1
  20. package/dist/index.system.min.js.map +1 -1
  21. package/dist/index.umd.js +13102 -12937
  22. package/dist/index.umd.js.map +1 -1
  23. package/dist/index.umd.min.js +1 -1
  24. package/dist/index.umd.min.js.map +1 -1
  25. package/dist/types/src/Pops.d.ts +131 -77
  26. package/dist/types/src/PopsAnimation.d.ts +33 -0
  27. package/dist/types/src/PopsIcon.d.ts +1 -1
  28. package/dist/types/src/components/alert/index.d.ts +3 -1
  29. package/dist/types/src/components/confirm/index.d.ts +3 -1
  30. package/dist/types/src/components/drawer/index.d.ts +3 -1
  31. package/dist/types/src/components/folder/index.d.ts +3 -1
  32. package/dist/types/src/components/iframe/index.d.ts +6 -1
  33. package/dist/types/src/components/iframe/types/index.d.ts +4 -2
  34. package/dist/types/src/components/loading/index.d.ts +3 -1
  35. package/dist/types/src/components/panel/handlerComponents.d.ts +4 -1
  36. package/dist/types/src/components/panel/index.d.ts +2 -16
  37. package/dist/types/src/components/panel/types/index.d.ts +7 -2
  38. package/dist/types/src/components/prompt/index.d.ts +3 -1
  39. package/dist/types/src/components/searchSuggestion/index.d.ts +4 -1
  40. package/dist/types/src/components/tooltip/index.d.ts +5 -1
  41. package/dist/types/src/config/GlobalConfig.d.ts +63 -23
  42. package/dist/types/src/event/EventEmiter.d.ts +33 -0
  43. package/dist/types/src/handler/PopsHandler.d.ts +16 -11
  44. package/dist/types/src/handler/PopsInstHandler.d.ts +67 -0
  45. package/dist/types/src/types/EventEmitter.d.ts +18 -0
  46. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +4 -0
  47. package/dist/types/src/types/button.d.ts +2 -1
  48. package/dist/types/src/types/event.d.ts +6 -2
  49. package/dist/types/src/types/inst.d.ts +4 -4
  50. package/dist/types/src/utils/PopsDOMUtils.d.ts +0 -16
  51. package/dist/types/src/utils/PopsInstanceUtils.d.ts +1 -89
  52. package/dist/types/src/utils/PopsUtils.d.ts +57 -0
  53. package/package.json +3 -3
  54. package/src/Pops.ts +7 -2
  55. package/src/PopsAnimation.ts +126 -0
  56. package/src/components/alert/index.ts +9 -9
  57. package/src/components/confirm/index.ts +9 -9
  58. package/src/components/drawer/index.ts +12 -9
  59. package/src/components/folder/index.ts +9 -8
  60. package/src/components/iframe/index.ts +18 -12
  61. package/src/components/iframe/types/index.ts +10 -8
  62. package/src/components/loading/index.ts +12 -6
  63. package/src/components/panel/defaultConfig.ts +1 -0
  64. package/src/components/panel/handlerComponents.ts +41 -111
  65. package/src/components/panel/index.ts +34 -28
  66. package/src/components/panel/types/index.ts +7 -2
  67. package/src/components/prompt/index.ts +9 -8
  68. package/src/components/rightClickMenu/index.ts +17 -14
  69. package/src/components/searchSuggestion/index.ts +5 -1
  70. package/src/components/tooltip/index.ts +20 -10
  71. package/src/config/GlobalConfig.ts +21 -14
  72. package/src/css/index.css +2 -0
  73. package/src/event/EventEmiter.ts +95 -0
  74. package/src/handler/PopsElementHandler.ts +8 -6
  75. package/src/handler/PopsHandler.ts +65 -48
  76. package/src/handler/PopsInstHandler.ts +557 -0
  77. package/src/types/EventEmitter.d.ts +18 -0
  78. package/src/types/PopsDOMUtilsEventType.d.ts +4 -0
  79. package/src/types/button.d.ts +2 -1
  80. package/src/types/event.d.ts +6 -2
  81. package/src/types/inst.d.ts +4 -4
  82. package/src/utils/PopsDOMUtils.ts +1 -40
  83. package/src/utils/PopsInstanceUtils.ts +10 -639
  84. package/src/utils/PopsUtils.ts +194 -0
@@ -0,0 +1,557 @@
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";
9
+ import type { PopsRightClickMenuConfig } from "../components/rightClickMenu/types";
10
+ import type { PopsToolTipConfig } from "../components/tooltip/types";
11
+ import { PopsAnimation } from "../PopsAnimation";
12
+ import { PopsCore } from "../PopsCore";
13
+ import { PopsInstData } from "../PopsInst";
14
+ import type { PopsInstGeneralConfig } from "../types/inst";
15
+ import type { PopsInstStoreType } from "../types/main";
16
+ import { popsDOMUtils } from "../utils/PopsDOMUtils";
17
+ import { popsUtils } from "../utils/PopsUtils";
18
+
19
+ export const PopsInstHandler = {
20
+ /**
21
+ * 删除配置中对应的对象
22
+ * @param totalInstConfigList 配置实例列表
23
+ * @param guid 唯一标识
24
+ * @param isAll 是否全部删除
25
+ */
26
+ async removeInstance(totalInstConfigList: PopsInstGeneralConfig[][], guid?: string, isAll = false) {
27
+ /**
28
+ * 移除元素实例
29
+ * @param instCommonConfig
30
+ */
31
+ const removeInst = async (instCommonConfig: PopsInstGeneralConfig) => {
32
+ await instCommonConfig.emitter.emit("pops:before-destory", instCommonConfig);
33
+ instCommonConfig?.$anim?.remove();
34
+ instCommonConfig?.$pops?.remove();
35
+ instCommonConfig?.$mask?.remove();
36
+ instCommonConfig?.$shadowContainer?.remove();
37
+ await instCommonConfig.emitter.emit("pops:destory");
38
+ // 再清空全部监听的事件
39
+ await instCommonConfig.emitter.offAll();
40
+ };
41
+ const asyncInstTask: Promise<void>[] = [];
42
+ // [ inst[], inst[],...]
43
+ for (const instConfigList of totalInstConfigList) {
44
+ for (let index = 0; index < instConfigList.length; index++) {
45
+ const instConfigItem = instConfigList[index];
46
+ // 移除全部或者guid相同
47
+ if (isAll || (typeof guid === "string" && instConfigItem.guid === guid)) {
48
+ // 判断是否有动画
49
+ const animName = instConfigItem.$anim.getAttribute("anim")!;
50
+ if (PopsAnimation.hasAnim(animName)) {
51
+ const reverseAnimName = animName + "-reverse";
52
+ popsDOMUtils.css(instConfigItem.$anim, "width", "100%");
53
+ popsDOMUtils.css(instConfigItem.$anim, "height", "100%");
54
+ popsDOMUtils.css(instConfigItem.$anim, "animation-name", reverseAnimName);
55
+ if (PopsAnimation.hasAnim(popsDOMUtils.css(instConfigItem.$anim, "animation-name"))) {
56
+ asyncInstTask.push(
57
+ new Promise<void>((resolve) => {
58
+ popsDOMUtils.on(
59
+ instConfigItem.$anim,
60
+ popsDOMUtils.getAnimationEndNameList(),
61
+ async () => {
62
+ await removeInst(instConfigItem);
63
+ resolve();
64
+ },
65
+ {
66
+ capture: true,
67
+ }
68
+ );
69
+ })
70
+ );
71
+ } else {
72
+ asyncInstTask.push(removeInst(instConfigItem));
73
+ }
74
+ } else {
75
+ asyncInstTask.push(removeInst(instConfigItem));
76
+ }
77
+ instConfigList.splice(index, 1);
78
+ index--;
79
+ }
80
+ }
81
+ }
82
+ await Promise.all(asyncInstTask);
83
+ return totalInstConfigList;
84
+ },
85
+ /**
86
+ * 隐藏
87
+ * @param popsType
88
+ * @param instConfigList
89
+ * @param guid
90
+ * @param config
91
+ * @param $anim
92
+ * @param $mask
93
+ */
94
+ hide(
95
+ config:
96
+ | PopsAlertConfig
97
+ | PopsDrawerConfig
98
+ | PopsPromptConfig
99
+ | PopsConfirmConfig
100
+ | PopsIframeConfig
101
+ | PopsLoadingConfig
102
+ | PopsPanelConfig
103
+ | PopsFolderConfig,
104
+ popsType: PopsInstStoreType,
105
+ instConfigList: PopsInstGeneralConfig[],
106
+ guid: string,
107
+ $anim: HTMLElement,
108
+ $mask?: HTMLElement
109
+ ) {
110
+ // oxlint-disable-next-line no-async-promise-executor
111
+ return new Promise<void>(async (resolve) => {
112
+ const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
113
+ const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
114
+ if (fintInst) {
115
+ // 存在实例
116
+ const startAnim = async () => {
117
+ if (popsType === "drawer") {
118
+ // drawer是抽屉
119
+ // 单独处理动画
120
+ const drawerConfig = config as Required<PopsDrawerConfig>;
121
+ await popsUtils.sleep(drawerConfig.closeDelay ?? 0);
122
+ if ($mask) {
123
+ popsDOMUtils.css($mask, "display", "none");
124
+ }
125
+ const direction = drawerConfig.direction!;
126
+ const size = "0";
127
+ if (["top", "bottom"].includes(direction)) {
128
+ $pops.style.setProperty("height", size);
129
+ } else if (["left", "right"].includes(direction)) {
130
+ $pops.style.setProperty("width", size);
131
+ } else {
132
+ console.error("未知direction: ", direction);
133
+ }
134
+ } else {
135
+ instConfigItem.$anim.style.width = "100%";
136
+ instConfigItem.$anim.style.height = "100%";
137
+ Reflect.set(
138
+ instConfigItem.$anim.style,
139
+ "animation-name",
140
+ instConfigItem.$anim.getAttribute("anim") + "-reverse"
141
+ );
142
+ }
143
+ };
144
+ const endCallback = () => {
145
+ instConfigItem.$anim.style.display = "none";
146
+ if (instConfigItem.$mask) {
147
+ instConfigItem.$mask.style.display = "none";
148
+ }
149
+ fintInst.emitter.emit("pops:hide", instConfigItem);
150
+ };
151
+ const instConfigItem = fintInst;
152
+ fintInst.emitter.emit("pops:before-hide", instConfigItem);
153
+ await startAnim();
154
+ if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.$anim.style, "animation-name"))) {
155
+ /**
156
+ * 动画结束的回调
157
+ */
158
+ const animationendCallBack = () => {
159
+ listener.off();
160
+ endCallback();
161
+ resolve();
162
+ };
163
+ const listener = popsDOMUtils.on(
164
+ instConfigItem.$anim,
165
+ popsDOMUtils.getAnimationEndNameList(),
166
+ animationendCallBack,
167
+ {
168
+ capture: true,
169
+ once: true,
170
+ }
171
+ );
172
+ } else {
173
+ endCallback();
174
+ resolve();
175
+ }
176
+ } else {
177
+ console.error("hide-error: 该实例未存储");
178
+ resolve();
179
+ }
180
+ });
181
+ },
182
+ /**
183
+ * 显示
184
+ * @param popsType
185
+ * @param instConfigList
186
+ * @param guid
187
+ * @param config
188
+ * @param $anim
189
+ * @param $mask
190
+ */
191
+ show(
192
+ config:
193
+ | PopsAlertConfig
194
+ | PopsDrawerConfig
195
+ | PopsPromptConfig
196
+ | PopsConfirmConfig
197
+ | PopsIframeConfig
198
+ | PopsLoadingConfig
199
+ | PopsPanelConfig
200
+ | PopsFolderConfig,
201
+ popsType: PopsInstStoreType,
202
+ instConfigList: PopsInstGeneralConfig[],
203
+ guid: string,
204
+ $anim: HTMLElement,
205
+ $mask?: HTMLElement
206
+ ) {
207
+ // oxlint-disable-next-line no-async-promise-executor
208
+ return new Promise<void>(async (resolve) => {
209
+ const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
210
+
211
+ const fintInst = instConfigList.find((instConfigItem) => instConfigItem.guid === guid);
212
+ if (fintInst) {
213
+ const startAnim = async () => {
214
+ if (popsType === "drawer") {
215
+ // drawer是抽屉
216
+ // 单独处理动画
217
+ const drawerConfig = config as Required<PopsDrawerConfig>;
218
+ await popsUtils.sleep(drawerConfig.openDelay ?? 0);
219
+ if ($mask) {
220
+ popsDOMUtils.css($mask, "display", "");
221
+ }
222
+ const direction = drawerConfig.direction!;
223
+ const size = drawerConfig.size!.toString();
224
+ if (["top", "bottom"].includes(direction)) {
225
+ $pops.style.setProperty("height", size);
226
+ } else if (["left", "right"].includes(direction)) {
227
+ $pops.style.setProperty("width", size);
228
+ } else {
229
+ console.error("未知direction:", direction);
230
+ }
231
+ } else {
232
+ instConfigItem.$anim.style.width = "";
233
+ instConfigItem.$anim.style.height = "";
234
+ Reflect.set(
235
+ instConfigItem.$anim.style,
236
+ "animation-name",
237
+ instConfigItem.$anim!.getAttribute("anim")!.replace("-reverse", "")
238
+ );
239
+ }
240
+ };
241
+ const endCallback = () => {
242
+ instConfigItem.$anim.style.display = "";
243
+ if (instConfigItem.$mask) {
244
+ instConfigItem.$mask.style.display = "";
245
+ }
246
+ fintInst.emitter.emit("pops:show", instConfigItem);
247
+ };
248
+ const instConfigItem = fintInst;
249
+ fintInst.emitter.emit("pops:before-show", instConfigItem);
250
+ await startAnim();
251
+ if (PopsAnimation.hasAnim(Reflect.get(instConfigItem.$anim.style, "animation-name"))) {
252
+ /**
253
+ * 动画结束的回调
254
+ */
255
+ const animationendCallBack = () => {
256
+ listener.off();
257
+ endCallback();
258
+ resolve();
259
+ };
260
+ const listener = popsDOMUtils.on(
261
+ instConfigItem.$anim,
262
+ popsDOMUtils.getAnimationEndNameList(),
263
+ animationendCallBack,
264
+ {
265
+ capture: true,
266
+ }
267
+ );
268
+ } else {
269
+ endCallback();
270
+ resolve();
271
+ }
272
+ } else {
273
+ console.error("show-error: 该实例未存储");
274
+ resolve();
275
+ }
276
+ });
277
+ },
278
+ /**
279
+ * 关闭
280
+ * @param popsType
281
+ * @param instConfigList
282
+ * @param guid
283
+ * @param config
284
+ * @param $anim
285
+ */
286
+ async close(
287
+ config:
288
+ | PopsAlertConfig
289
+ | PopsDrawerConfig
290
+ | PopsPromptConfig
291
+ | PopsConfirmConfig
292
+ | PopsIframeConfig
293
+ | PopsLoadingConfig
294
+ | PopsPanelConfig
295
+ | PopsFolderConfig,
296
+ popsType: string,
297
+ instConfigList: PopsInstGeneralConfig[],
298
+ guid: string,
299
+ $anim: HTMLElement
300
+ ) {
301
+ // 判断组件内部是否有rightClickMenu、tooltip、searchSuggestion组件
302
+ // 有的话也需要关闭
303
+ PopsInstData.rightClickMenu.forEach((itemConfig) => {
304
+ const config = itemConfig.config as PopsRightClickMenuConfig;
305
+ if (config.$target instanceof HTMLElement) {
306
+ const $root = config.$target.getRootNode();
307
+ if ($root instanceof HTMLElement && $root.parentElement == null) {
308
+ // 触发销毁元素
309
+ itemConfig.emitter.emit("pops:before-destory", itemConfig);
310
+ }
311
+ }
312
+ });
313
+ PopsInstData.tooltip.forEach((itemConfig) => {
314
+ const config = itemConfig.config as PopsToolTipConfig;
315
+ if (config.$target instanceof HTMLElement) {
316
+ const $root = config.$target.getRootNode();
317
+ if ($root instanceof HTMLElement && $root.parentElement == null) {
318
+ // 触发销毁元素
319
+ itemConfig.emitter.emit("pops:before-destory", itemConfig);
320
+ }
321
+ }
322
+ });
323
+ // eslint-disable-next-line no-async-promise-executor
324
+ await new Promise<void>(async (resolve) => {
325
+ const $pops = $anim.querySelector<HTMLDivElement>(".pops[type-value]")!;
326
+ const drawerConfig = config as Required<PopsDrawerConfig>;
327
+ const start = () => {
328
+ /**
329
+ * 弹窗已关闭的回调
330
+ */
331
+ const transtionEndCallback = async (event: Event) => {
332
+ if ((event as TransitionEvent).propertyName !== "transform") {
333
+ return;
334
+ }
335
+ listener.off();
336
+ await PopsInstHandler.removeInstance([instConfigList], guid);
337
+ resolve();
338
+ };
339
+ // 监听过渡结束
340
+ const listener = popsDOMUtils.on($pops, popsDOMUtils.getTransitionEndNameList(), transtionEndCallback, {
341
+ once: true,
342
+ });
343
+ const popsTransForm = globalThis.getComputedStyle($pops).transform;
344
+ if (popsTransForm !== "none") {
345
+ // 不存在动画
346
+ // 直接移除实例
347
+ listener.emit({ propertyName: "transform" });
348
+ return;
349
+ }
350
+ if (["top"].includes(drawerConfig.direction)) {
351
+ $pops.style.setProperty("transform", "translateY(-100%)");
352
+ } else if (["bottom"].includes(drawerConfig.direction)) {
353
+ $pops.style.setProperty("transform", "translateY(100%)");
354
+ } else if (["left"].includes(drawerConfig.direction)) {
355
+ $pops.style.setProperty("transform", "translateX(-100%)");
356
+ } else if (["right"].includes(drawerConfig.direction)) {
357
+ $pops.style.setProperty("transform", "translateX(100%)");
358
+ } else {
359
+ console.error("未知direction: ", drawerConfig.direction);
360
+ }
361
+ };
362
+ if (popsType === "drawer") {
363
+ await popsUtils.sleep(drawerConfig.closeDelay ?? 0);
364
+ start();
365
+ } else {
366
+ await PopsInstHandler.removeInstance([instConfigList], guid);
367
+ resolve();
368
+ }
369
+ });
370
+ },
371
+ /**
372
+ * 拖拽元素
373
+ * 说明:
374
+ * + 元素的position为absolute或者fixed
375
+ * + 会为元素的
376
+ * @param $move 需要拖拽的元素
377
+ * @param options 配置
378
+ */
379
+ drag(
380
+ $move: HTMLElement,
381
+ options: {
382
+ dragElement: HTMLElement;
383
+ limit: boolean;
384
+ emitClick?: boolean;
385
+ extraDistance: number;
386
+ container?: Window | typeof globalThis | HTMLElement;
387
+ startCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
388
+ moveCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
389
+ endCallBack?: (moveElement: HTMLElement, left: number, top: number) => void;
390
+ preventEvent?: (event: TouchEvent | PointerEvent) => boolean;
391
+ }
392
+ ) {
393
+ options = Object.assign(
394
+ {
395
+ limit: true,
396
+ extraDistance: 3,
397
+ container: PopsCore.globalThis,
398
+ emitClick: true,
399
+ },
400
+ options
401
+ );
402
+ let isMove = false;
403
+ // 点击元素,left偏移
404
+ let clickElementLeftOffset = 0;
405
+ // 点击元素,top偏移
406
+ let clickElementTopOffset = 0;
407
+ const AnyTouch = popsUtils.AnyTouch();
408
+ const anyTouchElement = new AnyTouch(options.dragElement, {
409
+ preventDefault(event: Event) {
410
+ if (typeof options.preventEvent === "function") {
411
+ return options.preventEvent(event as any);
412
+ } else {
413
+ // 返回true阻止滑动
414
+ return true;
415
+ }
416
+ },
417
+ });
418
+ popsDOMUtils.css(options.dragElement, {
419
+ cursor: "move",
420
+ });
421
+ /**
422
+ * 修改移动的元素的style
423
+ */
424
+ function changeMoveElementStyle(element: HTMLElement) {
425
+ const old_transitionDuration = element.style.transitionDuration;
426
+ if (globalThis.getComputedStyle(element).transitionDuration !== "0s") {
427
+ element.style.transitionDuration = "0s";
428
+ }
429
+ return () => {
430
+ element.style.transitionDuration = old_transitionDuration;
431
+ };
432
+ }
433
+ /**
434
+ * 获取容器的高度、宽度,一般是window为容器
435
+ */
436
+ function getContainerWidthOrHeight(container: HTMLElement | Window | typeof globalThis) {
437
+ container = container ?? globalThis;
438
+ return {
439
+ width: popsDOMUtils.width(container),
440
+ height: popsDOMUtils.height(container),
441
+ };
442
+ }
443
+ /**
444
+ * 获取容器的最小left、top偏移
445
+ */
446
+
447
+ function getContainerTopOrLeft(container: HTMLElement | Window | typeof globalThis) {
448
+ container = container ?? globalThis;
449
+ if (popsUtils.isWin(container)) {
450
+ return {
451
+ left: 0,
452
+ top: 0,
453
+ };
454
+ } else {
455
+ const rect = (container as HTMLElement).getBoundingClientRect();
456
+ return {
457
+ left: rect.left,
458
+ top: rect.top,
459
+ };
460
+ }
461
+ }
462
+ // 获取transform偏移
463
+ let transformInfo = popsDOMUtils.getTransform($move);
464
+
465
+ let resumeMoveElementStyle: ((...args: any[]) => any) | null = null;
466
+
467
+ anyTouchElement.on("pan", function (event) {
468
+ if (!isMove) {
469
+ isMove = true;
470
+ const rect = options.dragElement.getBoundingClientRect();
471
+ clickElementLeftOffset = event.x - rect.left;
472
+ clickElementTopOffset = event.y - rect.top;
473
+ transformInfo = popsDOMUtils.getTransform($move);
474
+ resumeMoveElementStyle = changeMoveElementStyle($move);
475
+ if (typeof options.startCallBack === "function") {
476
+ options.startCallBack($move, clickElementLeftOffset, clickElementTopOffset);
477
+ }
478
+ }
479
+
480
+ /** 当前移动的left偏移 */
481
+ let currentMoveLeftOffset = event.x - clickElementLeftOffset + transformInfo.transformLeft;
482
+ /** 当前移动的top偏移 */
483
+ let currentMoveTopOffset = event.y - clickElementTopOffset + transformInfo.transformTop;
484
+ // 拖拽移动
485
+ if (event.phase === "move") {
486
+ if (options.limit) {
487
+ // 限制在容器内移动
488
+ // left偏移最大值
489
+ const maxLeftOffset =
490
+ getContainerWidthOrHeight(options.container!).width -
491
+ popsDOMUtils.width($move) +
492
+ transformInfo.transformLeft;
493
+ const { left: minLeftOffset, top: minTopOffset } = getContainerTopOrLeft(options.container!);
494
+ // top偏移的最大值
495
+ const maxTopOffset =
496
+ getContainerWidthOrHeight(options.container!).height -
497
+ popsDOMUtils.height($move) +
498
+ transformInfo.transformTop;
499
+ if (currentMoveLeftOffset > maxLeftOffset) {
500
+ // 不允许超过容器的最大宽度
501
+ currentMoveLeftOffset = maxLeftOffset;
502
+ }
503
+ if (currentMoveTopOffset > maxTopOffset) {
504
+ // 不允许超过容器的最大高度
505
+ currentMoveTopOffset = maxTopOffset;
506
+ }
507
+ if (currentMoveLeftOffset - options.extraDistance * 2 < minLeftOffset + transformInfo.transformLeft) {
508
+ // 不允许left偏移小于容器最小值
509
+ currentMoveLeftOffset = minLeftOffset + transformInfo.transformLeft;
510
+ // 最左边 +额外距离
511
+ currentMoveLeftOffset += options.extraDistance;
512
+ } else {
513
+ // 最右边 -额外距离
514
+ currentMoveLeftOffset -= options.extraDistance;
515
+ }
516
+ if (currentMoveTopOffset - options.extraDistance * 2 < minTopOffset + transformInfo.transformTop) {
517
+ // 不允许top偏移小于容器最小值
518
+ currentMoveTopOffset = minTopOffset + transformInfo.transformTop;
519
+ // 最上面 +额外距离
520
+ currentMoveTopOffset += options.extraDistance;
521
+ } else {
522
+ // 最下面 -额外距离
523
+ currentMoveTopOffset -= options.extraDistance;
524
+ }
525
+ }
526
+ if (typeof options.moveCallBack === "function") {
527
+ options.moveCallBack($move, currentMoveLeftOffset, currentMoveTopOffset);
528
+ }
529
+
530
+ popsDOMUtils.css($move, {
531
+ left: currentMoveLeftOffset + "px",
532
+ top: currentMoveTopOffset + "px",
533
+ });
534
+ }
535
+
536
+ // 停止拖拽
537
+ if (event.phase === "end") {
538
+ isMove = false;
539
+ if (typeof resumeMoveElementStyle === "function") {
540
+ resumeMoveElementStyle();
541
+ resumeMoveElementStyle = null;
542
+ }
543
+ if (typeof options.endCallBack === "function") {
544
+ options.endCallBack($move, currentMoveLeftOffset, currentMoveTopOffset);
545
+ }
546
+ }
547
+ });
548
+ if (options.emitClick) {
549
+ // 因为会覆盖上面的点击事件,主动触发一下
550
+ anyTouchElement.on(["tap"], function (event) {
551
+ event.changedPoints.forEach((item) => {
552
+ popsDOMUtils.emit(item.target! as HTMLElement, "click", void 0, true);
553
+ });
554
+ });
555
+ }
556
+ },
557
+ };
@@ -0,0 +1,18 @@
1
+ import type { PopsInstGeneralConfig } from "./inst";
2
+
3
+ export type EventMap = {
4
+ "pops:before-show": (config: PopsInstGeneralConfig) => IPromise<void>;
5
+ "pops:show": (config: PopsInstGeneralConfig) => IPromise<void>;
6
+ "pops:before-hide": (config: PopsInstGeneralConfig) => IPromise<void>;
7
+ "pops:hide": (config: PopsInstGeneralConfig) => IPromise<void>;
8
+ "pops:before-destory": (config: PopsInstGeneralConfig) => IPromise<void>;
9
+ "pops:destory": () => IPromise<void>;
10
+ "pops:before-append-to-page": (
11
+ $shadowRoot: ShadowRoot | HTMLElement,
12
+ $shadowContainer: HTMLDivElement
13
+ ) => IPromise<void>;
14
+ };
15
+
16
+ export type CustomEventMap = {
17
+ [K in string]: (...args: any[]) => IPromise<void>;
18
+ };
@@ -34,6 +34,10 @@ export type PopsDOMUtils_MouseEventType = keyof PopsDOMUtils_MouseEvent;
34
34
  */
35
35
  export interface PopsDOMUtils_KeyboardEvent {
36
36
  keydown: KeyboardEvent;
37
+ /**
38
+ * @link https://developer.mozilla.org/zh-CN/docs/Web/API/Element/keypress_event
39
+ * @deprecated
40
+ */
37
41
  keypress: KeyboardEvent;
38
42
  keyup: KeyboardEvent;
39
43
  }
@@ -1,3 +1,4 @@
1
+ import type { EventEmiter } from "../event/EventEmiter";
1
2
  import type { PopsEventConfig, PopsHandlerEventConfig } from "./event";
2
3
  import type { PopsIconType } from "./icon";
3
4
 
@@ -63,7 +64,7 @@ export interface PopsGlobalButtonConfig<T = object> {
63
64
  *
64
65
  * 如果传入该值,那么将不会自动关闭弹窗
65
66
  */
66
- callback(eventConfig: PopsHandlerEventConfig & T, event: PointerEvent | MouseEvent): void;
67
+ callback(eventConfig: PopsHandlerEventConfig<EventEmiter> & T, event: PointerEvent | MouseEvent): void;
67
68
  }
68
69
 
69
70
  /**
@@ -1,9 +1,11 @@
1
+ import type { EventEmiter } from "../event/EventEmiter";
2
+ import type { CustomEventMap } from "./EventEmitter";
1
3
  import type { PopsType } from "./main";
2
4
 
3
5
  /**
4
6
  * 事件配置
5
7
  */
6
- export interface PopsEventConfig {
8
+ export interface PopsEventConfig<E extends EventEmiter<CustomEventMap> = EventEmiter<CustomEventMap>> {
7
9
  /** 最外层包裹的元素 */
8
10
  $shadowContainer: HTMLDivElement;
9
11
  /** ShadowRoot */
@@ -20,6 +22,8 @@ export interface PopsEventConfig {
20
22
  mode: PopsType;
21
23
  /** 唯一id */
22
24
  guid: string;
25
+ /** 事件发送器 */
26
+ emitter: E;
23
27
  /**
24
28
  * 关闭弹窗
25
29
  */
@@ -37,7 +41,7 @@ export interface PopsEventConfig {
37
41
  /**
38
42
  * 处理过的事件配置
39
43
  */
40
- export interface PopsHandlerEventConfig extends PopsEventConfig {
44
+ export interface PopsHandlerEventConfig<E extends EventEmiter<CustomEventMap>> extends PopsEventConfig<E> {
41
45
  /** 当前按钮类型 */
42
46
  type: "cancel" | "close" | "ok" | "other";
43
47
  }
@@ -1,3 +1,5 @@
1
+ import type { EventEmiter } from "../event/EventEmiter";
2
+
1
3
  /**
2
4
  * config实例配置
3
5
  */
@@ -19,10 +21,8 @@ export interface PopsInstGeneralConfig extends PopsInstConfig {
19
21
  $shadowContainer: HTMLDivElement;
20
22
  /** shadow容器的shandowRoot */
21
23
  $shadowRoot: ShadowRoot | HTMLElement;
22
- /** 移除实例前的回调函数 */
23
- beforeRemoveCallBack?: (instCommonConfig: PopsInstGeneralConfig) => void;
24
24
  /** 配置 */
25
25
  config: any;
26
- /** 销毁元素 */
27
- destory(): void | Promise<void>;
26
+ /** 事件发送器 */
27
+ emitter: EventEmiter;
28
28
  }