@whitesev/pops 2.5.4 → 2.6.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.
Files changed (59) hide show
  1. package/dist/index.amd.js +195 -161
  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 +195 -161
  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 +195 -161
  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 +195 -161
  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 +195 -161
  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 +195 -161
  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 +60 -20968
  26. package/dist/types/src/components/alert/index.d.ts +1 -1
  27. package/dist/types/src/components/confirm/index.d.ts +1 -1
  28. package/dist/types/src/components/drawer/index.d.ts +1 -1
  29. package/dist/types/src/components/folder/index.d.ts +1 -1
  30. package/dist/types/src/components/iframe/index.d.ts +2 -2
  31. package/dist/types/src/components/iframe/types/index.d.ts +6 -6
  32. package/dist/types/src/components/loading/index.d.ts +1 -1
  33. package/dist/types/src/components/panel/index.d.ts +4 -4
  34. package/dist/types/src/components/prompt/index.d.ts +1 -1
  35. package/dist/types/src/components/rightClickMenu/index.d.ts +134 -20954
  36. package/dist/types/src/components/rightClickMenu/types/index.d.ts +17 -1
  37. package/dist/types/src/handler/PopsHandler.d.ts +18 -17
  38. package/dist/types/src/types/button.d.ts +4 -4
  39. package/dist/types/src/types/event.d.ts +7 -7
  40. package/dist/types/src/utils/PopsInstanceUtils.d.ts +8 -8
  41. package/package.json +12 -12
  42. package/src/components/alert/index.ts +13 -13
  43. package/src/components/confirm/index.ts +15 -16
  44. package/src/components/drawer/index.ts +22 -22
  45. package/src/components/folder/index.ts +14 -14
  46. package/src/components/iframe/index.ts +19 -20
  47. package/src/components/iframe/types/index.ts +6 -6
  48. package/src/components/loading/index.ts +8 -8
  49. package/src/components/panel/index.css +12 -1
  50. package/src/components/panel/index.ts +11 -11
  51. package/src/components/prompt/index.ts +28 -29
  52. package/src/components/rightClickMenu/config.ts +3 -0
  53. package/src/components/rightClickMenu/index.css +3 -0
  54. package/src/components/rightClickMenu/index.ts +51 -19
  55. package/src/components/rightClickMenu/types/index.ts +17 -1
  56. package/src/handler/PopsHandler.ts +70 -68
  57. package/src/types/button.d.ts +4 -4
  58. package/src/types/event.d.ts +7 -7
  59. package/src/utils/PopsInstanceUtils.ts +28 -24
@@ -4,7 +4,7 @@ import { PopsElementHandler } from "../../handler/PopsElementHandler";
4
4
  import { PopsHandler } from "../../handler/PopsHandler";
5
5
  import { PopsCSS } from "../../PopsCSS";
6
6
  import { PopsInstData } from "../../PopsInst";
7
- import type { PopsEventDetails } from "../../types/event";
7
+ import type { PopsEventConfig } from "../../types/event";
8
8
  import { popsDOMUtils } from "../../utils/PopsDOMUtils";
9
9
  import { PopsInstanceUtils } from "../../utils/PopsInstanceUtils";
10
10
  import { popsUtils } from "../../utils/PopsUtils";
@@ -115,14 +115,14 @@ export const PopsIframe = {
115
115
  /**
116
116
  * 遮罩层元素
117
117
  */
118
- let $mask: HTMLDivElement | null = null;
118
+ let $mask: HTMLDivElement | undefined = void 0;
119
119
  /**
120
120
  * 已创建的元素列表
121
121
  */
122
- const elementList: HTMLElement[] = [$anim];
122
+ const $elList: HTMLElement[] = [$anim];
123
123
 
124
124
  if (config.mask.enable) {
125
- const _handleMask_ = PopsHandler.handleMask({
125
+ const handleMask = PopsHandler.handleMask({
126
126
  type: popsType,
127
127
  guid: guid,
128
128
 
@@ -130,25 +130,24 @@ export const PopsIframe = {
130
130
  animElement: $anim,
131
131
  maskHTML: maskHTML,
132
132
  });
133
- $mask = _handleMask_.maskElement;
134
- elementList.push($mask);
133
+ $mask = handleMask.maskElement;
134
+ $elList.push($mask);
135
135
  }
136
136
 
137
- const eventDetails = PopsHandler.handleEventDetails(
137
+ const evtConfig = PopsHandler.handleEventConfig(
138
+ config,
138
139
  guid,
139
140
  $shadowContainer,
140
141
  $shadowRoot,
141
142
  popsType,
142
143
  $anim,
143
-
144
- $pops!,
145
- $mask!,
146
- config
147
- ) as any as PopsEventDetails & {
144
+ $pops,
145
+ $mask
146
+ ) as any as PopsEventConfig & {
148
147
  iframeElement: HTMLIFrameElement;
149
148
  };
150
149
 
151
- eventDetails["iframeElement"] = $iframe!;
150
+ evtConfig["iframeElement"] = $iframe!;
152
151
 
153
152
  popsDOMUtils.on($anim, popsDOMUtils.getAnimationEndNameList(), function () {
154
153
  /* 动画加载完毕 */
@@ -170,11 +169,11 @@ export const PopsIframe = {
170
169
  $title!.querySelector<HTMLElement>("p")!.innerText = $iframe!.contentDocument.title;
171
170
  }
172
171
 
173
- config.loadEndCallBack(eventDetails);
172
+ config.loadEndCallBack(evtConfig);
174
173
  });
175
174
  /* 创建到页面中 */
176
175
 
177
- popsDOMUtils.append($shadowRoot, elementList);
176
+ popsDOMUtils.append($shadowRoot, $elList);
178
177
  if (typeof config.beforeAppendToPageCallBack === "function") {
179
178
  config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
180
179
  }
@@ -218,7 +217,7 @@ export const PopsIframe = {
218
217
  // 显示复位图标
219
218
  headerMiseBtnElement.style.setProperty("display", "");
220
219
  if (typeof config?.btn?.min?.callback === "function") {
221
- config.btn.min.callback(eventDetails, event);
220
+ config.btn.min.callback(evtConfig, event);
222
221
  }
223
222
  },
224
223
  {
@@ -252,7 +251,7 @@ export const PopsIframe = {
252
251
  // 显示复位图标
253
252
  headerMiseBtnElement.style.setProperty("display", "");
254
253
  if (typeof config?.btn?.max?.callback === "function") {
255
- config.btn.max.callback(eventDetails, event);
254
+ config.btn.max.callback(evtConfig, event);
256
255
  }
257
256
  },
258
257
  {
@@ -294,7 +293,7 @@ export const PopsIframe = {
294
293
  headerMiseBtnElement.style.setProperty("display", "none");
295
294
  }
296
295
  if (typeof config?.btn?.mise?.callback === "function") {
297
- config.btn.mise.callback(eventDetails, event);
296
+ config.btn.mise.callback(evtConfig, event);
298
297
  }
299
298
  },
300
299
  {
@@ -310,7 +309,7 @@ export const PopsIframe = {
310
309
  event.stopPropagation();
311
310
  PopsInstanceUtils.removeInstance([PopsInstData.iframe], guid, false);
312
311
  if (typeof config?.btn?.close?.callback === "function") {
313
- config.btn.close.callback(eventDetails, event);
312
+ config.btn.close.callback(evtConfig, event);
314
313
  }
315
314
  },
316
315
  {
@@ -329,7 +328,7 @@ export const PopsIframe = {
329
328
  $shadowRoot: $shadowRoot,
330
329
  });
331
330
 
332
- const result = PopsHandler.handleResultDetails(eventDetails);
331
+ const result = PopsHandler.handleResultConfig(evtConfig);
333
332
  return result;
334
333
  },
335
334
  };
@@ -1,6 +1,6 @@
1
1
  import type { PopsTitleConfig, PopsDragConfig, PopsCommonConfig } from "../../../types/components";
2
2
 
3
- import type { PopsEventDetails } from "../../../types/event";
3
+ import type { PopsEventConfig } from "../../../types/event";
4
4
 
5
5
  /**
6
6
  * pops.iframe的按钮的点击回调参数event
@@ -65,7 +65,7 @@ export interface PopsIframeDetails extends PopsTitleConfig, PopsDragConfig, Pops
65
65
  * 点击的回调函数
66
66
  */
67
67
  callback: (
68
- eventDetails: PopsEventDetails & {
68
+ eventConfig: PopsEventConfig & {
69
69
  iframeElement: HTMLIFrameElement;
70
70
  },
71
71
  event: MouseEvent | PointerEvent
@@ -79,7 +79,7 @@ export interface PopsIframeDetails extends PopsTitleConfig, PopsDragConfig, Pops
79
79
  * 点击的回调函数
80
80
  */
81
81
  callback: (
82
- eventDetails: PopsEventDetails & {
82
+ eventConfig: PopsEventConfig & {
83
83
  iframeElement: HTMLIFrameElement;
84
84
  },
85
85
  event: MouseEvent | PointerEvent
@@ -93,7 +93,7 @@ export interface PopsIframeDetails extends PopsTitleConfig, PopsDragConfig, Pops
93
93
  * 点击的回调函数
94
94
  */
95
95
  callback: (
96
- eventDetails: PopsEventDetails & {
96
+ eventConfig: PopsEventConfig & {
97
97
  iframeElement: HTMLIFrameElement;
98
98
  },
99
99
  event: MouseEvent | PointerEvent
@@ -107,7 +107,7 @@ export interface PopsIframeDetails extends PopsTitleConfig, PopsDragConfig, Pops
107
107
  * 点击的回调函数
108
108
  */
109
109
  callback: (
110
- eventDetails: PopsEventDetails & {
110
+ eventConfig: PopsEventConfig & {
111
111
  iframeElement: HTMLIFrameElement;
112
112
  },
113
113
  event: MouseEvent | PointerEvent
@@ -132,7 +132,7 @@ export interface PopsIframeDetails extends PopsTitleConfig, PopsDragConfig, Pops
132
132
  * 加载完毕的回调
133
133
  */
134
134
  loadEndCallBack?: (
135
- details: PopsEventDetails & {
135
+ details: PopsEventConfig & {
136
136
  iframeElement: HTMLIFrameElement;
137
137
  }
138
138
  ) => void;
@@ -56,15 +56,15 @@ export const PopsLoading = {
56
56
  /**
57
57
  * 遮罩层元素
58
58
  */
59
- let $mask: HTMLDivElement | null = null;
59
+ let $mask: HTMLDivElement | undefined = void 0;
60
60
  /**
61
61
  * 已创建的元素列表
62
62
  */
63
- const elementList: HTMLElement[] = [$anim];
63
+ const $elList: HTMLElement[] = [$anim];
64
64
 
65
65
  if (config.mask.enable) {
66
66
  // 创建遮罩层
67
- const _handleMask_ = PopsHandler.handleMask({
67
+ const handleMask = PopsHandler.handleMask({
68
68
  type: PopsType,
69
69
  guid: guid,
70
70
 
@@ -72,11 +72,11 @@ export const PopsLoading = {
72
72
  animElement: $anim,
73
73
  maskHTML: maskHTML,
74
74
  });
75
- $mask = _handleMask_.maskElement;
76
- elementList.push($mask);
75
+ $mask = handleMask.maskElement;
76
+ $elList.push($mask);
77
77
  }
78
- const eventDetails = PopsHandler.handleLoadingEventDetails(guid, PopsType, $anim, $pops!, $mask!, config);
79
- popsDOMUtils.append(config.parent, elementList);
78
+ const evtConfig = PopsHandler.handleLoadingEventConfig(config, guid, PopsType, $anim, $pops, $mask);
79
+ popsDOMUtils.append(config.parent, $elList);
80
80
  if ($mask != null) {
81
81
  $anim.after($mask);
82
82
  }
@@ -93,7 +93,7 @@ export const PopsLoading = {
93
93
  popsDOMUtils.css($anim, "position", "absolute !important");
94
94
  $mask && popsDOMUtils.css($mask, "position", "absolute !important");
95
95
  }
96
- const result = PopsHandler.handleResultDetails(eventDetails);
96
+ const result = PopsHandler.handleResultConfig(evtConfig);
97
97
  return result;
98
98
  },
99
99
  };
@@ -278,6 +278,9 @@ section.pops-panel-container .pops-panel-forms-fold .pops-panel-forms-container-
278
278
  .pops[type-value="panel"] section.pops-panel-container > ul > li div:nth-child(2) {
279
279
  max-width: 55%;
280
280
  }
281
+ .pops[type-value="panel"] section.pops-panel-container > ul > li .pops-panel-input span.pops-panel-input__suffix {
282
+ padding: 0 4px;
283
+ }
281
284
  .pops[type-value="panel"] section.pops-panel-container .pops-panel-select select {
282
285
  min-width: 88px !important;
283
286
  width: -webkit-fill-available;
@@ -668,6 +671,7 @@ section.pops-panel-container .pops-panel-slider input[type="range"]::-moz-range-
668
671
  background-color: var(--pops-panel-components-input-bg-color);
669
672
  position: relative;
670
673
  box-shadow: none;
674
+ width: 200px;
671
675
  }
672
676
  .pops-panel-input:hover {
673
677
  border: 1px solid var(--pops-panel-components-input-hover-bd-color);
@@ -724,7 +728,7 @@ section.pops-panel-container .pops-panel-slider input[type="range"]::-moz-range-
724
728
  transition: all 0.3s;
725
729
  pointer-events: none;
726
730
  padding: 0 8px;
727
- position: absolute;
731
+ position: relative;
728
732
  right: 0px;
729
733
  border-top-right-radius: 4px;
730
734
  border-bottom-right-radius: 4px;
@@ -746,6 +750,13 @@ section.pops-panel-container .pops-panel-slider input[type="range"]::-moz-range-
746
750
  .pops-panel-input:active span.pops-panel-input__suffix:has(svg[data-type="circleClose"]) {
747
751
  display: inline-flex;
748
752
  }
753
+ /* 当清空图标显示时,则隐藏输入框的padding-right */
754
+ .pops-panel-input:hover:has(span.pops-panel-input__suffix svg[data-type="circleClose"]) input,
755
+ .pops-panel-input:focus:has(span.pops-panel-input__suffix svg[data-type="circleClose"]) input,
756
+ .pops-panel-input:focus-within:has(span.pops-panel-input__suffix svg[data-type="circleClose"]) input,
757
+ .pops-panel-input:active:has(span.pops-panel-input__suffix svg[data-type="circleClose"]) input {
758
+ padding-right: 0;
759
+ }
749
760
  .pops-panel-input .pops-panel-icon {
750
761
  cursor: pointer;
751
762
  }
@@ -129,41 +129,41 @@ export const PopsPanel = {
129
129
  /**
130
130
  * 遮罩层元素
131
131
  */
132
- let $mask: HTMLDivElement | null = null;
132
+ let $mask: HTMLDivElement | undefined = void 0;
133
133
  /**
134
134
  * 已创建的元素列表
135
135
  */
136
- const isCreatedElementList: HTMLElement[] = [$anim];
136
+ const $elList: HTMLElement[] = [$anim];
137
137
 
138
138
  /* 遮罩层元素 */
139
139
  if (config.mask.enable) {
140
- const { maskElement } = PopsHandler.handleMask({
140
+ const handleMask = PopsHandler.handleMask({
141
141
  type: popsType,
142
142
  guid: guid,
143
143
  config: config,
144
144
  animElement: $anim,
145
145
  maskHTML: maskHTML,
146
146
  });
147
- $mask = maskElement;
148
- isCreatedElementList.push($mask);
147
+ $mask = handleMask.maskElement;
148
+ $elList.push($mask);
149
149
  }
150
150
 
151
151
  /* 处理返回的配置 */
152
- const eventDetails = PopsHandler.handleEventDetails(
152
+ const evtConfig = PopsHandler.handleEventConfig(
153
+ config,
153
154
  guid,
154
155
  $shadowContainer,
155
156
  $shadowRoot,
156
157
  popsType,
157
158
  $anim,
158
159
  $pops,
159
- $mask!,
160
- config
160
+ $mask
161
161
  );
162
162
  /* 为顶部右边的关闭按钮添加点击事件 */
163
- PopsHandler.handleClickEvent("close", $headerBtnClose, eventDetails, config.btn.close!.callback!);
163
+ PopsHandler.handleClickEvent("close", $headerBtnClose, evtConfig, config.btn?.close?.callback);
164
164
 
165
165
  /* 创建到页面中 */
166
- popsDOMUtils.append($shadowRoot, isCreatedElementList);
166
+ popsDOMUtils.append($shadowRoot, $elList);
167
167
  if (typeof config.beforeAppendToPageCallBack === "function") {
168
168
  config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
169
169
  }
@@ -209,7 +209,7 @@ export const PopsPanel = {
209
209
  endCallBack: config.dragEndCallBack,
210
210
  });
211
211
  }
212
- const result = PopsHandler.handleResultDetails(eventDetails);
212
+ const result = PopsHandler.handleResultConfig(evtConfig);
213
213
 
214
214
  return {
215
215
  ...result,
@@ -104,76 +104,75 @@ export const PopsPrompt = {
104
104
  /**
105
105
  * 遮罩层元素
106
106
  */
107
- let $mask: HTMLDivElement | null = null;
107
+ let $mask: HTMLDivElement | undefined = void 0;
108
108
 
109
109
  /**
110
110
  * 已创建的元素列表
111
111
  */
112
- const elementList: HTMLElement[] = [$anim];
112
+ const $elList: HTMLElement[] = [$anim];
113
113
 
114
114
  if (config.mask.enable) {
115
115
  // 启用遮罩层
116
- const _handleMask_ = PopsHandler.handleMask({
116
+ const handleMask = PopsHandler.handleMask({
117
117
  type: popsType,
118
118
  guid: guid,
119
119
  config: config,
120
120
  animElement: $anim,
121
121
  maskHTML: maskHTML,
122
122
  });
123
- $mask = _handleMask_.maskElement;
124
- elementList.push($mask);
123
+ $mask = handleMask.maskElement;
124
+ $elList.push($mask);
125
125
  }
126
- const eventDetails = PopsHandler.handleEventDetails(
126
+ const evtConfig = PopsHandler.handleEventConfig(
127
+ config,
127
128
  guid,
128
129
  $shadowContainer,
129
130
  $shadowRoot,
130
131
  popsType,
131
132
  $anim,
132
-
133
- $pops!,
134
- $mask!,
135
- config
133
+ $pops,
134
+ $mask
136
135
  );
137
136
  /* 输入框赋值初始值 */
138
137
 
139
- $input!.value = config.content.text;
138
+ $input.value = config.content.text;
140
139
  PopsHandler.handlePromptClickEvent(
141
140
  "close",
142
- $input!,
143
- $btnClose!,
144
- eventDetails,
141
+ $input,
142
+ $btnClose,
143
+ evtConfig,
145
144
 
146
- config.btn.close!.callback!
145
+ config.btn.close.callback
147
146
  );
148
147
 
149
148
  PopsHandler.handlePromptClickEvent(
150
149
  "ok",
151
- $input!,
152
- $btnOk!,
153
- eventDetails,
150
+ $input,
151
+ $btnOk,
152
+ evtConfig,
154
153
 
155
- config.btn.ok!.callback!
154
+ config.btn.ok.callback
156
155
  );
157
156
  PopsHandler.handlePromptClickEvent(
158
157
  "cancel",
159
- $input!,
160
- $btnCancel!,
161
- eventDetails,
158
+ $input,
159
+ $btnCancel,
160
+ evtConfig,
162
161
 
163
- config.btn.cancel!.callback!
162
+ config.btn.cancel.callback
164
163
  );
165
164
 
166
165
  PopsHandler.handlePromptClickEvent(
167
166
  "other",
168
- $input!,
169
- $btnOther!,
170
- eventDetails,
167
+ $input,
168
+ $btnOther,
169
+ evtConfig,
171
170
 
172
- config.btn.other!.callback!
171
+ config.btn.other.callback
173
172
  );
174
173
  /* 创建到页面中 */
175
174
 
176
- popsDOMUtils.append($shadowRoot, elementList);
175
+ popsDOMUtils.append($shadowRoot, $elList);
177
176
  if (typeof config.beforeAppendToPageCallBack === "function") {
178
177
  config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
179
178
  }
@@ -210,7 +209,7 @@ export const PopsPrompt = {
210
209
  if (config.content.select) {
211
210
  $input.select();
212
211
  }
213
- const result = PopsHandler.handleResultDetails(eventDetails);
212
+ const result = PopsHandler.handleResultConfig(evtConfig);
214
213
  return result;
215
214
  },
216
215
  };
@@ -5,6 +5,7 @@ export const rightClickMenuConfig = (): DeepRequired<PopsRightClickMenuDetails>
5
5
  return {
6
6
  target: document.documentElement,
7
7
  targetSelector: null,
8
+ position: "fixed",
8
9
  data: [
9
10
  {
10
11
  icon: PopsIcon.getIcon("search")!,
@@ -94,5 +95,7 @@ export const rightClickMenuConfig = (): DeepRequired<PopsRightClickMenuDetails>
94
95
  preventDefault: true,
95
96
  style: null,
96
97
  beforeAppendToPageCallBack() {},
98
+ limitPositionXInView: true,
99
+ limitPositionYInView: true,
97
100
  };
98
101
  };
@@ -30,6 +30,9 @@
30
30
  -webkit-backdrop-filter: var(--pops-right-context-backdrop-filter);
31
31
  backdrop-filter: var(--pops-right-context-backdrop-filter);
32
32
  }
33
+ .pops-rightClickMenu[data-position="absolute"] {
34
+ position: absolute;
35
+ }
33
36
  /* scale动画 */
34
37
  .pops-rightClickMenu-anim-scale {
35
38
  transition:
@@ -47,7 +47,7 @@ export const PopsRightClickMenu = {
47
47
  ]);
48
48
 
49
49
  if (config.style != null) {
50
- const cssNode = popsDOMUtils.createElement(
50
+ const $css = popsDOMUtils.createElement(
51
51
  "style",
52
52
  {
53
53
  innerHTML: config.style,
@@ -56,7 +56,7 @@ export const PopsRightClickMenu = {
56
56
  type: "text/css",
57
57
  }
58
58
  );
59
- $shadowRoot.appendChild(cssNode);
59
+ $shadowRoot.appendChild($css);
60
60
  }
61
61
 
62
62
  const PopsContextMenu = {
@@ -132,7 +132,7 @@ export const PopsRightClickMenu = {
132
132
  * @param event
133
133
  * @param selectorTarget
134
134
  */
135
- contextMenuEvent(event: PointerEvent, selectorTarget: HTMLElement) {
135
+ contextMenuEvent(event: PointerEvent, selectorTarget: NonNullable<PopsRightClickMenuDetails["target"]>) {
136
136
  if (config.preventDefault) {
137
137
  popsDOMUtils.preventEvent(event);
138
138
  }
@@ -140,6 +140,7 @@ export const PopsRightClickMenu = {
140
140
  if (PopsContextMenu.rootElement) {
141
141
  PopsContextMenu.closeAllMenu(PopsContextMenu.rootElement);
142
142
  }
143
+ selectorTarget = selectorTarget ?? config.target;
143
144
  const rootElement = PopsContextMenu.showMenu(event, config.data, selectorTarget);
144
145
  PopsContextMenu.rootElement = rootElement;
145
146
  if (config.only) {
@@ -186,7 +187,6 @@ export const PopsRightClickMenu = {
186
187
  });
187
188
  $menu.remove();
188
189
  };
189
- popsDOMUtils.containsClassName;
190
190
  if (popsDOMUtils.containsClassName($menu, `pops-${popsType}-anim-show`)) {
191
191
  /* 有动画 */
192
192
  popsDOMUtils.on($menu, popsDOMUtils.getTransitionEndNameList(), transitionEndEvent, {
@@ -233,10 +233,16 @@ export const PopsRightClickMenu = {
233
233
  * @param isChildren 是否是rightClickMenu的某一项的子菜单
234
234
  */
235
235
  createMenuContainerElement(isChildren: boolean) {
236
- const $menu = popsDOMUtils.createElement("div", {
237
- className: `pops-${popsType}`,
238
- innerHTML: /*html*/ `<ul class="pops-${popsType}-wrapper"></ul>`,
239
- });
236
+ const $menu = popsDOMUtils.createElement(
237
+ "div",
238
+ {
239
+ className: `pops-${popsType}`,
240
+ innerHTML: /*html*/ `<ul class="pops-${popsType}-wrapper"></ul>`,
241
+ },
242
+ {
243
+ "data-position": config.position,
244
+ }
245
+ );
240
246
  const zIndex = this.getMenuZIndex();
241
247
  if (zIndex > 10000) {
242
248
  $menu.style.zIndex = zIndex.toString();
@@ -287,8 +293,13 @@ export const PopsRightClickMenu = {
287
293
  * 限制的间隙距离
288
294
  */
289
295
  const limitDistance = 1;
290
- const maxPageLeftOffset = popsDOMUtils.width(globalThis) - limitDistance;
291
- const maxPageTopOffset = popsDOMUtils.height(globalThis) - limitDistance;
296
+ let maxPageLeftOffset = popsDOMUtils.width(globalThis) - limitDistance;
297
+ let maxPageTopOffset = popsDOMUtils.height(globalThis) - limitDistance;
298
+ if (config.position === "absolute") {
299
+ // 添加滚动距离
300
+ maxPageLeftOffset += globalThis.scrollX;
301
+ maxPageTopOffset += globalThis.scrollY;
302
+ }
292
303
  /* left最大偏移 */
293
304
  const maxLeftOffset = maxPageLeftOffset - menuElementWidth;
294
305
  /* top最大偏移 */
@@ -299,8 +310,10 @@ export const PopsRightClickMenu = {
299
310
  let currentLeftOffset = mousePosition.x;
300
311
  let currentTopOffset = mousePosition.y;
301
312
  currentLeftOffset = currentLeftOffset < 0 ? 0 : currentLeftOffset;
313
+ currentTopOffset = currentTopOffset < 0 ? 0 : currentTopOffset;
314
+
302
315
  // 不允许超出left最大值
303
- if (currentLeftOffset + chileMenuLeftOrRightDistance >= maxLeftOffset) {
316
+ if (config.limitPositionXInView && currentLeftOffset + chileMenuLeftOrRightDistance >= maxLeftOffset) {
304
317
  // 超过,那么子菜单将会在放在左边
305
318
  // 偏移计算方式就是父菜单的右偏移+父菜单的宽度
306
319
  if (parentInfo) {
@@ -326,8 +339,7 @@ export const PopsRightClickMenu = {
326
339
  Reflect.deleteProperty(result, "right");
327
340
  }
328
341
  // 不允许超出top最大值
329
- currentTopOffset = currentTopOffset < 0 ? 0 : currentTopOffset;
330
- if (currentTopOffset + childMenuTopOrBottomDistance >= maxTopOffset) {
342
+ if (config.limitPositionYInView && currentTopOffset + childMenuTopOrBottomDistance >= maxTopOffset) {
331
343
  // 超过,那么子菜单将会在放在上面
332
344
  if (parentInfo) {
333
345
  // 以项的top偏移为基准
@@ -347,6 +359,7 @@ export const PopsRightClickMenu = {
347
359
  Reflect.deleteProperty(result, "top");
348
360
  } else {
349
361
  currentTopOffset = currentTopOffset + childMenuTopOrBottomDistance;
362
+ // 底部偏移
350
363
  result.top = currentTopOffset;
351
364
  Reflect.deleteProperty(result, "bottom");
352
365
  }
@@ -358,7 +371,11 @@ export const PopsRightClickMenu = {
358
371
  * @param _config_
359
372
  * @param menuListenerRootNode 右键菜单监听的元素
360
373
  */
361
- showMenu(menuEvent: PointerEvent, _config_: PopsRightClickMenuDataDetails[], menuListenerRootNode: HTMLElement) {
374
+ showMenu(
375
+ menuEvent: PointerEvent,
376
+ _config_: PopsRightClickMenuDataDetails[],
377
+ menuListenerRootNode: NonNullable<PopsRightClickMenuDetails["target"]>
378
+ ) {
362
379
  const menuElement = this.createMenuContainerElement(false);
363
380
  Reflect.set(menuElement, "__menuData__", {
364
381
  child: [],
@@ -395,7 +412,7 @@ export const PopsRightClickMenu = {
395
412
  _config_: PopsRightClickMenuDataDetails[],
396
413
  rootElement: HTMLDivElement,
397
414
  targetLiElement: HTMLLIElement,
398
- menuListenerRootNode: HTMLElement
415
+ menuListenerRootNode: NonNullable<PopsRightClickMenuDetails["target"]>
399
416
  ) {
400
417
  const menuElement = this.createMenuContainerElement(true);
401
418
  Reflect.set(menuElement, "__menuData__", {
@@ -467,7 +484,7 @@ export const PopsRightClickMenu = {
467
484
  rootElement: HTMLDivElement,
468
485
  menuElement: HTMLDivElement,
469
486
  _config_: PopsRightClickMenuDataDetails[],
470
- menuListenerRootNode: HTMLElement
487
+ menuListenerRootNode: NonNullable<PopsRightClickMenuDetails["target"]>
471
488
  ) {
472
489
  const menuEventTarget = menuEvent.target;
473
490
  const menuULElement = menuElement.querySelector<HTMLUListElement>("ul")!;
@@ -592,11 +609,26 @@ export const PopsRightClickMenu = {
592
609
  PopsContextMenu.addWindowCheckClickListener();
593
610
  return {
594
611
  guid: guid,
595
- config: config,
596
- removeWindowCheckClickListener: PopsContextMenu.removeWindowCheckClickListener,
612
+ config: config as DeepRequired<PopsRightClickMenuDetails>,
597
613
  addWindowCheckClickListener: PopsContextMenu.addWindowCheckClickListener,
598
- removeContextMenuEvent: PopsContextMenu.removeContextMenuEvent,
614
+ removeWindowCheckClickListener: PopsContextMenu.removeWindowCheckClickListener,
599
615
  addContextMenuEvent: PopsContextMenu.addContextMenuEvent,
616
+ removeContextMenuEvent: PopsContextMenu.removeContextMenuEvent,
617
+ /**
618
+ * 移除初始化时的添加的监听事件
619
+ */
620
+ removeInitEventListener: {
621
+ contextMenu() {
622
+ PopsContextMenu.removeContextMenuEvent(config.target as Window, config.targetSelector!);
623
+ },
624
+ windowClick() {
625
+ PopsContextMenu.removeWindowCheckClickListener();
626
+ },
627
+ },
628
+ /**
629
+ * 操作弹出菜单的对象
630
+ */
631
+ PopsContextMenu: PopsContextMenu,
600
632
  };
601
633
  },
602
634
  };
@@ -35,7 +35,7 @@ export interface PopsRightClickMenuDataDetails {
35
35
  clickEvent: PointerEvent,
36
36
  contextMenuEvent: PointerEvent,
37
37
  liElement: HTMLLIElement,
38
- menuListenerRootNode: HTMLElement
38
+ menuListenerRootNode: NonNullable<PopsRightClickMenuDetails["target"]>
39
39
  ) => boolean | void | Promise<boolean | void>;
40
40
  /**
41
41
  * 子项配置
@@ -55,8 +55,14 @@ export interface PopsRightClickMenuDetails
55
55
  target?: HTMLElement | Window | EventTarget | Node;
56
56
  /**
57
57
  * 目标的子元素选择器,默认为空
58
+ * @default null
58
59
  */
59
60
  targetSelector?: string | null;
61
+ /**
62
+ * 位置
63
+ * @default "fixed"
64
+ */
65
+ position?: "absolute" | "fixed";
60
66
  /**
61
67
  * 右键菜单数据
62
68
  */
@@ -95,4 +101,14 @@ export interface PopsRightClickMenuDetails
95
101
  * @default false
96
102
  */
97
103
  preventDefault?: boolean;
104
+ /**
105
+ * 限制x位置在当前视窗内
106
+ * @default true
107
+ */
108
+ limitPositionXInView?: boolean;
109
+ /**
110
+ * 限制y位置在当前视窗内
111
+ * @default true
112
+ */
113
+ limitPositionYInView?: boolean;
98
114
  }