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