@whitesev/pops 2.0.6 → 2.0.8

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 (62) hide show
  1. package/dist/index.amd.js +506 -128
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +506 -128
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +506 -128
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +506 -128
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +506 -128
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +506 -128
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Pops.d.ts +20761 -15
  14. package/dist/types/src/components/alert/index.d.ts +3 -3
  15. package/dist/types/src/components/confirm/index.d.ts +3 -3
  16. package/dist/types/src/components/drawer/index.d.ts +3 -3
  17. package/dist/types/src/components/drawer/indexType.d.ts +10 -2
  18. package/dist/types/src/components/folder/index.d.ts +3 -3
  19. package/dist/types/src/components/folder/indexType.d.ts +4 -1
  20. package/dist/types/src/components/iframe/index.d.ts +6 -3
  21. package/dist/types/src/components/iframe/indexType.d.ts +2 -0
  22. package/dist/types/src/components/loading/index.d.ts +3 -3
  23. package/dist/types/src/components/loading/indexType.d.ts +3 -1
  24. package/dist/types/src/components/panel/index.d.ts +3 -3
  25. package/dist/types/src/components/panel/indexType.d.ts +1 -0
  26. package/dist/types/src/components/panel/sliderType.d.ts +14 -4
  27. package/dist/types/src/components/prompt/index.d.ts +3 -3
  28. package/dist/types/src/components/prompt/indexType.d.ts +1 -0
  29. package/dist/types/src/components/rightClickMenu/index.d.ts +20661 -3
  30. package/dist/types/src/components/rightClickMenu/indexType.d.ts +6 -2
  31. package/dist/types/src/components/searchSuggestion/index.d.ts +141 -3
  32. package/dist/types/src/components/searchSuggestion/indexType.d.ts +0 -108
  33. package/dist/types/src/components/tooltip/index.d.ts +60 -5
  34. package/dist/types/src/components/tooltip/indexType.d.ts +6 -4
  35. package/dist/types/src/utils/PopsUtils.d.ts +16 -0
  36. package/package.json +6 -5
  37. package/src/Pops.ts +26 -25
  38. package/src/components/alert/index.ts +6 -5
  39. package/src/components/confirm/index.ts +6 -5
  40. package/src/components/drawer/index.ts +8 -7
  41. package/src/components/drawer/indexType.ts +10 -2
  42. package/src/components/folder/index.ts +8 -7
  43. package/src/components/folder/indexType.ts +4 -1
  44. package/src/components/iframe/index.ts +5 -5
  45. package/src/components/iframe/indexType.ts +2 -0
  46. package/src/components/loading/index.ts +6 -5
  47. package/src/components/loading/indexType.ts +3 -1
  48. package/src/components/panel/PanelHandleContentDetails.ts +71 -38
  49. package/src/components/panel/index.ts +6 -5
  50. package/src/components/panel/indexType.ts +1 -0
  51. package/src/components/panel/sliderType.ts +14 -4
  52. package/src/components/prompt/index.ts +6 -5
  53. package/src/components/prompt/indexType.ts +1 -0
  54. package/src/components/rightClickMenu/index.ts +5 -6
  55. package/src/components/rightClickMenu/indexType.ts +6 -7
  56. package/src/components/searchSuggestion/index.ts +6 -6
  57. package/src/components/searchSuggestion/indexType.ts +0 -109
  58. package/src/components/tooltip/index.ts +65 -25
  59. package/src/components/tooltip/indexType.ts +11 -4
  60. package/src/utils/PopsDOMUtils.ts +1 -1
  61. package/src/utils/PopsInstanceUtils.ts +6 -6
  62. package/src/utils/PopsUtils.ts +53 -1
@@ -7,8 +7,8 @@ import { GlobalConfig } from "../../GlobalConfig";
7
7
  import { PopsSafeUtils } from "../../utils/PopsSafeUtils";
8
8
  import type { PopsSearchSuggestionDetails } from "./indexType";
9
9
 
10
- export class PopsSearchSuggestion {
11
- constructor(details: PopsSearchSuggestionDetails) {
10
+ export const PopsSearchSuggestion = {
11
+ init(details: PopsSearchSuggestionDetails) {
12
12
  const guid = popsUtils.getRandomGUID();
13
13
  // 设置当前类型
14
14
  const PopsType = "searchSuggestion";
@@ -17,7 +17,7 @@ export class PopsSearchSuggestion {
17
17
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
18
18
  config = popsUtils.assign(config, details);
19
19
  if (config.target == null) {
20
- throw new TypeError("config.target 不能为空");
20
+ throw new Error("config.target 不能为空");
21
21
  }
22
22
  /* 做下兼容处理 */
23
23
  if (config.inputTarget == null) {
@@ -352,7 +352,7 @@ export class PopsSearchSuggestion {
352
352
  option
353
353
  );
354
354
  } else {
355
- throw new TypeError("未知followPosition:" + config.followPosition);
355
+ throw new Error("未知followPosition:" + config.followPosition);
356
356
  }
357
357
  },
358
358
  /**
@@ -675,5 +675,5 @@ export class PopsSearchSuggestion {
675
675
  },
676
676
  };
677
677
  return SearchSuggestion;
678
- }
679
- }
678
+ },
679
+ };
@@ -145,112 +145,3 @@ export interface PopsSearchSuggestionDetails<T = any>
145
145
  data: T
146
146
  ) => void;
147
147
  }
148
-
149
- /**
150
- * pops.searchSuggestion的函数返回值
151
- */
152
- export interface PopsSearchSuggestionResult<T = any> {
153
- $el: {
154
- /** 根元素 */
155
- root: HTMLElement;
156
- /** ul元素 */
157
- $hintULContainer: HTMLUListElement;
158
- /** 动态更新CSS */
159
- $dynamicCSS: HTMLStyleElement;
160
- };
161
- /**
162
- * 初始化
163
- */
164
- init: () => void;
165
- /**
166
- * 获取显示出搜索建议框的html
167
- */
168
- getSearchSelectElement: () => HTMLElement;
169
- /**
170
- * 获取显示出搜索建议框的每一项的html
171
- */
172
- getSearchItemLiElement: (data: T, index: number) => HTMLElement;
173
- /**
174
- * 获取data-value值
175
- */
176
- getItemDataValue: (data: T) => T;
177
- /**
178
- * 设置搜索建议框每一项的点击事件
179
- */
180
- setSearchItemClickEvent: (liElement: HTMLLIElement) => void;
181
- /**
182
- * 监听输入框内容改变
183
- */
184
- setInputChangeEvent: (option?: AddEventListenerOptions) => void;
185
- /**
186
- * 移除输入框内容改变的监听
187
- */
188
- removeInputChangeEvent: (option?: AddEventListenerOptions) => void;
189
- /**
190
- * 设置显示搜索建议框的事件
191
- */
192
- setShowEvent: (option?: AddEventListenerOptions) => void;
193
- /**
194
- * 移除显示搜索建议框的事件
195
- */
196
- removeShowEvent: (option?: AddEventListenerOptions) => void;
197
- /**
198
- * 设置隐藏搜索建议框的事件
199
- */
200
- setHideEvent: (option?: AddEventListenerOptions) => void;
201
- /**
202
- * 移除隐藏搜索建议框的事件
203
- */
204
- removeHideEvent: (option?: AddEventListenerOptions) => void;
205
- /**
206
- * 设置所有监听
207
- */
208
- setAllEvent: (option?: AddEventListenerOptions) => void;
209
- /**
210
- * 移除所有监听
211
- */
212
- removeAllEvent: (option?: AddEventListenerOptions) => void;
213
- /**
214
- * 获取删除按钮的html
215
- */
216
- getDeleteIconHTML: (size: number, fill: string) => void;
217
- /**
218
- * 设置当前正在搜索中的提示
219
- */
220
- setPromptsInSearch: () => void;
221
- /**
222
- * 移除正在搜索中的提示
223
- */
224
- removePromptsInSearch: () => void;
225
- /**
226
- * 清空所有的搜索结果
227
- */
228
- clearAllSearchItemLi: () => void;
229
- /**
230
- * 修改搜索建议框的位置(top、left)
231
- * 因为目标元素可能是动态隐藏的
232
- */
233
- changeHintULElementPosition: () => void;
234
- /**
235
- * 修改搜索建议框的width
236
- * 因为目标元素可能是动态隐藏的
237
- */
238
- changeHintULElementWidth: () => void;
239
- updateDynamicCSS: () => void;
240
- /**
241
- * 更新页面显示的搜索结果
242
- */
243
- update: (data: T[]) => void;
244
- /**
245
- * 清空当前的搜索结果并显示无结果
246
- */
247
- clear: () => void;
248
- /**
249
- * 隐藏搜索建议框
250
- */
251
- hide: () => void;
252
- /**
253
- * 显示搜索建议框
254
- */
255
- show: () => void;
256
- }
@@ -146,6 +146,7 @@ export class ToolTip {
146
146
  }
147
147
  /**
148
148
  * 计算 提示框的位置
149
+ * @param event 触发的事件
149
150
  * @param targetElement 目标元素
150
151
  * @param arrowDistance 箭头和目标元素的距离
151
152
  * @param otherDistance 其它位置的偏移
@@ -153,7 +154,8 @@ export class ToolTip {
153
154
  calcToolTipPosition(
154
155
  targetElement: HTMLElement,
155
156
  arrowDistance: number,
156
- otherDistance: number
157
+ otherDistance: number,
158
+ event?: MouseEvent | TouchEvent | PointerEvent
157
159
  ) {
158
160
  let offsetInfo = popsDOMUtils.offset(
159
161
  targetElement,
@@ -180,6 +182,30 @@ export class ToolTip {
180
182
  /* 目标元素的Y轴的中间位置 */
181
183
  let targetElement_Y_center_pos =
182
184
  targetElement_top + targetElement_height / 2 - toolTipElement_height / 2;
185
+
186
+ let mouseX = 0;
187
+ let mouseY = 0;
188
+ if (event != null) {
189
+ if (event instanceof MouseEvent || event instanceof PointerEvent) {
190
+ mouseX = event.pageX;
191
+ mouseY = event.y;
192
+ } else if (event instanceof TouchEvent) {
193
+ let touchEvent = event.touches[0];
194
+ mouseX = touchEvent.pageX;
195
+ mouseY = touchEvent.pageY;
196
+ } else {
197
+ // @ts-ignore
198
+ if (typeof event.clientX === "number") {
199
+ // @ts-ignore
200
+ mouseX = event.clientX;
201
+ }
202
+ // @ts-ignore
203
+ if (typeof event.clientY === "number") {
204
+ // @ts-ignore
205
+ mouseY = event.clientY;
206
+ }
207
+ }
208
+ }
183
209
  return {
184
210
  TOP: {
185
211
  left: targetElement_X_center_pos - otherDistance,
@@ -205,19 +231,26 @@ export class ToolTip {
205
231
  arrow: "right",
206
232
  motion: "fadeInLeft",
207
233
  },
234
+ FOLLOW: {
235
+ left: mouseX + otherDistance,
236
+ top: mouseY + otherDistance,
237
+ arrow: "follow",
238
+ motion: "",
239
+ },
208
240
  };
209
241
  }
210
242
  /**
211
243
  * 动态修改tooltip的位置
212
244
  */
213
- changePosition() {
245
+ changePosition(event?: MouseEvent | TouchEvent | PointerEvent) {
214
246
  let positionInfo = this.calcToolTipPosition(
215
247
  this.$data.config.target,
216
248
  this.$data.config.arrowDistance,
217
- this.$data.config.otherDistance
249
+ this.$data.config.otherDistance,
250
+ event
218
251
  );
219
- let positionKey =
220
- this.$data.config.position.toUpperCase() as any as keyof typeof positionInfo;
252
+ let positionKey = this.$data.config.position.toUpperCase() as any as
253
+ | keyof typeof positionInfo;
221
254
  let positionDetail = positionInfo[positionKey];
222
255
  if (positionDetail) {
223
256
  this.$el.$toolTip.style.left = positionDetail.left + "px";
@@ -276,12 +309,12 @@ export class ToolTip {
276
309
  if (typeof timeId === "number") {
277
310
  // 只清除一个
278
311
  if (timeId == currentTimeId) {
279
- clearTimeout(timeId);
312
+ popsUtils.clearTimeout(timeId);
280
313
  timeIdList.splice(index, 1);
281
314
  break;
282
315
  }
283
316
  } else {
284
- clearTimeout(currentTimeId);
317
+ popsUtils.clearTimeout(currentTimeId);
285
318
  timeIdList.splice(index, 1);
286
319
  index--;
287
320
  }
@@ -322,7 +355,7 @@ export class ToolTip {
322
355
  // 更新内容
323
356
  this.changeContent();
324
357
  // 更新tip的位置
325
- this.changePosition();
358
+ this.changePosition(event);
326
359
  if (typeof this.$data.config.showAfterCallBack === "function") {
327
360
  this.$data.config.showAfterCallBack(this.$el.$toolTip);
328
361
  }
@@ -380,19 +413,26 @@ export class ToolTip {
380
413
  ) {
381
414
  this.$data.config.delayCloseTime = 100;
382
415
  }
383
- let timeId = setTimeout(() => {
416
+ let timeId = popsUtils.setTimeout(() => {
384
417
  // 设置属性触发关闭动画
385
418
  this.clearCloseTimeoutId(eventType, timeId);
386
419
  if (this.$el.$toolTip == null) {
387
420
  // 已清除了
388
421
  return;
389
422
  }
390
- this.$el.$toolTip.setAttribute(
391
- "data-motion",
392
- this.$el.$toolTip
393
- .getAttribute("data-motion")!
394
- .replace("fadeIn", "fadeOut")
395
- );
423
+ let motion = this.$el.$toolTip.getAttribute("data-motion");
424
+ if (motion == null || motion.trim() === "") {
425
+ // 没有动画
426
+ this.toolTipAnimationFinishEvent();
427
+ } else {
428
+ // 修改data-motion触发动画关闭
429
+ this.$el.$toolTip.setAttribute(
430
+ "data-motion",
431
+ this.$el.$toolTip
432
+ .getAttribute("data-motion")!
433
+ .replace("fadeIn", "fadeOut")
434
+ );
435
+ }
396
436
  }, this.$data.config.delayCloseTime);
397
437
  this.addCloseTimeoutId(eventType, timeId);
398
438
  if (typeof this.$data.config.closeAfterCallBack === "function") {
@@ -544,8 +584,8 @@ export type PopsTooltipResult<T extends PopsToolTipDetails> = {
544
584
  toolTip: typeof ToolTip.prototype;
545
585
  };
546
586
 
547
- export class PopsTooltip {
548
- constructor(details: PopsToolTipDetails) {
587
+ export const PopsTooltip = {
588
+ init(details: PopsToolTipDetails) {
549
589
  const guid = popsUtils.getRandomGUID();
550
590
  // 设置当前类型
551
591
  const PopsType = "tooltip";
@@ -554,7 +594,7 @@ export class PopsTooltip {
554
594
  config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
555
595
  config = popsUtils.assign(config, details);
556
596
  if (!(config.target instanceof HTMLElement)) {
557
- throw "config.target 必须是HTMLElement类型";
597
+ throw new TypeError("config.target 必须是HTMLElement类型");
558
598
  }
559
599
  config = PopsHandler.handleOnly(PopsType, config);
560
600
 
@@ -579,11 +619,11 @@ export class PopsTooltip {
579
619
  }
580
620
 
581
621
  return {
582
- guid: guid,
583
- config: config,
584
- $shadowContainer: $shadowContainer,
585
- $shadowRoot: $shadowRoot,
586
- toolTip: toolTip,
622
+ guid,
623
+ config,
624
+ $shadowContainer,
625
+ $shadowRoot,
626
+ toolTip,
587
627
  };
588
- }
589
- }
628
+ },
629
+ };
@@ -1,7 +1,12 @@
1
1
  import type { PopsCommonConfig } from "../../types/components";
2
2
 
3
3
  /** tooltip的出现位置 */
4
- export type PopsTooltipPosition = "top" | "right" | "bottom" | "left";
4
+ export type PopsTooltipPosition =
5
+ | "top"
6
+ | "right"
7
+ | "bottom"
8
+ | "left"
9
+ | "follow";
5
10
 
6
11
  /**
7
12
  * pops.tooltip
@@ -21,18 +26,19 @@ export interface PopsToolTipDetails
21
26
  content: string | (() => string);
22
27
  /**
23
28
  * 位置
29
+ * + `follow` 跟随鼠标|触摸位置移动
24
30
  * @default "top"
25
31
  */
26
32
  position?: PopsTooltipPosition;
27
33
  /**
28
34
  * 自定义className
29
35
  *
30
- * + github-tooltip github的样式
36
+ * + `github-tooltip` github的样式
31
37
  * @default ""
32
38
  */
33
39
  className?: string;
34
40
  /**
35
- * 是否使用fixed定位,默认是absolute
41
+ * 是否使用fixed定位,false则是absolute定位
36
42
  *
37
43
  * @default false
38
44
  */
@@ -41,7 +47,7 @@ export interface PopsToolTipDetails
41
47
  * 是否总是显示,默认为false
42
48
  * + true 设置的triggerShowEventName、triggerCloseEventName将无效
43
49
  * 返回提供show和close函数,取消on和off
44
- * + false 不添加事件,只显示
50
+ * + false 事件触发才显示
45
51
  */
46
52
  alwaysShow?: boolean;
47
53
  /**
@@ -105,6 +111,7 @@ export interface PopsToolTipDetails
105
111
  * 其它的距离(px)
106
112
  * + 当position为left或者right,这个距离是上、下距离
107
113
  * + 当position为top或者bottom,这个距离是左、右距离
114
+ * + 当position为follow,这个距离是上、左距离
108
115
  * @default 0
109
116
  */
110
117
  otherDistance?: number;
@@ -680,7 +680,7 @@ class PopsDOMUtilsEvent {
680
680
  }
681
681
  if (checkDOMReadyState()) {
682
682
  /* 检查document状态 */
683
- setTimeout(callback);
683
+ popsUtils.setTimeout(callback, 0);
684
684
  } else {
685
685
  /* 添加监听 */
686
686
  addDomReadyListener();
@@ -273,7 +273,7 @@ export const PopsInstanceUtils = {
273
273
  animElement.querySelector<HTMLDivElement>(".pops[type-value]")!;
274
274
  if (popsType === "drawer") {
275
275
  let drawerConfig = config as Required<PopsDrawerDetails>;
276
- setTimeout(() => {
276
+ popsUtils.setTimeout(() => {
277
277
  maskElement.style.setProperty("display", "none");
278
278
  if (["top", "bottom"].includes(drawerConfig.direction)) {
279
279
  popsElement.style.setProperty("height", "0");
@@ -368,7 +368,7 @@ export const PopsInstanceUtils = {
368
368
  animElement.querySelector<HTMLDivElement>(".pops[type-value]")!;
369
369
  if (popsType === "drawer") {
370
370
  let drawerConfig = config as PopsDrawerDetails;
371
- setTimeout(() => {
371
+ popsUtils.setTimeout(() => {
372
372
  popsDOMUtils.css(maskElement!, "display", "");
373
373
  let direction = drawerConfig.direction!;
374
374
  let size = drawerConfig.size!.toString();
@@ -380,7 +380,7 @@ export const PopsInstanceUtils = {
380
380
  console.error("未知direction:", direction);
381
381
  }
382
382
  resolve();
383
- }, drawerConfig.openDelay);
383
+ }, drawerConfig.openDelay ?? 0);
384
384
  } else {
385
385
  let findLayerIns = layerConfigList.find(
386
386
  (layerConfigItem) => layerConfigItem.guid === guid
@@ -512,7 +512,7 @@ export const PopsInstanceUtils = {
512
512
  }
513
513
 
514
514
  if (popsType === "drawer") {
515
- setTimeout(() => {
515
+ popsUtils.setTimeout(() => {
516
516
  transitionendEvent();
517
517
  }, drawerConfig.closeDelay);
518
518
  } else {
@@ -786,10 +786,10 @@ export const PopsInstanceUtils = {
786
786
  sortByDesc = true
787
787
  ) {
788
788
  if (typeof sortByDesc !== "boolean") {
789
- throw "参数 sortByDesc 必须为boolean类型";
789
+ throw new TypeError("参数 sortByDesc 必须为boolean类型");
790
790
  }
791
791
  if (getBeforeValueFun == null || getAfterValueFun == null) {
792
- throw "获取前面的值或后面的值的方法不能为空";
792
+ throw new Error("获取前面的值或后面的值的方法不能为空");
793
793
  }
794
794
  return function (after_obj: T, before_obj: T) {
795
795
  var beforeValue = getBeforeValueFun(before_obj); /* 前 */
@@ -1,6 +1,12 @@
1
1
  import { PopsCore } from "../Core";
2
2
  import type { PopsUtilsOwnObject } from "../types/main";
3
3
  import { popsDOMUtils } from "./PopsDOMUtils";
4
+ import {
5
+ clearInterval as WorkerClearInterval,
6
+ clearTimeout as WorkerClearTimeout,
7
+ setInterval as WorkerSetInterval,
8
+ setTimeout as WorkerSetTimeout,
9
+ } from "worker-timers";
4
10
  import AnyTouch from "any-touch";
5
11
 
6
12
  class PopsUtils {
@@ -349,7 +355,7 @@ class PopsUtils {
349
355
  formatByteToSize(byteSize: number | string, addType = true) {
350
356
  byteSize = parseInt(byteSize.toString());
351
357
  if (isNaN(byteSize)) {
352
- throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
358
+ throw new TypeError("Utils.formatByteToSize 参数 byteSize 格式不正确");
353
359
  }
354
360
  let result = 0;
355
361
  let resultType = "KB";
@@ -383,6 +389,52 @@ class PopsUtils {
383
389
  AnyTouch = () => {
384
390
  return AnyTouch;
385
391
  };
392
+ /**
393
+ * 自动使用 Worker 执行 setTimeout
394
+ */
395
+ setTimeout(callback: Function, timeout: number = 0) {
396
+ try {
397
+ return WorkerSetTimeout(callback, timeout);
398
+ } catch (error) {
399
+ return globalThis.setTimeout(callback, timeout);
400
+ }
401
+ }
402
+ /**
403
+ * 配合 .setTimeout 使用
404
+ */
405
+ clearTimeout(timeId: number | undefined) {
406
+ try {
407
+ if (timeId != null) {
408
+ WorkerClearTimeout(timeId);
409
+ }
410
+ } catch (error) {
411
+ } finally {
412
+ globalThis.clearTimeout(timeId);
413
+ }
414
+ }
415
+ /**
416
+ * 自动使用 Worker 执行 setInterval
417
+ */
418
+ setInterval(callback: Function, timeout: number = 0) {
419
+ try {
420
+ return WorkerSetInterval(callback, timeout);
421
+ } catch (error) {
422
+ return globalThis.setInterval(callback, timeout);
423
+ }
424
+ }
425
+ /**
426
+ * 配合 .setInterval 使用
427
+ */
428
+ clearInterval(timeId: number | undefined) {
429
+ try {
430
+ if (timeId != null) {
431
+ WorkerClearInterval(timeId);
432
+ }
433
+ } catch (error) {
434
+ } finally {
435
+ globalThis.clearInterval(timeId);
436
+ }
437
+ }
386
438
  }
387
439
 
388
440
  const popsUtils = new PopsUtils();