@whitesev/pops 2.2.8 → 2.2.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.
Files changed (146) hide show
  1. package/dist/index.amd.js +2815 -3010
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +2815 -3010
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +2815 -3010
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +2815 -3010
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +2815 -3010
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +2815 -3010
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Pops.d.ts +11 -11
  14. package/dist/types/src/PopsIcon.d.ts +2 -2
  15. package/dist/types/src/components/rightClickMenu/index.d.ts +2 -2
  16. package/dist/types/src/components/tooltip/index.d.ts +2 -2
  17. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +256 -259
  18. package/dist/types/src/types/animation.d.ts +19 -19
  19. package/dist/types/src/types/button.d.ts +187 -196
  20. package/dist/types/src/types/components.d.ts +213 -229
  21. package/dist/types/src/types/event.d.ts +63 -63
  22. package/dist/types/src/types/global.d.ts +20 -20
  23. package/dist/types/src/types/icon.d.ts +32 -32
  24. package/dist/types/src/types/inst.d.ts +24 -24
  25. package/dist/types/src/types/main.d.ts +114 -122
  26. package/dist/types/src/types/mask.d.ts +49 -49
  27. package/dist/types/src/types/position.d.ts +60 -60
  28. package/package.json +61 -56
  29. package/LICENSE +0 -674
  30. package/src/Pops.ts +0 -209
  31. package/src/PopsAnimation.ts +0 -32
  32. package/src/PopsCSS.ts +0 -51
  33. package/src/PopsCore.ts +0 -44
  34. package/src/PopsIcon.ts +0 -95
  35. package/src/PopsInst.ts +0 -21
  36. package/src/components/alert/config.ts +0 -62
  37. package/src/components/alert/index.css +0 -0
  38. package/src/components/alert/index.ts +0 -181
  39. package/src/components/alert/types/index.ts +0 -30
  40. package/src/components/confirm/config.ts +0 -90
  41. package/src/components/confirm/index.css +0 -0
  42. package/src/components/confirm/index.ts +0 -192
  43. package/src/components/confirm/types/index.ts +0 -17
  44. package/src/components/drawer/config.ts +0 -89
  45. package/src/components/drawer/index.css +0 -35
  46. package/src/components/drawer/index.ts +0 -260
  47. package/src/components/drawer/types/index.ts +0 -61
  48. package/src/components/folder/config.ts +0 -147
  49. package/src/components/folder/folderIcon.ts +0 -28
  50. package/src/components/folder/index.css +0 -314
  51. package/src/components/folder/index.ts +0 -1050
  52. package/src/components/folder/types/index.ts +0 -101
  53. package/src/components/iframe/config.ts +0 -60
  54. package/src/components/iframe/index.css +0 -75
  55. package/src/components/iframe/index.ts +0 -351
  56. package/src/components/iframe/types/index.ts +0 -146
  57. package/src/components/loading/config.ts +0 -29
  58. package/src/components/loading/index.css +0 -66
  59. package/src/components/loading/index.ts +0 -114
  60. package/src/components/loading/types/index.ts +0 -40
  61. package/src/components/panel/config.ts +0 -550
  62. package/src/components/panel/handlerComponents.ts +0 -3277
  63. package/src/components/panel/index.css +0 -1292
  64. package/src/components/panel/index.ts +0 -213
  65. package/src/components/panel/types/components-button.ts +0 -69
  66. package/src/components/panel/types/components-common.ts +0 -55
  67. package/src/components/panel/types/components-deepMenu.ts +0 -85
  68. package/src/components/panel/types/components-forms.ts +0 -45
  69. package/src/components/panel/types/components-input.ts +0 -82
  70. package/src/components/panel/types/components-own.ts +0 -31
  71. package/src/components/panel/types/components-select.ts +0 -101
  72. package/src/components/panel/types/components-selectMultiple.ts +0 -133
  73. package/src/components/panel/types/components-slider.ts +0 -78
  74. package/src/components/panel/types/components-switch.ts +0 -57
  75. package/src/components/panel/types/components-textarea.ts +0 -69
  76. package/src/components/panel/types/index.ts +0 -177
  77. package/src/components/prompt/config.ts +0 -94
  78. package/src/components/prompt/index.css +0 -34
  79. package/src/components/prompt/index.ts +0 -222
  80. package/src/components/prompt/types/index.ts +0 -55
  81. package/src/components/rightClickMenu/config.ts +0 -130
  82. package/src/components/rightClickMenu/index.css +0 -88
  83. package/src/components/rightClickMenu/index.ts +0 -689
  84. package/src/components/rightClickMenu/types/index.ts +0 -91
  85. package/src/components/searchSuggestion/config.ts +0 -59
  86. package/src/components/searchSuggestion/index.ts +0 -708
  87. package/src/components/searchSuggestion/types/index.ts +0 -147
  88. package/src/components/tooltip/config.ts +0 -34
  89. package/src/components/tooltip/index.css +0 -196
  90. package/src/components/tooltip/index.ts +0 -655
  91. package/src/components/tooltip/types/index.ts +0 -125
  92. package/src/config/CommonCSSClassName.ts +0 -17
  93. package/src/config/GlobalConfig.ts +0 -80
  94. package/src/css/animation.css +0 -2245
  95. package/src/css/button.css +0 -542
  96. package/src/css/common.css +0 -52
  97. package/src/css/index.css +0 -254
  98. package/src/css/ninePalaceGridPosition.css +0 -50
  99. package/src/css/scrollbar.css +0 -22
  100. package/src/handler/PopsElementHandler.ts +0 -325
  101. package/src/handler/PopsHandler.ts +0 -719
  102. package/src/svg/arrowLeft.svg +0 -4
  103. package/src/svg/arrowRight.svg +0 -4
  104. package/src/svg/chromeFilled.svg +0 -14
  105. package/src/svg/circleClose.svg +0 -8
  106. package/src/svg/close.svg +0 -5
  107. package/src/svg/cpu.svg +0 -8
  108. package/src/svg/delete.svg +0 -5
  109. package/src/svg/documentCopy.svg +0 -5
  110. package/src/svg/edit.svg +0 -8
  111. package/src/svg/eleme.svg +0 -5
  112. package/src/svg/elemePlus.svg +0 -5
  113. package/src/svg/headset.svg +0 -5
  114. package/src/svg/hide.svg +0 -8
  115. package/src/svg/keyboard.svg +0 -8
  116. package/src/svg/loading.svg +0 -5
  117. package/src/svg/max.svg +0 -5
  118. package/src/svg/min.svg +0 -5
  119. package/src/svg/mise.svg +0 -5
  120. package/src/svg/monitor.svg +0 -5
  121. package/src/svg/next.svg +0 -5
  122. package/src/svg/picture.svg +0 -8
  123. package/src/svg/prev.svg +0 -5
  124. package/src/svg/search.svg +0 -5
  125. package/src/svg/share.svg +0 -5
  126. package/src/svg/upload.svg +0 -5
  127. package/src/svg/videoPause.svg +0 -5
  128. package/src/svg/videoPlay.svg +0 -5
  129. package/src/svg/view.svg +0 -5
  130. package/src/types/PopsDOMUtilsEventType.d.ts +0 -259
  131. package/src/types/animation.d.ts +0 -19
  132. package/src/types/button.d.ts +0 -196
  133. package/src/types/components.d.ts +0 -229
  134. package/src/types/event.d.ts +0 -63
  135. package/src/types/global.d.ts +0 -20
  136. package/src/types/icon.d.ts +0 -32
  137. package/src/types/inst.d.ts +0 -24
  138. package/src/types/main.d.ts +0 -122
  139. package/src/types/mask.d.ts +0 -49
  140. package/src/types/position.d.ts +0 -60
  141. package/src/utils/PopsDOMUtils.ts +0 -2649
  142. package/src/utils/PopsDOMUtilsEventsConfig.ts +0 -6
  143. package/src/utils/PopsInstanceUtils.ts +0 -801
  144. package/src/utils/PopsMathUtils.ts +0 -77
  145. package/src/utils/PopsSafeUtils.ts +0 -24
  146. package/src/utils/PopsUtils.ts +0 -430
@@ -1,689 +0,0 @@
1
- import { OriginPrototype } from "../../PopsCore";
2
- import { GlobalConfig } from "../../config/GlobalConfig";
3
- import { PopsHandler } from "../../handler/PopsHandler";
4
- import { popsDOMUtils } from "../../utils/PopsDOMUtils";
5
- import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
6
- import { popsUtils } from "../../utils/PopsUtils";
7
- import { rightClickMenuConfig as PopsRightClickMenuConfig } from "./config";
8
- import type {
9
- PopsRightClickMenuDataDetails,
10
- PopsRightClickMenuDetails,
11
- } from "./types";
12
- import { PopsCSS } from "../../PopsCSS";
13
- import { PopsIcon } from "../../PopsIcon";
14
- import type { PopsType } from "../../types/main";
15
-
16
- export const PopsRightClickMenu = {
17
- init(details: PopsRightClickMenuDetails) {
18
- const guid = popsUtils.getRandomGUID();
19
- // 设置当前类型
20
- const popsType: PopsType = "rightClickMenu";
21
-
22
- let config = PopsRightClickMenuConfig();
23
- config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
24
- config = popsUtils.assign(config, details);
25
- config = PopsHandler.handleOnly(popsType, config);
26
- if (config.target == null) {
27
- throw new Error("config.target 不能为空");
28
- }
29
- if (details.data) {
30
- // @ts-ignore
31
- config.data = details.data;
32
- }
33
- const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
34
- PopsHandler.handleInit($shadowRoot, [
35
- {
36
- name: "index",
37
- css: PopsCSS.index,
38
- },
39
- {
40
- name: "anim",
41
- css: PopsCSS.anim,
42
- },
43
- {
44
- name: "common",
45
- css: PopsCSS.common,
46
- },
47
- {
48
- name: "rightClickMenu",
49
- css: PopsCSS.rightClickMenu,
50
- },
51
- ]);
52
-
53
- if (config.style != null) {
54
- let cssNode = popsDOMUtils.createElement(
55
- "style",
56
- {
57
- innerHTML: config.style,
58
- },
59
- {
60
- type: "text/css",
61
- }
62
- );
63
- $shadowRoot.appendChild(cssNode);
64
- }
65
-
66
- const PopsContextMenu = {
67
- /**
68
- * 根元素
69
- */
70
- rootElement: null as any as HTMLElement,
71
- /**
72
- * 全局点击检测
73
- * @param event
74
- */
75
- windowCheckClickEvent(event: MouseEvent | PointerEvent) {
76
- if (!PopsContextMenu.rootElement) {
77
- return;
78
- }
79
- let $click = event.target as HTMLElement;
80
- if ($click.closest(`.pops-${popsType}`)) {
81
- return;
82
- }
83
- if (
84
- $click.className &&
85
- $click.className === "pops-shadow-container" &&
86
- $click.shadowRoot != null
87
- ) {
88
- return;
89
- }
90
- PopsContextMenu.closeAllMenu(PopsContextMenu.rootElement);
91
- },
92
- /**
93
- * target为shadowRoot或shadowRoot内的全局点击检测
94
- * @param event
95
- */
96
- shadowRootCheckClickEvent(event: MouseEvent | PointerEvent) {
97
- if (!PopsContextMenu.rootElement) {
98
- return;
99
- }
100
- let $click = event.target as HTMLElement;
101
- if ($click.closest(`.pops-${popsType}`)) {
102
- return;
103
- }
104
- PopsContextMenu.closeAllMenu(PopsContextMenu.rootElement);
105
- },
106
- /**
107
- * 添加全局点击检测事件
108
- */
109
- addWindowCheckClickListener() {
110
- popsDOMUtils.on(
111
- globalThis,
112
- "click touchstart",
113
- void 0,
114
- PopsContextMenu.windowCheckClickEvent,
115
- {
116
- capture: true,
117
- }
118
- );
119
- if (config.target instanceof Node) {
120
- const $shadowRoot = config.target.getRootNode();
121
- if ($shadowRoot instanceof ShadowRoot) {
122
- popsDOMUtils.on(
123
- $shadowRoot,
124
- "click touchstart",
125
- void 0,
126
- PopsContextMenu.shadowRootCheckClickEvent,
127
- {
128
- capture: true,
129
- }
130
- );
131
- }
132
- }
133
- },
134
- /**
135
- * 移除全局点击检测事件
136
- */
137
- removeWindowCheckClickListener() {
138
- popsDOMUtils.off(
139
- globalThis,
140
- "click touchstart",
141
- void 0,
142
- PopsContextMenu.windowCheckClickEvent,
143
- {
144
- capture: true,
145
- }
146
- );
147
- if (config.target instanceof Node) {
148
- const $shadowRoot = config.target.getRootNode();
149
- if ($shadowRoot instanceof ShadowRoot) {
150
- popsDOMUtils.off(
151
- $shadowRoot,
152
- "click touchstart",
153
- void 0,
154
- PopsContextMenu.windowCheckClickEvent,
155
- {
156
- capture: true,
157
- }
158
- );
159
- }
160
- }
161
- },
162
- /**
163
- * contextmenu事件
164
- * @param event
165
- * @param selectorTarget
166
- */
167
- contextMenuEvent(event: PointerEvent, selectorTarget: HTMLElement) {
168
- if (config.preventDefault) {
169
- popsDOMUtils.preventEvent(event);
170
- }
171
- PopsHandler.handleOnly(popsType, config);
172
- if (PopsContextMenu.rootElement) {
173
- PopsContextMenu.closeAllMenu(PopsContextMenu.rootElement);
174
- }
175
- let rootElement = PopsContextMenu.showMenu(
176
- event,
177
- config.data,
178
- selectorTarget
179
- );
180
- PopsContextMenu.rootElement = rootElement;
181
- if (config.only) {
182
- PopsHandler.handlePush(popsType, {
183
- $shadowRoot: $shadowRoot,
184
- $shadowContainer: $shadowContainer,
185
- guid: guid,
186
- animElement: rootElement,
187
- popsElement: rootElement,
188
- beforeRemoveCallBack(instCommonConfig) {
189
- PopsContextMenu.closeAllMenu(instCommonConfig.popsElement);
190
- },
191
- });
192
- }
193
- },
194
- /**
195
- * 添加contextmenu事件
196
- * @param target 目标
197
- * @param selector 子元素选择器
198
- */
199
- addContextMenuEvent(
200
- target: PopsRightClickMenuDetails["target"],
201
- selector?: string
202
- ) {
203
- popsDOMUtils.on(
204
- target!,
205
- "contextmenu",
206
- selector,
207
- PopsContextMenu.contextMenuEvent
208
- );
209
- },
210
- /**
211
- * 移除contextmenu事件
212
- * @param target 目标
213
- * @param selector 子元素选择器
214
- */
215
- removeContextMenuEvent(
216
- target: HTMLElement | typeof globalThis | Window,
217
- selector?: string
218
- ) {
219
- popsDOMUtils.off(
220
- target,
221
- "contextmenu",
222
- selector,
223
- PopsContextMenu.contextMenuEvent
224
- );
225
- },
226
- /**
227
- * 自动判断是否存在动画,存在动画就执行关闭动画并删除
228
- * @param element
229
- */
230
- animationCloseMenu(element: HTMLElement) {
231
- /**
232
- * 动画结束触发的事件
233
- */
234
- function transitionEndEvent(event: TransitionEvent) {
235
- popsDOMUtils.off(
236
- element,
237
- popsDOMUtils.getTransitionEndNameList(),
238
- transitionEndEvent,
239
- {
240
- capture: true,
241
- }
242
- );
243
- element.remove();
244
- }
245
- if (element.classList.contains(`pops-${popsType}-anim-show`)) {
246
- /* 有动画 */
247
- popsDOMUtils.on(
248
- element,
249
- popsDOMUtils.getTransitionEndNameList(),
250
- transitionEndEvent,
251
- {
252
- capture: true,
253
- }
254
- );
255
- element.classList.remove(`pops-${popsType}-anim-show`);
256
- } else {
257
- /* 无动画 */
258
- element.remove();
259
- }
260
- },
261
- /**
262
- * 关闭所有菜单
263
- * @param rootElement
264
- */
265
- closeAllMenu(rootElement: HTMLElement) {
266
- if (rootElement == null) {
267
- return;
268
- }
269
- if ((rootElement as any)?.["__menuData__"]?.root) {
270
- rootElement = (rootElement as any)?.["__menuData__"]?.root;
271
- }
272
-
273
- let childMenuList = (rootElement as any)["__menuData__"]
274
- .child as HTMLElement[];
275
- childMenuList.forEach((childMenuElement) => {
276
- this.animationCloseMenu(childMenuElement);
277
- });
278
- this.animationCloseMenu(rootElement);
279
- PopsContextMenu.rootElement = null as any;
280
- },
281
- /**
282
- * 获取菜单容器
283
- * @param isChildren 是否是rightClickMenu的某一项的子菜单
284
- */
285
- getMenuContainerElement(isChildren: boolean) {
286
- let $menu = popsDOMUtils.createElement("div", {
287
- className: `pops-${popsType}`,
288
- innerHTML: /*html*/ `
289
- <ul></ul>
290
- `,
291
- });
292
- let zIndex = this.getMenuZIndex();
293
- if (zIndex > 10000) {
294
- $menu.style.zIndex = zIndex.toString();
295
- }
296
- if (isChildren) {
297
- $menu.setAttribute("is-children", "true");
298
- }
299
- /* 添加动画 */
300
- if (config.isAnimation) {
301
- popsDOMUtils.addClassName($menu, `pops-${popsType}-anim-grid`);
302
- }
303
- return $menu;
304
- },
305
- /**
306
- * 动态获取配的z-index
307
- */
308
- getMenuZIndex() {
309
- return PopsHandler.handleZIndex(config.zIndex);
310
- },
311
- /**
312
- * 获取left、top偏移
313
- * @param menuElement 当前生成的菜单元素
314
- * @param mousePosition 鼠标位置信息
315
- * @param isMainMenu 是否是主菜单
316
- */
317
- getOffset(
318
- menuElement: HTMLElement,
319
- mousePosition: { x: number; y: number },
320
- parentInfo: {
321
- $menu: HTMLElement;
322
- $parentItem: HTMLElement;
323
- } | null
324
- ) {
325
- let result = {
326
- top: 0,
327
- right: 0,
328
- bottom: 0,
329
- left: 0,
330
- };
331
- let menuElementWidth = popsDOMUtils.width(menuElement);
332
- let menuElementHeight = popsDOMUtils.height(menuElement);
333
- /**
334
- * 限制的间隙距离
335
- */
336
- let limitDistance = 1;
337
- let maxPageLeftOffset = popsDOMUtils.width(globalThis) - limitDistance;
338
- let maxPageTopOffset = popsDOMUtils.height(globalThis) - limitDistance;
339
- /* left最大偏移 */
340
- let maxLeftOffset = maxPageLeftOffset - menuElementWidth;
341
- /* top最大偏移 */
342
- let maxTopOffset = maxPageTopOffset - menuElementHeight;
343
-
344
- let chileMenuLeftOrRightDistance = config.chileMenuLeftOrRightDistance;
345
- let childMenuTopOrBottomDistance = config.childMenuTopOrBottomDistance;
346
- let currentLeftOffset = mousePosition.x;
347
- let currentTopOffset = mousePosition.y;
348
- currentLeftOffset = currentLeftOffset < 0 ? 0 : currentLeftOffset;
349
- // 不允许超出left最大值
350
- if (currentLeftOffset + chileMenuLeftOrRightDistance >= maxLeftOffset) {
351
- // 超过,那么子菜单将会在放在左边
352
- // 偏移计算方式就是父菜单的右偏移+父菜单的宽度
353
- if (parentInfo) {
354
- // 子菜单
355
- let mainMenuOffset = popsDOMUtils.offset(parentInfo.$menu);
356
- currentLeftOffset =
357
- maxPageLeftOffset -
358
- mainMenuOffset.left -
359
- chileMenuLeftOrRightDistance +
360
- limitDistance;
361
- } else {
362
- // 主菜单 默认的
363
- currentLeftOffset = limitDistance + chileMenuLeftOrRightDistance;
364
- }
365
- if (currentLeftOffset < 0) {
366
- currentLeftOffset = 0;
367
- } else if (currentLeftOffset > maxLeftOffset) {
368
- currentLeftOffset = maxLeftOffset;
369
- }
370
- // 去除左偏移,变为右偏移
371
- result.right = currentLeftOffset;
372
- Reflect.deleteProperty(result, "left");
373
- } else {
374
- // 右边
375
- currentLeftOffset = currentLeftOffset + chileMenuLeftOrRightDistance;
376
- result.left = currentLeftOffset;
377
- Reflect.deleteProperty(result, "right");
378
- }
379
- // 不允许超出top最大值
380
- currentTopOffset = currentTopOffset < 0 ? 0 : currentTopOffset;
381
- if (currentTopOffset + childMenuTopOrBottomDistance >= maxTopOffset) {
382
- // 超过,那么子菜单将会在放在上面
383
- if (parentInfo) {
384
- // 以项的top偏移为基准
385
- let parentItemOffset = popsDOMUtils.offset(
386
- parentInfo.$parentItem,
387
- false
388
- );
389
- currentTopOffset =
390
- maxPageTopOffset -
391
- parentItemOffset.bottom -
392
- childMenuTopOrBottomDistance +
393
- limitDistance;
394
- } else {
395
- currentTopOffset = limitDistance + childMenuTopOrBottomDistance;
396
- }
397
- if (currentTopOffset < 0) {
398
- currentTopOffset = limitDistance;
399
- } else if (currentTopOffset > maxTopOffset) {
400
- currentTopOffset = maxTopOffset;
401
- }
402
- // 去除上偏移,变为下偏移
403
- result.bottom = currentTopOffset;
404
- Reflect.deleteProperty(result, "top");
405
- } else {
406
- currentTopOffset = currentTopOffset + childMenuTopOrBottomDistance;
407
- result.top = currentTopOffset;
408
- Reflect.deleteProperty(result, "bottom");
409
- }
410
- return result;
411
- },
412
- /**
413
- * 显示菜单
414
- * @param menuEvent 触发的事件
415
- * @param _config_
416
- * @param menuListenerRootNode 右键菜单监听的元素
417
- */
418
- showMenu(
419
- menuEvent: PointerEvent,
420
- _config_: PopsRightClickMenuDataDetails[],
421
- menuListenerRootNode: HTMLElement
422
- ) {
423
- let menuElement = this.getMenuContainerElement(false);
424
- Reflect.set(menuElement, "__menuData__", {
425
- child: [],
426
- });
427
- PopsContextMenu.addMenuLiELement(
428
- menuEvent,
429
- menuElement,
430
- menuElement,
431
- _config_,
432
- menuListenerRootNode
433
- );
434
- /* 先隐藏 */
435
- popsDOMUtils.css(menuElement, {
436
- display: "none",
437
- });
438
- popsDOMUtils.append($shadowRoot, menuElement);
439
- /* 添加到页面 */
440
- if (!document.contains($shadowContainer)) {
441
- if (typeof config.beforeAppendToPageCallBack === "function") {
442
- config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
443
- }
444
- popsDOMUtils.appendBody($shadowContainer);
445
- }
446
- let offset = this.getOffset(
447
- menuElement,
448
- {
449
- x: menuEvent.clientX,
450
- y: menuEvent.clientY,
451
- },
452
- null
453
- );
454
- popsDOMUtils.css(menuElement, {
455
- ...offset,
456
- display: "",
457
- });
458
- /* 过渡动画 */
459
- if (config.isAnimation) {
460
- popsDOMUtils.addClassName(menuElement, `pops-${popsType}-anim-show`);
461
- }
462
- return menuElement;
463
- },
464
- /**
465
- * 显示子菜单
466
- * @param menuEvent 事件
467
- * @param posInfo 位置信息
468
- * @param _config_
469
- * @param rootElement 根菜单元素
470
- * @param targetLiElement 父li项元素
471
- * @param menuListenerRootNode 右键菜单监听的元素
472
- */
473
- showClildMenu(
474
- menuEvent: PointerEvent,
475
- posInfo: {
476
- clientX: number;
477
- clientY: number;
478
- },
479
- _config_: PopsRightClickMenuDataDetails[],
480
- rootElement: HTMLDivElement,
481
- targetLiElement: HTMLLIElement,
482
- menuListenerRootNode: HTMLElement
483
- ) {
484
- let menuElement = this.getMenuContainerElement(true);
485
- Reflect.set(menuElement, "__menuData__", {
486
- parent: targetLiElement,
487
- root: rootElement,
488
- });
489
- // 根菜单数据
490
- let rootElementMenuData = Reflect.get(rootElement, "__menuData__");
491
- rootElementMenuData.child.push(menuElement);
492
- PopsContextMenu.addMenuLiELement(
493
- menuEvent,
494
- rootElement,
495
- menuElement,
496
- _config_,
497
- menuListenerRootNode
498
- );
499
- /* 先隐藏 */
500
- popsDOMUtils.css(menuElement, {
501
- display: "none",
502
- });
503
- /* 添加到页面 */
504
- popsDOMUtils.append($shadowRoot, menuElement);
505
- let $parentMenu = targetLiElement.closest<HTMLElement>(
506
- ".pops-rightClickMenu"
507
- )!;
508
- let offset = this.getOffset(
509
- menuElement,
510
- {
511
- x: posInfo.clientX,
512
- y: posInfo.clientY,
513
- },
514
- {
515
- $menu: $parentMenu,
516
- $parentItem: targetLiElement,
517
- }
518
- );
519
- popsDOMUtils.css(menuElement, { ...offset, display: "" });
520
- /* 过渡动画 */
521
- if (config.isAnimation) {
522
- popsDOMUtils.addClassName(menuElement, `pops-${popsType}-anim-show`);
523
- }
524
- return menuElement;
525
- },
526
- /**
527
- * 获取菜单项的元素
528
- * @param menuEvent 事件
529
- * @param rootElement 根元素
530
- * @param menuElement 菜单元素
531
- * @param _config_ 配置
532
- * @param menuListenerRootNode 右键菜单监听的元素
533
- */
534
- addMenuLiELement(
535
- menuEvent: PointerEvent,
536
- rootElement: HTMLDivElement,
537
- menuElement: HTMLDivElement,
538
- _config_: PopsRightClickMenuDataDetails[],
539
- menuListenerRootNode: HTMLElement
540
- ) {
541
- let menuEventTarget = menuEvent.target;
542
- let menuULElement = menuElement.querySelector<HTMLUListElement>("ul")!;
543
- _config_.forEach((item) => {
544
- let menuLiElement =
545
- popsDOMUtils.parseTextToDOM<HTMLLIElement>(`<li></li>`);
546
- /* 判断有无图标,有就添加进去 */
547
- if (typeof item.icon === "string" && item.icon.trim() !== "") {
548
- let iconSVGHTML = PopsIcon.getIcon(item.icon) ?? item.icon;
549
- let iconElement = popsDOMUtils.parseTextToDOM(
550
- /*html*/ `<i class="pops-${popsType}-icon" is-loading="${
551
- item.iconIsLoading ?? false
552
- }">${iconSVGHTML}</i>`
553
- );
554
- menuLiElement.appendChild(iconElement);
555
- }
556
- /* 插入文字 */
557
- menuLiElement.insertAdjacentHTML(
558
- "beforeend",
559
- PopsSafeUtils.getSafeHTML(`<span>${item.text}</span>`)
560
- );
561
- /* 如果存在子数据,显示 */
562
- if (item.item && Array.isArray(item.item)) {
563
- popsDOMUtils.addClassName(menuLiElement, `pops-${popsType}-item`);
564
- }
565
- /* 鼠标|触摸 移入事件 */
566
- function liElementHoverEvent() {
567
- Array.from(
568
- menuULElement.children as any as HTMLLIElement[]
569
- ).forEach((liElement) => {
570
- popsDOMUtils.removeClassName(
571
- liElement,
572
- `pops-${popsType}-is-visited`
573
- );
574
- if (!(liElement as any).__menuData__) {
575
- return;
576
- }
577
- function removeElement(element: HTMLElement) {
578
- element
579
- .querySelectorAll<HTMLLIElement>("ul li")
580
- .forEach((ele) => {
581
- if ((ele as any)?.__menuData__?.child) {
582
- removeElement((ele as any).__menuData__.child);
583
- }
584
- });
585
- element.remove();
586
- }
587
- /* 遍历根元素的上的__menuData__.child,判断 */
588
- removeElement((liElement as any).__menuData__.child);
589
- });
590
- /* 清理根元素上的children不存在于页面中的元素 */
591
- for (
592
- let index = 0;
593
- index < (rootElement as any).__menuData__.child.length;
594
- index++
595
- ) {
596
- let element = (rootElement as any).__menuData__.child[index];
597
- if (!$shadowRoot.contains(element)) {
598
- (rootElement as any).__menuData__.child.splice(index, 1);
599
- index--;
600
- }
601
- }
602
- popsDOMUtils.addClassName(
603
- menuLiElement,
604
- `pops-${popsType}-is-visited`
605
- );
606
- if (!item.item) {
607
- return;
608
- }
609
- let rect = menuLiElement.getBoundingClientRect();
610
- let childMenu = PopsContextMenu.showClildMenu(
611
- menuEvent,
612
- {
613
- clientX: rect.left + popsDOMUtils.outerWidth(menuLiElement),
614
- clientY: rect.top,
615
- },
616
- item.item,
617
- rootElement,
618
- menuLiElement,
619
- menuListenerRootNode
620
- );
621
- (menuLiElement as any).__menuData__ = {
622
- child: childMenu,
623
- };
624
- }
625
- /**
626
- * 点击事件
627
- * @param clickEvent
628
- * @returns
629
- */
630
- async function liElementClickEvent(
631
- clickEvent: MouseEvent | PointerEvent
632
- ) {
633
- if (typeof item.callback === "function") {
634
- try {
635
- OriginPrototype.Object.defineProperty(menuEvent, "target", {
636
- get() {
637
- return menuEventTarget;
638
- },
639
- });
640
- } catch (error) {}
641
- let callbackResult = await item.callback(
642
- clickEvent as PointerEvent,
643
- menuEvent,
644
- menuLiElement,
645
- menuListenerRootNode
646
- );
647
- if (
648
- typeof callbackResult === "boolean" &&
649
- callbackResult == false
650
- ) {
651
- return;
652
- }
653
- }
654
- /* 取消绑定的鼠标/触摸事件,防止关闭的时候再次触发 */
655
- Array.from(
656
- menuULElement.children as any as HTMLLIElement[]
657
- ).forEach((liEle) => {
658
- popsDOMUtils.off(liEle, "mouseenter touchstart");
659
- });
660
- PopsContextMenu.closeAllMenu(rootElement);
661
- }
662
- popsDOMUtils.on(
663
- menuLiElement,
664
- "mouseenter touchstart",
665
- void 0,
666
- liElementHoverEvent
667
- );
668
- /* 项-点击事件 */
669
- popsDOMUtils.on(menuLiElement, "click", void 0, liElementClickEvent);
670
- menuULElement.appendChild(menuLiElement);
671
- });
672
- },
673
- };
674
-
675
- // 添加右键菜单事件
676
- PopsContextMenu.addContextMenuEvent(config.target, config.targetSelector!);
677
- // 添加全局点击检测
678
- PopsContextMenu.addWindowCheckClickListener();
679
- return {
680
- guid: guid,
681
- config: config,
682
- removeWindowCheckClickListener:
683
- PopsContextMenu.removeWindowCheckClickListener,
684
- addWindowCheckClickListener: PopsContextMenu.addWindowCheckClickListener,
685
- removeContextMenuEvent: PopsContextMenu.removeContextMenuEvent,
686
- addContextMenuEvent: PopsContextMenu.addContextMenuEvent,
687
- };
688
- },
689
- };