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