@whitesev/pops 1.5.6 → 1.5.9

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.
@@ -255,13 +255,24 @@ export class PopsRightClickMenu {
255
255
  if (config.preventDefault) {
256
256
  popsDOMUtils.preventEvent(event);
257
257
  }
258
+ PopsHandler.handleOnly(PopsType, config);
258
259
  if (PopsContextMenu.rootElement) {
259
260
  PopsContextMenu.closeAllMenu(PopsContextMenu.rootElement);
260
261
  }
261
- PopsContextMenu.rootElement = PopsContextMenu.showMenu(
262
- event,
263
- config.data
264
- );
262
+ let rootElement = PopsContextMenu.showMenu(event, config.data);
263
+ PopsContextMenu.rootElement = rootElement;
264
+ if (config.only) {
265
+ PopsHandler.handlePush(PopsType, {
266
+ $shadowRoot: $shadowRoot,
267
+ $shadowContainer: $shadowContainer,
268
+ guid: guid,
269
+ animElement: rootElement as HTMLDivElement,
270
+ popsElement: rootElement as HTMLDivElement,
271
+ beforeRemoveCallBack(layerCommonConfig) {
272
+ PopsContextMenu.closeAllMenu(layerCommonConfig.popsElement);
273
+ },
274
+ });
275
+ }
265
276
  },
266
277
  /**
267
278
  * 添加contextmenu事件
@@ -337,6 +348,9 @@ export class PopsRightClickMenu {
337
348
  * @param rootElement
338
349
  */
339
350
  closeAllMenu(rootElement: HTMLElement) {
351
+ if (rootElement == null) {
352
+ return;
353
+ }
340
354
  if ((rootElement as any)?.["__menuData__"]?.root) {
341
355
  rootElement = (rootElement as any)?.["__menuData__"]?.root;
342
356
  }
@@ -725,7 +739,9 @@ export class PopsRightClickMenu {
725
739
  },
726
740
  };
727
741
 
742
+ // 添加右键菜单事件
728
743
  PopsContextMenu.addContextMenuEvent(config.target, config.targetSelector!);
744
+ // 添加全局点击检测
729
745
  PopsContextMenu.addWindowCheckClickListener();
730
746
 
731
747
  return {
@@ -631,11 +631,10 @@ export const PopsHandler = {
631
631
  type === "tooltip" ||
632
632
  type === "rightClickMenu"
633
633
  ) {
634
- PopsInstanceUtils.removeInstance(
635
- [(pops.config.layer as any)[type]],
636
- "",
637
- true
638
- );
634
+ let layer = pops.config.layer[type as keyof typeof pops.config.layer];
635
+ if (layer) {
636
+ PopsInstanceUtils.removeInstance([layer], "", true);
637
+ }
639
638
  } else {
640
639
  PopsInstanceUtils.removeInstance(
641
640
  [
@@ -662,7 +661,7 @@ export const PopsHandler = {
662
661
  );
663
662
  return maxZIndex;
664
663
  };
665
- }else{
664
+ } else {
666
665
  const { zIndex: maxZIndex } = PopsInstanceUtils.getPopsMaxZIndex(
667
666
  PopsHandler.handleZIndex(config.zIndex) + 100
668
667
  );
@@ -17,4 +17,6 @@ export interface PopsLayerCommonConfig extends PopsLayerConfig {
17
17
  $shadowContainer: HTMLDivElement;
18
18
  /** shadow容器的shandowRoot */
19
19
  $shadowRoot: ShadowRoot;
20
+ /** 移除实例前的回调函数 */
21
+ beforeRemoveCallBack?: (layerCommonConfig: PopsLayerCommonConfig) => void;
20
22
  }
@@ -48,7 +48,7 @@ export type PopsType = keyof PopsTypeDetails;
48
48
  export type PopsMode = PopsType | "tooltip" | "rightClickMenu";
49
49
 
50
50
  /** 存储实例的类型 9个 */
51
- export type PopsLayerMode = PopsType | "tooltip";
51
+ export type PopsLayerMode = PopsType | "tooltip" | "rightClickMenu";
52
52
 
53
53
  /** pops弹窗支持动画元素的配置 */
54
54
  export interface PopsSupportAnim {
@@ -25,7 +25,7 @@ export interface PopsMaskDetails {
25
25
  * @param config 配置信息
26
26
  */
27
27
  clickCallBack?: (
28
- originalRun: (originalRun: Function) => void,
28
+ originalRun: () => void,
29
29
  config:
30
30
  | PopsAlertDetails
31
31
  | PopsDrawerDetails
@@ -84,17 +84,27 @@ export const PopsInstanceUtils = {
84
84
  guid: string,
85
85
  isAll = false
86
86
  ) {
87
- function removeItem(item: PopsLayerCommonConfig) {
88
- item?.animElement?.remove();
89
- item?.popsElement?.remove();
90
- item?.maskElement?.remove();
91
- item?.$shadowContainer?.remove();
87
+ /**
88
+ * 移除元素实例
89
+ * @param layerCommonConfig
90
+ */
91
+ function removeItem(layerCommonConfig: PopsLayerCommonConfig) {
92
+ if (typeof layerCommonConfig.beforeRemoveCallBack === "function") {
93
+ // 调用移除签的回调
94
+ layerCommonConfig.beforeRemoveCallBack(layerCommonConfig);
95
+ }
96
+ layerCommonConfig?.animElement?.remove();
97
+ layerCommonConfig?.popsElement?.remove();
98
+ layerCommonConfig?.maskElement?.remove();
99
+ layerCommonConfig?.$shadowContainer?.remove();
92
100
  }
93
101
  // [ layer[], layer[],...]
94
102
  moreLayerConfigList.forEach((layerConfigList) => {
95
103
  // layer[]
96
104
  layerConfigList.forEach((layerConfigItem, index) => {
105
+ // 移除全部或者guid相同
97
106
  if (isAll || layerConfigItem["guid"] === guid) {
107
+ // 判断是否有动画
98
108
  if (
99
109
  pops.config.animation.hasOwnProperty(
100
110
  layerConfigItem.animElement.getAttribute("anim") as string