@whitesev/pops 3.1.3 → 3.2.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 (61) hide show
  1. package/dist/index.amd.js +230 -133
  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 +230 -133
  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 +230 -133
  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 +230 -133
  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 +230 -133
  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 +230 -133
  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 +10 -10
  26. package/dist/types/src/components/panel/index.d.ts +2 -2
  27. package/dist/types/src/components/rightClickMenu/index.d.ts +1 -1
  28. package/dist/types/src/components/rightClickMenu/types/index.d.ts +8 -1
  29. package/dist/types/src/components/tooltip/index.d.ts +5 -5
  30. package/dist/types/src/components/tooltip/types/index.d.ts +15 -14
  31. package/dist/types/src/handler/PopsHandler.d.ts +4 -4
  32. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +39 -0
  33. package/dist/types/src/types/components.d.ts +2 -1
  34. package/dist/types/src/types/event.d.ts +13 -3
  35. package/dist/types/src/types/inst.d.ts +4 -0
  36. package/dist/types/src/utils/PopsDOMUtils.d.ts +10 -12
  37. package/dist/types/src/utils/PopsInstanceUtils.d.ts +2 -2
  38. package/package.json +2 -2
  39. package/src/components/alert/index.ts +3 -1
  40. package/src/components/confirm/index.ts +3 -1
  41. package/src/components/drawer/index.ts +3 -1
  42. package/src/components/folder/index.ts +3 -1
  43. package/src/components/iframe/index.ts +6 -4
  44. package/src/components/panel/handlerComponents.ts +26 -26
  45. package/src/components/panel/index.ts +3 -1
  46. package/src/components/prompt/index.ts +3 -1
  47. package/src/components/rightClickMenu/defaultConfig.ts +1 -0
  48. package/src/components/rightClickMenu/index.ts +18 -7
  49. package/src/components/rightClickMenu/types/index.ts +8 -1
  50. package/src/components/searchSuggestion/index.ts +7 -19
  51. package/src/components/tooltip/defaultConfig.ts +1 -1
  52. package/src/components/tooltip/index.ts +26 -17
  53. package/src/components/tooltip/types/index.ts +15 -14
  54. package/src/handler/PopsHandler.ts +22 -19
  55. package/src/types/PopsDOMUtilsEventType.d.ts +39 -0
  56. package/src/types/components.d.ts +2 -1
  57. package/src/types/event.d.ts +13 -3
  58. package/src/types/inst.d.ts +4 -0
  59. package/src/utils/PopsDOMUtils.ts +71 -40
  60. package/src/utils/PopsInstanceUtils.ts +62 -30
  61. package/src/utils/PopsUtils.ts +1 -1
@@ -1284,7 +1284,7 @@ export const PanelHandlerComponents = () => {
1284
1284
  * 监听输入框内容改变
1285
1285
  */
1286
1286
  onValueChange() {
1287
- popsDOMUtils.on<InputEvent>(this.$el.input, ["input", "propertychange"], void 0, (event) => {
1287
+ popsDOMUtils.on<InputEvent>(this.$el.input, ["input", "propertychange"], (event) => {
1288
1288
  this.$data.value = this.$el.input.value;
1289
1289
  if (inputType !== "password") {
1290
1290
  // 不是密码框
@@ -1673,7 +1673,7 @@ export const PanelHandlerComponents = () => {
1673
1673
  * 监听点击事件
1674
1674
  */
1675
1675
  onClick() {
1676
- popsDOMUtils.on(this.$el.$select, "click", void 0, (event) => {
1676
+ popsDOMUtils.on(this.$el.$select, "click", (event) => {
1677
1677
  this.setSelectOptionsDisableStatus();
1678
1678
  if (typeof viewConfig.clickCallBack === "function") {
1679
1679
  const $isSelectedElement = this.$el.$select[this.$el.$select.selectedIndex] as HTMLOptionElement;
@@ -3461,7 +3461,7 @@ export const PanelHandlerComponents = () => {
3461
3461
  * 设置按钮的点击事件
3462
3462
  */
3463
3463
  onButtonClick() {
3464
- popsDOMUtils.on(this.$ele.button, "click", void 0, (event) => {
3464
+ popsDOMUtils.on(this.$ele.button, "click", (event) => {
3465
3465
  if (typeof viewConfig.callback === "function") {
3466
3466
  viewConfig.callback(event);
3467
3467
  }
@@ -3533,13 +3533,13 @@ export const PanelHandlerComponents = () => {
3533
3533
  initContainerItem($container: HTMLElement, formItemConfig: PopsPanelViewConfig | PopsPanelContainerConfig) {
3534
3534
  const containerViewConfig = formItemConfig as PopsPanelContainerConfig;
3535
3535
  if (containerViewConfig.type === "container") {
3536
- const childForms = containerViewConfig["views"];
3536
+ const childViewConfig = containerViewConfig["views"];
3537
3537
  // 每一项<li>元素
3538
- const formContainerListElement = popsDOMUtils.createElement("li");
3538
+ const $itemLi = popsDOMUtils.createElement("li");
3539
3539
  // 每一项<li>内的子<ul>元素
3540
- const formContainerULElement = popsDOMUtils.createElement("ul");
3541
- formContainerULElement.classList.add("pops-panel-forms-container-item-formlist");
3542
- formContainerListElement.classList.add("pops-panel-forms-container-item");
3540
+ const $itemUL = popsDOMUtils.createElement("ul");
3541
+ $itemUL.classList.add("pops-panel-forms-container-item-formlist");
3542
+ $itemLi.classList.add("pops-panel-forms-container-item");
3543
3543
  // 区域头部的文字
3544
3544
  const formHeaderDivElement = popsDOMUtils.createElement("div", {
3545
3545
  className: "pops-panel-forms-container-item-header-text",
@@ -3562,41 +3562,41 @@ export const PanelHandlerComponents = () => {
3562
3562
  );
3563
3563
  // 添加点击事件
3564
3564
  popsDOMUtils.on(formHeaderDivElement, "click", () => {
3565
- if (formContainerListElement.hasAttribute("data-fold-enable")) {
3566
- formContainerListElement.removeAttribute("data-fold-enable");
3565
+ if ($itemLi.hasAttribute("data-fold-enable")) {
3566
+ $itemLi.removeAttribute("data-fold-enable");
3567
3567
  } else {
3568
- formContainerListElement.setAttribute("data-fold-enable", "");
3568
+ $itemLi.setAttribute("data-fold-enable", "");
3569
3569
  }
3570
3570
  });
3571
3571
  popsDOMUtils.addClassName(formHeaderDivElement, "pops-panel-forms-fold-container");
3572
3572
  popsDOMUtils.addClassName(formHeaderDivElement, PopsCommonCSSClassName.userSelectNone);
3573
- formContainerListElement.setAttribute("data-fold-enable", "");
3573
+ $itemLi.setAttribute("data-fold-enable", "");
3574
3574
  popsDOMUtils.addClassName(formHeaderDivElement, "pops-panel-forms-fold");
3575
- formContainerListElement.appendChild(formHeaderDivElement);
3575
+ $itemLi.appendChild(formHeaderDivElement);
3576
3576
  } else {
3577
3577
  // 加进容器内
3578
- formContainerListElement.appendChild(formHeaderDivElement);
3578
+ $itemLi.appendChild(formHeaderDivElement);
3579
3579
  }
3580
3580
 
3581
- that.setElementClassName(formContainerListElement, formItemConfig.className);
3582
- that.setElementAttributes(formContainerListElement, formItemConfig.attributes);
3583
- that.setElementProps(formContainerListElement, formItemConfig.props);
3584
- childForms.forEach((childViewConfig) => {
3581
+ that.setElementClassName($itemLi, formItemConfig.className);
3582
+ that.setElementAttributes($itemLi, formItemConfig.attributes);
3583
+ that.setElementProps($itemLi, formItemConfig.props);
3584
+ $itemLi.appendChild($itemUL);
3585
+ $container.appendChild($itemLi);
3586
+ childViewConfig.forEach((childViewConfig) => {
3585
3587
  that.uListContainerAddItem(childViewConfig, {
3586
- ulElement: formContainerULElement,
3588
+ ulElement: $itemUL,
3587
3589
  sectionContainerULElement: that.sectionContainerULElement,
3588
- formContainerListElement: formContainerListElement,
3590
+ formContainerListElement: $itemLi,
3589
3591
  formHeaderDivElement: formHeaderDivElement,
3590
3592
  });
3591
3593
  });
3592
- formContainerListElement.appendChild(formContainerULElement);
3593
- $container.appendChild(formContainerListElement);
3594
3594
  if (typeof containerViewConfig.afterAddToUListCallBack === "function") {
3595
3595
  containerViewConfig.afterAddToUListCallBack(viewConfig as any as PopsPanelContainerConfig, {
3596
- target: formContainerListElement,
3597
- ulElement: formContainerULElement,
3596
+ target: $itemLi,
3597
+ ulElement: $itemUL,
3598
3598
  sectionContainerULElement: that.sectionContainerULElement,
3599
- formContainerListElement: formContainerListElement,
3599
+ formContainerListElement: $itemLi,
3600
3600
  formHeaderDivElement: formHeaderDivElement,
3601
3601
  });
3602
3602
  }
@@ -3747,7 +3747,7 @@ export const PanelHandlerComponents = () => {
3747
3747
  },
3748
3748
  /** 设置项的点击事件 */
3749
3749
  onLiClick() {
3750
- popsDOMUtils.on($li, "click", void 0, async (event) => {
3750
+ popsDOMUtils.on($li, "click", async (event) => {
3751
3751
  if (typeof viewConfig.clickCallBack === "function") {
3752
3752
  const result = await viewConfig.clickCallBack(event, viewConfig);
3753
3753
  if (result) {
@@ -146,6 +146,7 @@ export const PopsPanel = {
146
146
  $pops,
147
147
  $mask
148
148
  );
149
+ const result = PopsHandler.handleResultConfig(evtConfig);
149
150
  // 为顶部右边的关闭按钮添加点击事件
150
151
  PopsHandler.handleClickEvent("close", $headerBtnClose, evtConfig, config.btn?.close?.callback);
151
152
 
@@ -185,6 +186,8 @@ export const PopsPanel = {
185
186
  $mask: $mask!,
186
187
  $shadowContainer: $shadowContainer,
187
188
  $shadowRoot: $shadowRoot,
189
+ config: config,
190
+ destory: result.close,
188
191
  });
189
192
  // 拖拽
190
193
  if (config.drag) {
@@ -196,7 +199,6 @@ export const PopsPanel = {
196
199
  endCallBack: config.dragEndCallBack,
197
200
  });
198
201
  }
199
- const result = PopsHandler.handleResultConfig(evtConfig);
200
202
 
201
203
  return {
202
204
  ...result,
@@ -133,6 +133,7 @@ export const PopsPrompt = {
133
133
  $pops,
134
134
  $mask
135
135
  );
136
+ const result = PopsHandler.handleResultConfig(evtConfig);
136
137
  // 输入框赋值初始值
137
138
 
138
139
  $input.value = config.content.text;
@@ -188,6 +189,8 @@ export const PopsPrompt = {
188
189
  $mask: $mask!,
189
190
  $shadowContainer: $shadowContainer,
190
191
  $shadowRoot: $shadowRoot,
192
+ config: config,
193
+ destory: result.close,
191
194
  });
192
195
  // 拖拽
193
196
  if (config.drag) {
@@ -207,7 +210,6 @@ export const PopsPrompt = {
207
210
  if (config.content.select) {
208
211
  $input.select();
209
212
  }
210
- const result = PopsHandler.handleResultConfig(evtConfig);
211
213
  return result;
212
214
  },
213
215
  };
@@ -98,5 +98,6 @@ export const PopsRightClickMenuDefaultConfig = (): DeepRequired<PopsRightClickMe
98
98
  beforeAppendToPageCallBack() {},
99
99
  limitPositionXInView: true,
100
100
  limitPositionYInView: true,
101
+ beforeShowCallBack() {},
101
102
  };
102
103
  };
@@ -80,6 +80,8 @@ export const PopsRightClickMenu = {
80
80
  return;
81
81
  }
82
82
  if ($click.className && $click.className === "pops-shadow-container" && $click.shadowRoot != null) {
83
+ // pops的shadow-container
84
+ PopsContextMenu.shadowRootCheckClickEvent(event);
83
85
  return;
84
86
  }
85
87
  PopsContextMenu.closeAllMenu(PopsContextMenu.$el.$root);
@@ -92,7 +94,7 @@ export const PopsRightClickMenu = {
92
94
  if (!PopsContextMenu.$el.$root) {
93
95
  return;
94
96
  }
95
- const $click = event.target as HTMLElement;
97
+ const $click = event.composedPath()[0] as HTMLElement;
96
98
  if ($click.closest(`.pops-${popsType}`)) {
97
99
  return;
98
100
  }
@@ -102,13 +104,13 @@ export const PopsRightClickMenu = {
102
104
  * 添加全局点击检测事件
103
105
  */
104
106
  addWindowCheckClickListener() {
105
- popsDOMUtils.on(globalThis, "click touchstart", void 0, PopsContextMenu.windowCheckClickEvent, {
107
+ popsDOMUtils.on(globalThis, "click touchstart", PopsContextMenu.windowCheckClickEvent, {
106
108
  capture: true,
107
109
  });
108
110
  if (config.$target instanceof Node) {
109
111
  const $shadowRoot = config.$target.getRootNode();
110
112
  if ($shadowRoot instanceof ShadowRoot) {
111
- popsDOMUtils.on($shadowRoot, "click touchstart", void 0, PopsContextMenu.shadowRootCheckClickEvent, {
113
+ popsDOMUtils.on($shadowRoot, "click touchstart", PopsContextMenu.shadowRootCheckClickEvent, {
112
114
  capture: true,
113
115
  });
114
116
  }
@@ -118,13 +120,13 @@ export const PopsRightClickMenu = {
118
120
  * 移除全局点击检测事件
119
121
  */
120
122
  removeWindowCheckClickListener() {
121
- popsDOMUtils.off(globalThis, "click touchstart", void 0, PopsContextMenu.windowCheckClickEvent, {
123
+ popsDOMUtils.off(globalThis, "click touchstart", PopsContextMenu.windowCheckClickEvent, {
122
124
  capture: true,
123
125
  });
124
126
  if (config.$target instanceof Node) {
125
127
  const $shadowRoot = config.$target.getRootNode();
126
128
  if ($shadowRoot instanceof ShadowRoot) {
127
- popsDOMUtils.off($shadowRoot, "click touchstart", void 0, PopsContextMenu.windowCheckClickEvent, {
129
+ popsDOMUtils.off($shadowRoot, "click touchstart", PopsContextMenu.windowCheckClickEvent, {
128
130
  capture: true,
129
131
  });
130
132
  }
@@ -135,7 +137,7 @@ export const PopsRightClickMenu = {
135
137
  * @param event
136
138
  * @param selectorTarget
137
139
  */
138
- contextMenuEvent(event: PointerEvent, selectorTarget: NonNullable<PopsRightClickMenuConfig["$target"]>) {
140
+ async contextMenuEvent(event: PointerEvent, selectorTarget: NonNullable<PopsRightClickMenuConfig["$target"]>) {
139
141
  if (config.preventDefault) {
140
142
  popsDOMUtils.preventEvent(event);
141
143
  }
@@ -144,6 +146,10 @@ export const PopsRightClickMenu = {
144
146
  PopsContextMenu.closeAllMenu(PopsContextMenu.$el.$root);
145
147
  }
146
148
  selectorTarget = selectorTarget ?? config.$target;
149
+ const beforeShowCallBackResult = await config?.beforeShowCallBack(event);
150
+ if (typeof beforeShowCallBackResult === "boolean" && !beforeShowCallBackResult) {
151
+ return;
152
+ }
147
153
  const rootElement = PopsContextMenu.showMenu(event, config.data, selectorTarget);
148
154
  PopsContextMenu.$el.$root = rootElement;
149
155
  if (config.only) {
@@ -156,6 +162,10 @@ export const PopsRightClickMenu = {
156
162
  beforeRemoveCallBack(instCommonConfig) {
157
163
  PopsContextMenu.closeAllMenu(instCommonConfig.$pops);
158
164
  },
165
+ config: config,
166
+ destory: () => {
167
+ PopsContextMenu.closeAllMenu(rootElement);
168
+ },
159
169
  });
160
170
  }
161
171
  },
@@ -506,7 +516,8 @@ export const PopsRightClickMenu = {
506
516
  menuLiElement.appendChild(iconElement);
507
517
  }
508
518
  // 插入文字
509
- menuLiElement.insertAdjacentHTML("beforeend", PopsSafeUtils.getSafeHTML(`<span>${item.text}</span>`));
519
+ const text = typeof item.text === "function" ? item.text() : item.text;
520
+ menuLiElement.insertAdjacentHTML("beforeend", PopsSafeUtils.getSafeHTML(`<span>${text}</span>`));
510
521
  // 如果存在子数据,显示
511
522
  if (item.item && Array.isArray(item.item)) {
512
523
  popsDOMUtils.addClassName(menuLiElement, `pops-${popsType}-item`);
@@ -41,7 +41,7 @@ export interface PopsRightClickMenuDataConfig {
41
41
  /**
42
42
  * 文字
43
43
  */
44
- text: string | (() => string);
44
+ text: IFunction<string>;
45
45
  /**
46
46
  * 点击的回调函数
47
47
  * @param clickEvent 点击菜单的click事件
@@ -133,4 +133,11 @@ export interface PopsRightClickMenuConfig
133
133
  * @default true
134
134
  */
135
135
  limitPositionYInView?: boolean;
136
+ /**
137
+ * 菜单显示前的回调
138
+ * @returns
139
+ *
140
+ * + `false`:阻止默认行为(显示菜单)
141
+ */
142
+ beforeShowCallBack?(event: PointerEvent): IPromise<false | void>;
136
143
  }
@@ -488,9 +488,9 @@ export const PopsSearchSuggestion = {
488
488
  setShowEvent(option: AddEventListenerOptions = defaultListenerOption) {
489
489
  /* 焦点|点击事件*/
490
490
  if (config.followPosition === "target") {
491
- popsDOMUtils.on([config.$target], ["focus", "click"], void 0, SearchSuggestion.showEvent, option);
491
+ popsDOMUtils.on([config.$target], ["focus", "click"], SearchSuggestion.showEvent, option);
492
492
  } else if (config.followPosition === "input") {
493
- popsDOMUtils.on([config.$inputTarget], ["focus", "click"], void 0, SearchSuggestion.showEvent, option);
493
+ popsDOMUtils.on([config.$inputTarget], ["focus", "click"], SearchSuggestion.showEvent, option);
494
494
  } else if (config.followPosition === "inputCursor") {
495
495
  popsDOMUtils.on([config.$inputTarget], ["focus", "click", "input"], SearchSuggestion.showEvent, option);
496
496
  } else {
@@ -502,15 +502,9 @@ export const PopsSearchSuggestion = {
502
502
  */
503
503
  removeShowEvent(option: AddEventListenerOptions = defaultListenerOption) {
504
504
  /* 焦点|点击事件*/
505
- popsDOMUtils.off(
506
- [config.$target, config.$inputTarget],
507
- ["focus", "click"],
508
- void 0,
509
- SearchSuggestion.showEvent,
510
- option
511
- );
505
+ popsDOMUtils.off([config.$target, config.$inputTarget], ["focus", "click"], SearchSuggestion.showEvent, option);
512
506
  // 内容改变事件
513
- popsDOMUtils.off([config.$inputTarget], ["input"], void 0, SearchSuggestion.showEvent, option);
507
+ popsDOMUtils.off([config.$inputTarget], ["input"], SearchSuggestion.showEvent, option);
514
508
  },
515
509
  /**
516
510
  * 隐藏搜索建议框的事件
@@ -541,7 +535,7 @@ export const PopsSearchSuggestion = {
541
535
  // 全局触摸屏点击事件
542
536
  if (Array.isArray(SearchSuggestion.selfDocument)) {
543
537
  SearchSuggestion.selfDocument.forEach(($checkParent) => {
544
- popsDOMUtils.on($checkParent, ["click", "touchstart"], void 0, SearchSuggestion.hideEvent, option);
538
+ popsDOMUtils.on($checkParent, ["click", "touchstart"], SearchSuggestion.hideEvent, option);
545
539
  });
546
540
  } else {
547
541
  popsDOMUtils.on(SearchSuggestion.selfDocument, ["click", "touchstart"], SearchSuggestion.hideEvent, option);
@@ -553,16 +547,10 @@ export const PopsSearchSuggestion = {
553
547
  removeHideEvent(option: AddEventListenerOptions = defaultListenerOption) {
554
548
  if (Array.isArray(SearchSuggestion.selfDocument)) {
555
549
  SearchSuggestion.selfDocument.forEach(($checkParent) => {
556
- popsDOMUtils.off($checkParent, ["click", "touchstart"], void 0, SearchSuggestion.hideEvent, option);
550
+ popsDOMUtils.off($checkParent, ["click", "touchstart"], SearchSuggestion.hideEvent, option);
557
551
  });
558
552
  } else {
559
- popsDOMUtils.off(
560
- SearchSuggestion.selfDocument,
561
- ["click", "touchstart"],
562
- void 0,
563
- SearchSuggestion.hideEvent,
564
- option
565
- );
553
+ popsDOMUtils.off(SearchSuggestion.selfDocument, ["click", "touchstart"], SearchSuggestion.hideEvent, option);
566
554
  }
567
555
  },
568
556
  /**
@@ -11,7 +11,7 @@ export const PopsTooltipDefaultConfig = (): DeepRequired<PopsToolTipConfig> => {
11
11
  isFixed: false,
12
12
  alwaysShow: false,
13
13
  onShowEventName: "mouseenter touchstart",
14
- onCloseEventName: "mouseleave touchend",
14
+ onCloseEventName: "mouseleave touchend touchcancel",
15
15
  zIndex: 10000,
16
16
  only: false,
17
17
  eventOption: {
@@ -240,14 +240,14 @@ export class ToolTip {
240
240
  this.$data.config.otherDistance,
241
241
  event
242
242
  );
243
- const positionKey = this.$data.config.position.toUpperCase() as any as keyof typeof positionInfo;
244
- const positionDetail = positionInfo[positionKey];
245
- if (positionDetail) {
246
- this.$el.$toolTip.style.left = positionDetail.left + "px";
247
- this.$el.$toolTip.style.top = positionDetail.top + "px";
248
- this.$el.$toolTip.setAttribute("data-motion", positionDetail.motion);
243
+ const positionKey = this.$data.config.position.toUpperCase() as keyof typeof positionInfo;
244
+ const position = positionInfo[positionKey];
245
+ if (position) {
246
+ this.$el.$toolTip.style.left = position.left + "px";
247
+ this.$el.$toolTip.style.top = position.top + "px";
248
+ this.$el.$toolTip.setAttribute("data-motion", position.motion);
249
249
 
250
- this.$el.$arrow.setAttribute("data-position", positionDetail.arrow);
250
+ this.$el.$arrow.setAttribute("data-position", position.arrow);
251
251
  } else {
252
252
  console.error("不存在该位置", this.$data.config.position);
253
253
  }
@@ -443,13 +443,13 @@ export class ToolTip {
443
443
  */
444
444
  destory() {
445
445
  if (this.$el.$toolTip) {
446
- this.$el.$shadowRoot.removeChild(this.$el.$toolTip);
446
+ this.$el.$toolTip.remove();
447
447
  }
448
- // @ts-ignore
448
+ // @ts-expect-error
449
449
  this.$el.$toolTip = null;
450
- // @ts-ignore
450
+ // @ts-expect-error
451
451
  this.$el.$arrow = null;
452
- // @ts-ignore
452
+ // @ts-expect-error
453
453
  this.$el.$content = null;
454
454
  }
455
455
  /**
@@ -502,7 +502,7 @@ export class ToolTip {
502
502
  );
503
503
  }
504
504
  /**
505
- * 取消监听鼠标|触摸事件
505
+ * 取消监听事件 - 鼠标|触摸
506
506
  */
507
507
  offToolTipMouseEnterEvent() {
508
508
  popsDOMUtils.off(
@@ -513,30 +513,30 @@ export class ToolTip {
513
513
  );
514
514
  }
515
515
  /**
516
- * 鼠标|触摸离开事件
516
+ * 离开事件 - 鼠标|触摸
517
517
  */
518
518
  toolTipMouseLeaveEvent(event: MouseEvent | PointerEvent) {
519
519
  this.close(event);
520
520
  // this.$el.$toolTip.style.animationPlayState = "running";
521
521
  }
522
522
  /**
523
- * 监听鼠标|触摸离开事件
523
+ * 监听离开事件 - 鼠标|触摸
524
524
  */
525
525
  onToolTipMouseLeaveEvent() {
526
526
  popsDOMUtils.on(
527
527
  this.$el.$toolTip,
528
- "mouseleave touchend",
528
+ "mouseleave touchend touchcancel",
529
529
  this.toolTipMouseLeaveEvent,
530
530
  this.$data.config.eventOption
531
531
  );
532
532
  }
533
533
  /**
534
- * 取消监听鼠标|触摸离开事件
534
+ * 取消监听离开事件 - 鼠标|触摸
535
535
  */
536
536
  offToolTipMouseLeaveEvent() {
537
537
  popsDOMUtils.off(
538
538
  this.$el.$toolTip,
539
- "mouseleave touchend",
539
+ "mouseleave touchend touchcancel",
540
540
  this.toolTipMouseLeaveEvent,
541
541
  this.$data.config.eventOption
542
542
  );
@@ -565,6 +565,15 @@ export const PopsTooltip = {
565
565
  }
566
566
  config = PopsHandler.handleOnly(popsType, config);
567
567
 
568
+ if (config.position === "follow") {
569
+ config.onShowEventName = config.onShowEventName.trim();
570
+ const showEventNameSplit = config.onShowEventName.split(" ");
571
+ ["mousemove", "touchmove"].forEach((it) => {
572
+ if (showEventNameSplit.includes(it)) return;
573
+ config.onShowEventName += ` ${it}`;
574
+ });
575
+ }
576
+
568
577
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
569
578
  PopsHandler.handleInit($shadowRoot, [
570
579
  {
@@ -18,35 +18,34 @@ export interface PopsToolTipConfig
18
18
  */
19
19
  content: string | (() => string);
20
20
  /**
21
- * 是否比较获取到的content的内容是否改变
21
+ * 是否比较获取到的`content`的内容是否改变
22
22
  *
23
- * 如果未改变,则在触发.show时不修改内容
23
+ * 如果未改变,则在触发`.show`时不修改内容
24
24
  * @default false
25
25
  */
26
26
  isDiffContent?: boolean;
27
27
  /**
28
28
  * 位置
29
- * + `follow` 跟随鼠标|触摸位置移动
29
+ * + `follow` 跟随(鼠标|触摸)的位置而移动
30
30
  * @default "top"
31
31
  */
32
32
  position?: PopsTooltipPosition;
33
33
  /**
34
34
  * 自定义className
35
35
  *
36
- * + `github-tooltip` github的样式
36
+ * + `github-tooltip`:github的样式
37
37
  * @default ""
38
38
  */
39
39
  className?: PopsPanelGeneralConfig<any>["className"];
40
40
  /**
41
- * 是否使用fixed定位,false则是absolute定位
42
- *
41
+ * 是否使用`fixed`定位,`false`则是`absolute`定位
43
42
  * @default false
44
43
  */
45
44
  isFixed?: boolean;
46
45
  /**
47
46
  * 是否总是显示,默认为false
48
- * + true 设置的onShowEventNameonCloseEventName将无效
49
- * 返回提供showclose函数,取消onoff
47
+ * + true 设置的`onShowEventName`、`onCloseEventName`将无效
48
+ * 返回提供`show`和`close`函数,取消`on`和`off`
50
49
  * + false 事件触发才显示
51
50
  */
52
51
  alwaysShow?: boolean;
@@ -56,13 +55,15 @@ export interface PopsToolTipConfig
56
55
  */
57
56
  delayCloseTime?: number;
58
57
  /**
59
- * 触发显示事件的名称,默认mouseenter touchstart,如果是多个事件,按空格分割
58
+ * 触发显示事件的名称,默认`mouseenter`、`touchstart`,如果是多个事件,按空格分割
59
+ *
60
+ * 如果`position`为`follow`,则添加`mousemove`、`touchmove`事件监听
60
61
  * @default "mouseenter touchstart"
61
62
  */
62
63
  onShowEventName?: string;
63
64
  /**
64
- * 触发关闭事件的名称,默认mouseleave touchend,如果是多个事件,按空格分割
65
- * @default "mouseleave touchend"
65
+ * 触发关闭事件的名称,默认`mouseleave`、`touchend`、`touchcancel`,如果是多个事件,按空格分割
66
+ * @default "mouseleave touchend touchcancel"
66
67
  */
67
68
  onCloseEventName?: string;
68
69
  /**
@@ -111,9 +112,9 @@ export interface PopsToolTipConfig
111
112
  arrowDistance?: number;
112
113
  /**
113
114
  * 其它的距离(px)
114
- * + positionleft或者right,这个距离是上、下距离
115
- * + positiontop或者bottom,这个距离是左、右距离
116
- * + positionfollow,这个距离是上、左距离
115
+ * + 当`position`为`left`或者`right`,这个距离是上、下距离
116
+ * + 当`position`为`top`或者`bottom`,这个距离是左、右距离
117
+ * + 当`position`为`follow`,这个距离是上、左距离
117
118
  * @default 0
118
119
  */
119
120
  otherDistance?: number;
@@ -171,12 +171,12 @@ export const PopsHandler = {
171
171
  );
172
172
  }
173
173
  // 判断按下的元素是否是pops-anim
174
- popsDOMUtils.on(config.animElement, ["touchstart", "mousedown"], void 0, (event) => {
174
+ popsDOMUtils.on(config.animElement, ["touchstart", "mousedown"], (event) => {
175
175
  const $click = event.composedPath()[0] as HTMLElement;
176
176
  isMaskClick = isAnimElement($click);
177
177
  });
178
178
  // 如果有动画层,在动画层上监听点击事件
179
- popsDOMUtils.on<MouseEvent | PointerEvent>(config.animElement, "click", void 0, (event) => {
179
+ popsDOMUtils.on<MouseEvent | PointerEvent>(config.animElement, "click", (event) => {
180
180
  const $click = event.composedPath()[0] as HTMLElement;
181
181
  if (isAnimElement($click) && isMaskClick) {
182
182
  return clickEvent(event);
@@ -184,7 +184,7 @@ export const PopsHandler = {
184
184
  });
185
185
  // 在遮罩层监听点击事件
186
186
  // 如果有动画层,那么该点击事件触发不了
187
- popsDOMUtils.on<MouseEvent | PointerEvent>(result.maskElement, "click", void 0, (event) => {
187
+ popsDOMUtils.on<MouseEvent | PointerEvent>(result.maskElement, "click", (event) => {
188
188
  isMaskClick = true;
189
189
  clickEvent(event);
190
190
  });
@@ -343,7 +343,7 @@ export const PopsHandler = {
343
343
  * @param guid
344
344
  * @param $shadowContainer
345
345
  * @param $shadowRoot
346
- * @param mode 当前弹窗类型
346
+ * @param type 当前弹窗类型
347
347
  * @param $anim 动画层
348
348
  * @param $pops 主元素
349
349
  * @param $mask 遮罩层
@@ -362,7 +362,7 @@ export const PopsHandler = {
362
362
  guid: string,
363
363
  $shadowContainer: HTMLDivElement,
364
364
  $shadowRoot: ShadowRoot | HTMLElement,
365
- mode: PopsInstStoreType,
365
+ type: PopsInstStoreType,
366
366
  $anim: HTMLDivElement,
367
367
  $pops: HTMLDivElement,
368
368
  $mask?: HTMLDivElement
@@ -374,23 +374,26 @@ export const PopsHandler = {
374
374
  $anim: $anim,
375
375
  $pops: $pops,
376
376
  $mask: $mask,
377
- mode: mode,
377
+ mode: type,
378
378
  guid: guid,
379
379
  close() {
380
- return PopsInstanceUtils.close(config, mode, PopsInstData[mode], guid, $anim);
380
+ return PopsInstanceUtils.close(config, type, PopsInstData[type], guid, $anim);
381
381
  },
382
382
  hide() {
383
- return PopsInstanceUtils.hide(config, mode, PopsInstData[mode], guid, $anim, $mask);
383
+ return PopsInstanceUtils.hide(config, type, PopsInstData[type], guid, $anim, $mask);
384
384
  },
385
- show() {
386
- return PopsInstanceUtils.show(config, mode, PopsInstData[mode], guid, $anim, $mask);
385
+ show($parent?: HTMLElement | Document | ShadowRoot) {
386
+ if ($parent) {
387
+ $parent.appendChild(PopsInstData[type][0].$shadowRoot);
388
+ }
389
+ return PopsInstanceUtils.show(config, type, PopsInstData[type], guid, $anim, $mask);
387
390
  },
388
391
  };
389
392
  },
390
393
  /**
391
394
  * 获取loading的事件配置
392
395
  * @param guid
393
- * @param mode 当前弹窗类型
396
+ * @param type 当前弹窗类型
394
397
  * @param $anim 动画层
395
398
  * @param $pops 主元素
396
399
  * @param $mask 遮罩层
@@ -407,7 +410,7 @@ export const PopsHandler = {
407
410
  | PopsPanelConfig
408
411
  | PopsFolderConfig,
409
412
  guid: string,
410
- mode: "loading",
413
+ type: "loading",
411
414
  $anim: HTMLDivElement,
412
415
  $pops: HTMLDivElement,
413
416
  $mask?: HTMLDivElement
@@ -417,16 +420,16 @@ export const PopsHandler = {
417
420
  $anim: $anim,
418
421
  $pops: $pops,
419
422
  $mask: $mask,
420
- mode: mode,
423
+ mode: type,
421
424
  guid: guid,
422
425
  close() {
423
- return PopsInstanceUtils.close(config, mode, PopsInstData[mode], guid, $anim);
426
+ return PopsInstanceUtils.close(config, type, PopsInstData[type], guid, $anim);
424
427
  },
425
428
  hide() {
426
- return PopsInstanceUtils.hide(config, mode, PopsInstData[mode], guid, $anim, $mask);
429
+ return PopsInstanceUtils.hide(config, type, PopsInstData[type], guid, $anim, $mask);
427
430
  },
428
431
  show() {
429
- return PopsInstanceUtils.show(config, mode, PopsInstData[mode], guid, $anim, $mask);
432
+ return PopsInstanceUtils.show(config, type, PopsInstData[type], guid, $anim, $mask);
430
433
  },
431
434
  };
432
435
  },
@@ -563,8 +566,8 @@ export const PopsHandler = {
563
566
  handleOnly<T extends Required<PopsSupportOnlyConfig[keyof PopsSupportOnlyConfig]>>(type: PopsType, config: T): T {
564
567
  if (config.only) {
565
568
  // .loading
566
- // .tooltip
567
569
  // .rightClickMenu
570
+ // .tooltip
568
571
  // 单独处理
569
572
  if (type === "loading" || type === "tooltip" || type === "rightClickMenu") {
570
573
  const inst = PopsInstData[type as keyof typeof PopsInstData];
@@ -576,11 +579,11 @@ export const PopsHandler = {
576
579
  [
577
580
  PopsInstData.alert,
578
581
  PopsInstData.confirm,
579
- PopsInstData.prompt,
580
- PopsInstData.iframe,
581
582
  PopsInstData.drawer,
582
583
  PopsInstData.folder,
584
+ PopsInstData.iframe,
583
585
  PopsInstData.panel,
586
+ PopsInstData.prompt,
584
587
  ],
585
588
  "",
586
589
  true