@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
package/src/css/index.css CHANGED
@@ -215,6 +215,8 @@ button.pops-header-control i:hover {
215
215
  .pops .pops-title p[pops] {
216
216
  color: var(--pops-title-color);
217
217
  width: 100%;
218
+ height: 100%;
219
+ align-content: center;
218
220
  overflow: hidden;
219
221
  text-indent: 15px;
220
222
  text-overflow: ellipsis;
@@ -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="pops ${
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
  /**
@@ -326,7 +328,7 @@ export const PopsElementHandler = {
326
328
  addLightStyle($parent: HTMLElement | ShadowRoot, style?: string | null) {
327
329
  const darkCSS = /*css*/ `
328
330
  @media (prefers-color-scheme: light) {
329
- ${style}
331
+ ${style ?? ""}
330
332
  }
331
333
  `;
332
334
  const $css = this.addStyle($parent, darkCSS);
@@ -342,7 +344,7 @@ export const PopsElementHandler = {
342
344
  addDarkStyle($parent: HTMLElement | ShadowRoot, style?: string | null) {
343
345
  const darkCSS = /*css*/ `
344
346
  @media (prefers-color-scheme: dark) {
345
- ${style}
347
+ ${style ?? ""}
346
348
  }
347
349
  `;
348
350
  const $css = this.addStyle($parent, darkCSS);
@@ -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 { PopsCore } from "../PopsCore";
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, PopsType, PopsSupportAnimConfigType, PopsSupportOnlyConfig } from "../types/main";
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 PopsInstanceUtils.close(config.config, config.type, targetInst, config.guid, config.animElement);
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 PopsInstanceUtils.hide(
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 PopsInstanceUtils.close(config, type, PopsInstData[type], guid, $anim);
408
+ return PopsInstHandler.close(config, type, PopsInstData[type], guid, $anim);
405
409
  },
406
410
  hide() {
407
- return PopsInstanceUtils.hide(config, type, PopsInstData[type], guid, $anim, $mask);
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 PopsInstanceUtils.show(config, type, PopsInstData[type], guid, $anim, $mask);
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, "$shadowContainer" | "$shadowRoot"> {
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 PopsInstanceUtils.close(config, type, PopsInstData[type], guid, $anim);
456
+ return PopsInstHandler.close(config, type, PopsInstData[type], guid, $anim);
451
457
  },
452
458
  hide() {
453
- return PopsInstanceUtils.hide(config, type, PopsInstData[type], guid, $anim, $mask);
459
+ return PopsInstHandler.hide(config, type, PopsInstData[type], guid, $anim, $mask);
454
460
  },
455
461
  show() {
456
- return PopsInstanceUtils.show(config, type, PopsInstData[type], guid, $anim, $mask);
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, event: PointerEvent | MouseEvent) => void
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
- * 把配置的z-index配置转为数字
576
- * @param zIndex
575
+ * 获取数值
576
+ * @param target
577
577
  */
578
- handleZIndex(zIndex: number | (() => number)): number {
579
- if (typeof zIndex === "function") {
580
- return zIndex();
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 zIndex;
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
- PopsInstanceUtils.removeInstance([inst], "", true);
600
+ PopsInstHandler.removeInstance([inst], "", true);
600
601
  }
601
602
  } else {
602
- PopsInstanceUtils.removeInstance(
603
+ PopsInstHandler.removeInstance(
603
604
  [
604
605
  PopsInstData.alert,
605
606
  PopsInstData.confirm,
@@ -613,15 +614,31 @@ 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
+ if (type !== "rightClickMenu") {
619
+ // rightClickMenu在配置处理时就处理了一次,这里不需要重复处理
620
+ config = this.handleZIndex(config);
621
+ }
622
+
623
+ return config;
624
+ },
625
+ /**
626
+ * 处理z-index
627
+ * @param config 配置
628
+ */
629
+ handleZIndex<T extends Required<PopsSupportOnlyConfig[keyof PopsSupportOnlyConfig]>>(config: T): T {
630
+ // 对配置进行处理
631
+ // 选择配置的z-index和已有的pops实例的最大z-index值
632
+ const originZIndex = config.zIndex;
633
+ const handler = () => {
634
+ let deviation = 100;
635
+ deviation += PopsHandler.getTargerOrFunctionValue(originZIndex) ?? 0;
636
+ let maxZIndex = deviation;
637
+ const pointZIndex = popsUtils.getMaxZIndexNodeInfoFromPoint(deviation)[0]?.zIndex ?? 0;
638
+ maxZIndex = Math.max(maxZIndex, pointZIndex);
639
+ return maxZIndex === deviation ? maxZIndex : maxZIndex + deviation;
640
+ };
641
+ config.zIndex = handler;
625
642
  return config;
626
643
  },
627
644
  /**