@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,655 +0,0 @@
1
- import { GlobalConfig } from "../../config/GlobalConfig";
2
- import { PopsHandler } from "../../handler/PopsHandler";
3
- import { PopsCSS } from "../../PopsCSS";
4
- import type { PopsType } from "../../types/main";
5
- import { popsDOMUtils } from "../../utils/PopsDOMUtils";
6
- import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
7
- import { popsUtils } from "../../utils/PopsUtils";
8
- import { PopsTooltipConfig } from "./config";
9
- import type { PopsToolTipDetails } from "./types/index";
10
-
11
- type ToolTipEventTypeName = "MouseEvent" | "TouchEvent";
12
-
13
- export class ToolTip {
14
- $el = {
15
- $shadowContainer: null as unknown as HTMLDivElement,
16
- $shadowRoot: null as unknown as ShadowRoot | HTMLElement,
17
- $toolTip: null as unknown as HTMLElement,
18
- $content: null as unknown as HTMLElement,
19
- $arrow: null as unknown as HTMLElement,
20
- };
21
- $data = {
22
- config: null as any as Required<PopsToolTipDetails>,
23
- guid: null as any as string,
24
- timeId_close_TouchEvent: <number[]>[],
25
- timeId_close_MouseEvent: <number[]>[],
26
- };
27
- constructor(
28
- config: Required<PopsToolTipDetails>,
29
- guid: string,
30
- ShadowInfo: {
31
- $shadowContainer: HTMLDivElement;
32
- $shadowRoot: ShadowRoot | HTMLElement;
33
- }
34
- ) {
35
- this.$data.config = config;
36
- this.$data.guid = guid;
37
- this.$el.$shadowContainer = ShadowInfo.$shadowContainer;
38
- this.$el.$shadowRoot = ShadowInfo.$shadowRoot;
39
- this.show = this.show.bind(this);
40
- this.close = this.close.bind(this);
41
- this.toolTipAnimationFinishEvent =
42
- this.toolTipAnimationFinishEvent.bind(this);
43
- this.toolTipMouseEnterEvent = this.toolTipMouseEnterEvent.bind(this);
44
- this.toolTipMouseLeaveEvent = this.toolTipMouseLeaveEvent.bind(this);
45
- this.init();
46
- }
47
- init() {
48
- let toolTipInfo = this.createToolTip();
49
- this.$el.$toolTip = toolTipInfo.$toolTipContainer;
50
- this.$el.$content = toolTipInfo.$toolTipContent;
51
- this.$el.$arrow = toolTipInfo.$toolTipArrow;
52
-
53
- this.changeContent();
54
- this.changeZIndex();
55
- this.changePosition();
56
-
57
- if (!this.$data.config.alwaysShow) {
58
- this.offEvent();
59
- this.onEvent();
60
- }
61
- }
62
- /**
63
- * 创建提示元素
64
- */
65
- createToolTip() {
66
- let $toolTipContainer = popsDOMUtils.createElement(
67
- "div",
68
- {
69
- className: "pops-tip",
70
- innerHTML: /*html*/ `
71
- <div class="pops-tip-content" style="text-align: center;"></div>
72
- <div class="pops-tip-arrow"></div>
73
- `,
74
- },
75
- {
76
- "data-position": this.$data.config.isFixed ? "fixed" : "absolute",
77
- "data-guid": this.$data.guid,
78
- }
79
- );
80
- /** 内容 */
81
- let $toolTipContent =
82
- $toolTipContainer.querySelector<HTMLElement>(".pops-tip-content")!;
83
- /** 箭头 */
84
- let $toolTipArrow =
85
- $toolTipContainer.querySelector<HTMLElement>(".pops-tip-arrow")!;
86
-
87
- // 处理className
88
- if (
89
- typeof this.$data.config.className === "string" &&
90
- this.$data.config.className.trim() !== ""
91
- ) {
92
- popsDOMUtils.addClassName($toolTipContainer, this.$data.config.className);
93
- }
94
- // 添加z-index
95
- $toolTipContainer.style.zIndex = PopsHandler.handleZIndex(
96
- this.$data.config.zIndex
97
- ).toString();
98
- if (this.$data.config.style != null) {
99
- /* 添加自定义style */
100
- let cssNode = popsDOMUtils.createElement("style", {
101
- type: "text/css",
102
- innerHTML: this.$data.config.style,
103
- });
104
- $toolTipContainer.appendChild(cssNode);
105
- }
106
- // 处理是否显示箭头元素
107
- if (!this.$data.config.showArrow) {
108
- $toolTipArrow.remove();
109
- }
110
- return {
111
- $toolTipContainer: $toolTipContainer,
112
- $toolTipArrow: $toolTipArrow,
113
- $toolTipContent: $toolTipContent,
114
- };
115
- }
116
- /**
117
- * 获取提示的内容
118
- */
119
- getContent() {
120
- return typeof this.$data.config.content === "function"
121
- ? this.$data.config.content()
122
- : this.$data.config.content;
123
- }
124
- /**
125
- * 修改提示的内容
126
- * @param text
127
- */
128
- changeContent(text?: string) {
129
- if (text == null) {
130
- text = this.getContent();
131
- }
132
- if (this.$data.config.isDiffContent) {
133
- let contentPropKey = "data-content";
134
- // @ts-ignore
135
- let originContentText: string = this.$el.$content[contentPropKey];
136
- if (typeof originContentText === "string") {
137
- if (originContentText === text) {
138
- // 内容未改变,不修改避免渲染
139
- return;
140
- }
141
- }
142
- // @ts-ignore
143
- this.$el.$content[contentPropKey] = text;
144
- }
145
- PopsSafeUtils.setSafeHTML(this.$el.$content, text);
146
- }
147
- /**
148
- * 获取z-index
149
- */
150
- getZIndex() {
151
- const zIndex = PopsHandler.handleZIndex(this.$data.config.zIndex);
152
- return zIndex;
153
- }
154
- /**
155
- * 动态修改z-index
156
- */
157
- changeZIndex() {
158
- const zIndex = this.getZIndex();
159
- this.$el.$toolTip.style.setProperty("z-index", zIndex.toString());
160
- }
161
- /**
162
- * 计算 提示框的位置
163
- * @param event 触发的事件
164
- * @param targetElement 目标元素
165
- * @param arrowDistance 箭头和目标元素的距离
166
- * @param otherDistance 其它位置的偏移
167
- */
168
- calcToolTipPosition(
169
- targetElement: HTMLElement,
170
- arrowDistance: number,
171
- otherDistance: number,
172
- event?: MouseEvent | TouchEvent | PointerEvent
173
- ) {
174
- let offsetInfo = popsDOMUtils.offset(
175
- targetElement,
176
- !this.$data.config.isFixed
177
- );
178
- // 目标 宽
179
- let targetElement_width = offsetInfo.width;
180
- // 目标 高
181
- let targetElement_height = offsetInfo.height;
182
- // 目标 顶部距离
183
- let targetElement_top = offsetInfo.top;
184
-
185
- // let targetElement_bottom = offsetInfo.bottom;
186
- // 目标 左边距离
187
- let targetElement_left = offsetInfo.left;
188
-
189
- // let targetElement_right = offsetInfo.right;
190
-
191
- let toolTipElement_width = popsDOMUtils.outerWidth(this.$el.$toolTip);
192
- let toolTipElement_height = popsDOMUtils.outerHeight(this.$el.$toolTip);
193
- /* 目标元素的x轴的中间位置 */
194
- let targetElement_X_center_pos =
195
- targetElement_left + targetElement_width / 2 - toolTipElement_width / 2;
196
- /* 目标元素的Y轴的中间位置 */
197
- let targetElement_Y_center_pos =
198
- targetElement_top + targetElement_height / 2 - toolTipElement_height / 2;
199
-
200
- let mouseX = 0;
201
- let mouseY = 0;
202
- if (event != null) {
203
- if (event instanceof MouseEvent || event instanceof PointerEvent) {
204
- mouseX = event.pageX;
205
- mouseY = event.y;
206
- } else if (event instanceof TouchEvent) {
207
- let touchEvent = event.touches[0];
208
- mouseX = touchEvent.pageX;
209
- mouseY = touchEvent.pageY;
210
- } else {
211
- // @ts-ignore
212
- if (typeof event.clientX === "number") {
213
- // @ts-ignore
214
- mouseX = event.clientX;
215
- }
216
- // @ts-ignore
217
- if (typeof event.clientY === "number") {
218
- // @ts-ignore
219
- mouseY = event.clientY;
220
- }
221
- }
222
- }
223
- return {
224
- TOP: {
225
- left: targetElement_X_center_pos - otherDistance,
226
- top: targetElement_top - toolTipElement_height - arrowDistance,
227
- arrow: "bottom",
228
- motion: "fadeInTop",
229
- },
230
- RIGHT: {
231
- left: targetElement_left + targetElement_width + arrowDistance,
232
- top: targetElement_Y_center_pos + otherDistance,
233
- arrow: "left",
234
- motion: "fadeInRight",
235
- },
236
- BOTTOM: {
237
- left: targetElement_X_center_pos - otherDistance,
238
- top: targetElement_top + targetElement_height + arrowDistance,
239
- arrow: "top",
240
- motion: "fadeInBottom",
241
- },
242
- LEFT: {
243
- left: targetElement_left - toolTipElement_width - arrowDistance,
244
- top: targetElement_Y_center_pos + otherDistance,
245
- arrow: "right",
246
- motion: "fadeInLeft",
247
- },
248
- FOLLOW: {
249
- left: mouseX + otherDistance,
250
- top: mouseY + otherDistance,
251
- arrow: "follow",
252
- motion: "",
253
- },
254
- };
255
- }
256
- /**
257
- * 动态修改tooltip的位置
258
- */
259
- changePosition(event?: MouseEvent | TouchEvent | PointerEvent) {
260
- let positionInfo = this.calcToolTipPosition(
261
- this.$data.config.target,
262
- this.$data.config.arrowDistance,
263
- this.$data.config.otherDistance,
264
- event
265
- );
266
- let positionKey = this.$data.config.position.toUpperCase() as any as
267
- | keyof typeof positionInfo;
268
- let positionDetail = positionInfo[positionKey];
269
- if (positionDetail) {
270
- this.$el.$toolTip.style.left = positionDetail.left + "px";
271
- this.$el.$toolTip.style.top = positionDetail.top + "px";
272
- this.$el.$toolTip.setAttribute("data-motion", positionDetail.motion);
273
-
274
- this.$el.$arrow.setAttribute("data-position", positionDetail.arrow);
275
- } else {
276
- console.error("不存在该位置", this.$data.config.position);
277
- }
278
- }
279
- /**
280
- * 事件绑定
281
- */
282
- onEvent() {
283
- // 监听动画结束事件
284
- this.onToolTipAnimationFinishEvent();
285
- this.onShowEvent();
286
- this.onCloseEvent();
287
- this.onToolTipMouseEnterEvent();
288
- this.onToolTipMouseLeaveEvent();
289
- }
290
- /**
291
- * 取消事件绑定
292
- */
293
- offEvent() {
294
- this.offToolTipAnimationFinishEvent();
295
- this.offShowEvent();
296
- this.offCloseEvent();
297
- this.offToolTipMouseEnterEvent();
298
- this.offToolTipMouseLeaveEvent();
299
- }
300
- /**
301
- * 添加关闭的timeId
302
- * @param type
303
- * @param timeId
304
- */
305
- addCloseTimeoutId(type: ToolTipEventTypeName, timeId: number) {
306
- if (type === "MouseEvent") {
307
- this.$data.timeId_close_MouseEvent.push(timeId);
308
- } else {
309
- this.$data.timeId_close_TouchEvent.push(timeId);
310
- }
311
- }
312
- /**
313
- * 清除延迟的timeId
314
- * @param type 事件类型
315
- */
316
- clearCloseTimeoutId(type: ToolTipEventTypeName, timeId?: number) {
317
- let timeIdList =
318
- type === "MouseEvent"
319
- ? this.$data.timeId_close_MouseEvent
320
- : this.$data.timeId_close_TouchEvent;
321
- for (let index = 0; index < timeIdList.length; index++) {
322
- const currentTimeId = timeIdList[index];
323
- if (typeof timeId === "number") {
324
- // 只清除一个
325
- if (timeId == currentTimeId) {
326
- popsUtils.clearTimeout(timeId);
327
- timeIdList.splice(index, 1);
328
- break;
329
- }
330
- } else {
331
- popsUtils.clearTimeout(currentTimeId);
332
- timeIdList.splice(index, 1);
333
- index--;
334
- }
335
- }
336
- }
337
- /**
338
- * 显示提示框
339
- */
340
- show(...args: any[]) {
341
- let event = args[0] as MouseEvent | TouchEvent;
342
- let eventType: ToolTipEventTypeName =
343
- event instanceof MouseEvent ? "MouseEvent" : "TouchEvent";
344
- this.clearCloseTimeoutId(eventType);
345
-
346
- if (typeof this.$data.config.showBeforeCallBack === "function") {
347
- let result = this.$data.config.showBeforeCallBack(this.$el.$toolTip);
348
- if (typeof result === "boolean" && !result) {
349
- return;
350
- }
351
- }
352
- if (!popsUtils.contains(this.$el.$shadowRoot, this.$el.$toolTip)) {
353
- // 不在容器中,添加
354
- this.init();
355
- popsDOMUtils.append(this.$el.$shadowRoot, this.$el.$toolTip);
356
- }
357
-
358
- if (!popsUtils.contains(this.$el.$shadowContainer)) {
359
- // 页面不存在Shadow,添加
360
- if (typeof this.$data.config.beforeAppendToPageCallBack === "function") {
361
- this.$data.config.beforeAppendToPageCallBack(
362
- this.$el.$shadowRoot,
363
- this.$el.$shadowContainer
364
- );
365
- }
366
- popsDOMUtils.append(document.body, this.$el.$shadowContainer);
367
- }
368
-
369
- // 更新内容
370
- this.changeContent();
371
- // 更新tip的位置
372
- this.changePosition(event);
373
- if (typeof this.$data.config.showAfterCallBack === "function") {
374
- this.$data.config.showAfterCallBack(this.$el.$toolTip);
375
- }
376
- }
377
- /**
378
- * 绑定 显示事件
379
- */
380
- onShowEvent() {
381
- popsDOMUtils.on(
382
- this.$data.config.target,
383
- this.$data.config.triggerShowEventName,
384
- this.show,
385
- this.$data.config.eventOption
386
- );
387
- }
388
- /**
389
- * 取消绑定 显示事件
390
- */
391
- offShowEvent() {
392
- popsDOMUtils.off(
393
- this.$data.config.target,
394
- this.$data.config.triggerShowEventName,
395
- this.show,
396
- {
397
- capture: true,
398
- }
399
- );
400
- }
401
- /**
402
- * 关闭提示框
403
- */
404
- close(...args: any[]) {
405
- let event = args[0] as MouseEvent | TouchEvent;
406
- let eventType: ToolTipEventTypeName =
407
- event instanceof MouseEvent ? "MouseEvent" : "TouchEvent";
408
- // 只判断鼠标事件
409
- // 其它的如Touch事件不做处理
410
- if (event && event instanceof MouseEvent) {
411
- let $target = event.composedPath()[0];
412
- // 如果是目标元素的子元素/tooltip元素的子元素触发的话,那就不管
413
- if ($target != this.$data.config.target && $target != this.$el.$toolTip) {
414
- return;
415
- }
416
- }
417
- if (typeof this.$data.config.closeBeforeCallBack === "function") {
418
- let result = this.$data.config.closeBeforeCallBack(this.$el.$toolTip);
419
- if (typeof result === "boolean" && !result) {
420
- return;
421
- }
422
- }
423
- if (
424
- this.$data.config.delayCloseTime == null ||
425
- (typeof this.$data.config.delayCloseTime === "number" &&
426
- this.$data.config.delayCloseTime <= 0)
427
- ) {
428
- this.$data.config.delayCloseTime = 100;
429
- }
430
- let timeId = popsUtils.setTimeout(() => {
431
- // 设置属性触发关闭动画
432
- this.clearCloseTimeoutId(eventType, timeId);
433
- if (this.$el.$toolTip == null) {
434
- // 已清除了
435
- return;
436
- }
437
- let motion = this.$el.$toolTip.getAttribute("data-motion");
438
- if (motion == null || motion.trim() === "") {
439
- // 没有动画
440
- this.toolTipAnimationFinishEvent();
441
- } else {
442
- // 修改data-motion触发动画关闭
443
- this.$el.$toolTip.setAttribute(
444
- "data-motion",
445
- this.$el.$toolTip
446
- .getAttribute("data-motion")!
447
- .replace("fadeIn", "fadeOut")
448
- );
449
- }
450
- }, this.$data.config.delayCloseTime);
451
- this.addCloseTimeoutId(eventType, timeId);
452
- if (typeof this.$data.config.closeAfterCallBack === "function") {
453
- this.$data.config.closeAfterCallBack(this.$el.$toolTip);
454
- }
455
- }
456
- /**
457
- * 绑定 关闭事件
458
- */
459
- onCloseEvent() {
460
- popsDOMUtils.on(
461
- this.$data.config.target,
462
- this.$data.config.triggerCloseEventName,
463
- this.close,
464
- this.$data.config.eventOption
465
- );
466
- }
467
- /**
468
- * 取消绑定 关闭事件
469
- */
470
- offCloseEvent() {
471
- popsDOMUtils.off(
472
- this.$data.config.target,
473
- this.$data.config.triggerCloseEventName,
474
- this.close,
475
- {
476
- capture: true,
477
- }
478
- );
479
- }
480
- /**
481
- * 销毁元素
482
- */
483
- destory() {
484
- if (this.$el.$toolTip) {
485
- this.$el.$shadowRoot.removeChild(this.$el.$toolTip);
486
- }
487
- // @ts-ignore
488
- this.$el.$toolTip = null;
489
- // @ts-ignore
490
- this.$el.$arrow = null;
491
- // @ts-ignore
492
- this.$el.$content = null;
493
- }
494
- /**
495
- * 动画结束事件
496
- */
497
- toolTipAnimationFinishEvent() {
498
- if (!this.$el.$toolTip) {
499
- return;
500
- }
501
- if (this.$el.$toolTip.getAttribute("data-motion")!.includes("In")) {
502
- return;
503
- }
504
- this.destory();
505
- }
506
- /**
507
- * 监听tooltip的动画结束
508
- */
509
- onToolTipAnimationFinishEvent() {
510
- popsDOMUtils.on(
511
- this.$el.$toolTip,
512
- popsDOMUtils.getAnimationEndNameList(),
513
- this.toolTipAnimationFinishEvent
514
- );
515
- }
516
- /**
517
- * 取消tooltip监听动画结束
518
- */
519
- offToolTipAnimationFinishEvent() {
520
- popsDOMUtils.off(
521
- this.$el.$toolTip,
522
- popsDOMUtils.getAnimationEndNameList(),
523
- this.toolTipAnimationFinishEvent
524
- );
525
- }
526
- /**
527
- * 鼠标|触摸进入事件
528
- */
529
- toolTipMouseEnterEvent() {
530
- this.clearCloseTimeoutId("MouseEvent");
531
- this.clearCloseTimeoutId("TouchEvent");
532
- // 重置动画状态
533
- // this.$el.$toolTip.style.animationPlayState = "paused";
534
- // if (parseInt(getComputedStyle(toolTipElement)) > 0.5) {
535
- // toolTipElement.style.animationPlayState = "paused";
536
- // }
537
- }
538
- /**
539
- * 监听鼠标|触摸事件
540
- */
541
- onToolTipMouseEnterEvent() {
542
- this.clearCloseTimeoutId("MouseEvent");
543
- this.clearCloseTimeoutId("TouchEvent");
544
- popsDOMUtils.on(
545
- this.$el.$toolTip,
546
- "mouseenter touchstart",
547
- this.toolTipMouseEnterEvent,
548
- this.$data.config.eventOption
549
- );
550
- }
551
- /**
552
- * 取消监听鼠标|触摸事件
553
- */
554
- offToolTipMouseEnterEvent() {
555
- popsDOMUtils.off(
556
- this.$el.$toolTip,
557
- "mouseenter touchstart",
558
- this.toolTipMouseEnterEvent,
559
- this.$data.config.eventOption
560
- );
561
- }
562
- /**
563
- * 鼠标|触摸离开事件
564
- */
565
- toolTipMouseLeaveEvent(event: MouseEvent | PointerEvent) {
566
- this.close(event);
567
- // this.$el.$toolTip.style.animationPlayState = "running";
568
- }
569
- /**
570
- * 监听鼠标|触摸离开事件
571
- */
572
- onToolTipMouseLeaveEvent() {
573
- popsDOMUtils.on(
574
- this.$el.$toolTip,
575
- "mouseleave touchend",
576
- this.toolTipMouseLeaveEvent,
577
- this.$data.config.eventOption
578
- );
579
- }
580
- /**
581
- * 取消监听鼠标|触摸离开事件
582
- */
583
- offToolTipMouseLeaveEvent() {
584
- popsDOMUtils.off(
585
- this.$el.$toolTip,
586
- "mouseleave touchend",
587
- this.toolTipMouseLeaveEvent,
588
- this.$data.config.eventOption
589
- );
590
- }
591
- }
592
-
593
- export type PopsTooltipResult<T extends PopsToolTipDetails> = {
594
- guid: string;
595
- config: T;
596
- $shadowContainer: HTMLDivElement;
597
- $shadowRoot: ShadowRoot;
598
- toolTip: typeof ToolTip.prototype;
599
- };
600
-
601
- export const PopsTooltip = {
602
- init(details: PopsToolTipDetails) {
603
- const guid = popsUtils.getRandomGUID();
604
- // 设置当前类型
605
- const popsType: PopsType = "tooltip";
606
-
607
- let config = PopsTooltipConfig();
608
- config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
609
- config = popsUtils.assign(config, details);
610
- if (!(config.target instanceof HTMLElement)) {
611
- throw new TypeError("config.target 必须是HTMLElement类型");
612
- }
613
- config = PopsHandler.handleOnly(popsType, config);
614
-
615
- const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
616
- PopsHandler.handleInit($shadowRoot, [
617
- {
618
- name: "index",
619
- css: PopsCSS.index,
620
- },
621
- {
622
- name: "anim",
623
- css: PopsCSS.anim,
624
- },
625
- {
626
- name: "common",
627
- css: PopsCSS.common,
628
- },
629
- {
630
- name: "tooltipCSS",
631
- css: PopsCSS.tooltipCSS,
632
- },
633
- ]);
634
-
635
- let toolTip = new ToolTip(config, guid, {
636
- $shadowContainer,
637
- $shadowRoot,
638
- });
639
- if (config.alwaysShow) {
640
- /* 总是显示 */
641
- /* 直接显示 */
642
- toolTip.show();
643
- } else {
644
- /* 事件触发才显示 */
645
- }
646
-
647
- return {
648
- guid,
649
- config,
650
- $shadowContainer,
651
- $shadowRoot,
652
- toolTip,
653
- };
654
- },
655
- };