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