@whitesev/pops 2.3.4 → 2.3.6

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.
package/dist/index.umd.js CHANGED
@@ -186,9 +186,19 @@
186
186
  window: window,
187
187
  globalThis: globalThis,
188
188
  self: self,
189
+ setTimeout: globalThis.setTimeout.bind(globalThis),
190
+ setInterval: globalThis.setInterval.bind(globalThis),
191
+ clearTimeout: globalThis.clearTimeout.bind(globalThis),
192
+ clearInterval: globalThis.clearInterval.bind(globalThis),
189
193
  };
190
194
  const PopsCoreEnv = Object.assign({}, PopsCoreDefaultEnv);
191
195
  const PopsCore = {
196
+ init(option) {
197
+ if (!option) {
198
+ option = Object.assign({}, PopsCoreDefaultEnv);
199
+ }
200
+ Object.assign(PopsCoreEnv, option);
201
+ },
192
202
  get document() {
193
203
  return PopsCoreEnv.document;
194
204
  },
@@ -201,6 +211,18 @@
201
211
  get self() {
202
212
  return PopsCoreEnv.self;
203
213
  },
214
+ get setTimeout() {
215
+ return PopsCoreEnv.setTimeout;
216
+ },
217
+ get setInterval() {
218
+ return PopsCoreEnv.setInterval;
219
+ },
220
+ get clearTimeout() {
221
+ return PopsCoreEnv.clearTimeout;
222
+ },
223
+ get clearInterval() {
224
+ return PopsCoreEnv.clearInterval;
225
+ },
204
226
  };
205
227
  const OriginPrototype = {
206
228
  Object: {
@@ -719,7 +741,7 @@
719
741
  return setTimeout$1(callback, timeout);
720
742
  }
721
743
  catch (error) {
722
- return globalThis.setTimeout(callback, timeout);
744
+ return PopsCore.setTimeout(callback, timeout);
723
745
  }
724
746
  }
725
747
  /**
@@ -734,7 +756,7 @@
734
756
  catch (error) {
735
757
  }
736
758
  finally {
737
- globalThis.clearTimeout(timeId);
759
+ PopsCore.clearTimeout(timeId);
738
760
  }
739
761
  }
740
762
  /**
@@ -745,7 +767,7 @@
745
767
  return setInterval$1(callback, timeout);
746
768
  }
747
769
  catch (error) {
748
- return globalThis.setInterval(callback, timeout);
770
+ return PopsCore.setInterval(callback, timeout);
749
771
  }
750
772
  }
751
773
  /**
@@ -760,7 +782,7 @@
760
782
  catch (error) {
761
783
  }
762
784
  finally {
763
- globalThis.clearInterval(timeId);
785
+ PopsCore.clearInterval(timeId);
764
786
  }
765
787
  }
766
788
  }
@@ -10748,28 +10770,42 @@
10748
10770
  popsDOMUtils.addClassName(menuLiElement, `pops-${popsType}-item`);
10749
10771
  }
10750
10772
  /* 鼠标|触摸 移入事件 */
10751
- function liElementHoverEvent() {
10773
+ // 在移动端会先触发touchstart再然后mouseenter
10774
+ let isTriggerTouchEvent = false;
10775
+ /**
10776
+ * 鼠标|触摸 移入事件
10777
+ */
10778
+ function liElementHoverEvent(event) {
10779
+ if (event.type === "touchstart") {
10780
+ isTriggerTouchEvent = true;
10781
+ }
10782
+ if (isTriggerTouchEvent && event.type === "mouseenter") {
10783
+ return;
10784
+ }
10752
10785
  Array.from(menuULElement.children).forEach((liElement) => {
10753
10786
  popsDOMUtils.removeClassName(liElement, `pops-${popsType}-is-visited`);
10754
- if (!liElement.__menuData__) {
10787
+ let li_menuData = Reflect.get(liElement, "__menuData__");
10788
+ if (!li_menuData) {
10755
10789
  return;
10756
10790
  }
10757
10791
  function removeElement(element) {
10758
- element.querySelectorAll("ul li").forEach((ele) => {
10759
- if (ele?.__menuData__?.child) {
10760
- removeElement(ele.__menuData__.child);
10792
+ element.querySelectorAll("ul li").forEach(($ele) => {
10793
+ let menuData = Reflect.get($ele, "__menuData__");
10794
+ if (menuData?.child) {
10795
+ removeElement(menuData.child);
10761
10796
  }
10762
10797
  });
10763
10798
  element.remove();
10764
10799
  }
10765
10800
  /* 遍历根元素的上的__menuData__.child,判断 */
10766
- removeElement(liElement.__menuData__.child);
10801
+ removeElement(li_menuData.child);
10767
10802
  });
10768
10803
  /* 清理根元素上的children不存在于页面中的元素 */
10769
- for (let index = 0; index < rootElement.__menuData__.child.length; index++) {
10770
- let element = rootElement.__menuData__.child[index];
10804
+ let root_menuData = Reflect.get(rootElement, "__menuData__");
10805
+ for (let index = 0; index < root_menuData.child.length; index++) {
10806
+ let element = root_menuData.child[index];
10771
10807
  if (!$shadowRoot.contains(element)) {
10772
- rootElement.__menuData__.child.splice(index, 1);
10808
+ root_menuData.child.splice(index, 1);
10773
10809
  index--;
10774
10810
  }
10775
10811
  }
@@ -10782,14 +10818,13 @@
10782
10818
  clientX: rect.left + popsDOMUtils.outerWidth(menuLiElement),
10783
10819
  clientY: rect.top,
10784
10820
  }, item.item, rootElement, menuLiElement, menuListenerRootNode);
10785
- menuLiElement.__menuData__ = {
10821
+ Reflect.set(menuLiElement, "__menuData__", {
10786
10822
  child: childMenu,
10787
- };
10823
+ });
10788
10824
  }
10789
10825
  /**
10790
10826
  * 点击事件
10791
10827
  * @param clickEvent
10792
- * @returns
10793
10828
  */
10794
10829
  async function liElementClickEvent(clickEvent) {
10795
10830
  if (typeof item.callback === "function") {
@@ -10812,9 +10847,9 @@
10812
10847
  });
10813
10848
  PopsContextMenu.closeAllMenu(rootElement);
10814
10849
  }
10815
- popsDOMUtils.on(menuLiElement, "mouseenter touchstart", void 0, liElementHoverEvent);
10850
+ popsDOMUtils.on(menuLiElement, "mouseenter touchstart", liElementHoverEvent);
10816
10851
  /* 项-点击事件 */
10817
- popsDOMUtils.on(menuLiElement, "click", void 0, liElementClickEvent);
10852
+ popsDOMUtils.on(menuLiElement, "click", liElementClickEvent);
10818
10853
  menuULElement.appendChild(menuLiElement);
10819
10854
  });
10820
10855
  },