@whitesev/pops 2.0.11 → 2.0.13
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.amd.js +336 -103
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +336 -103
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +336 -103
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +336 -103
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +336 -103
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +336 -103
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Pops.d.ts +16 -12
- package/dist/types/src/components/rightClickMenu/index.d.ts +1 -1
- package/dist/types/src/components/rightClickMenu/indexType.d.ts +2 -1
- package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +19 -6
- package/dist/types/src/utils/PopsDOMUtils.d.ts +108 -26
- package/package.json +2 -1
- package/src/Pops.ts +1 -1
- package/src/components/rightClickMenu/index.ts +39 -24
- package/src/components/rightClickMenu/indexType.ts +3 -1
- package/src/types/PopsDOMUtilsEventType.d.ts +19 -6
- package/src/utils/PopsDOMUtils.ts +534 -169
package/dist/index.system.js
CHANGED
|
@@ -627,8 +627,9 @@ System.register('pops', [], (function (exports) {
|
|
|
627
627
|
* @param option
|
|
628
628
|
*/
|
|
629
629
|
function getOption(args, startIndex, option) {
|
|
630
|
-
|
|
631
|
-
|
|
630
|
+
let currentParam = args[startIndex];
|
|
631
|
+
if (typeof currentParam === "boolean") {
|
|
632
|
+
option.capture = currentParam;
|
|
632
633
|
if (typeof args[startIndex + 1] === "boolean") {
|
|
633
634
|
option.once = args[startIndex + 1];
|
|
634
635
|
}
|
|
@@ -636,20 +637,22 @@ System.register('pops', [], (function (exports) {
|
|
|
636
637
|
option.passive = args[startIndex + 2];
|
|
637
638
|
}
|
|
638
639
|
}
|
|
639
|
-
else if (typeof
|
|
640
|
-
("capture" in
|
|
641
|
-
"once" in
|
|
642
|
-
"passive" in
|
|
643
|
-
|
|
644
|
-
option.
|
|
645
|
-
option.
|
|
640
|
+
else if (typeof currentParam === "object" &&
|
|
641
|
+
("capture" in currentParam ||
|
|
642
|
+
"once" in currentParam ||
|
|
643
|
+
"passive" in currentParam ||
|
|
644
|
+
"isComposedPath" in currentParam)) {
|
|
645
|
+
option.capture = currentParam.capture;
|
|
646
|
+
option.once = currentParam.once;
|
|
647
|
+
option.passive = currentParam.passive;
|
|
648
|
+
option.isComposedPath = currentParam.isComposedPath;
|
|
646
649
|
}
|
|
647
650
|
return option;
|
|
648
651
|
}
|
|
649
652
|
let DOMUtilsContext = this;
|
|
650
653
|
let args = arguments;
|
|
651
654
|
if (typeof element === "string") {
|
|
652
|
-
element =
|
|
655
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
653
656
|
}
|
|
654
657
|
if (element == null) {
|
|
655
658
|
return;
|
|
@@ -662,88 +665,116 @@ System.register('pops', [], (function (exports) {
|
|
|
662
665
|
else {
|
|
663
666
|
elementList.push(element);
|
|
664
667
|
}
|
|
668
|
+
// 事件名
|
|
665
669
|
let eventTypeList = [];
|
|
666
670
|
if (Array.isArray(eventType)) {
|
|
667
|
-
eventTypeList = eventTypeList.concat(eventType);
|
|
671
|
+
eventTypeList = eventTypeList.concat(eventType.filter((eventTypeItem) => typeof eventTypeItem === "string" && eventTypeItem.toString() !== ""));
|
|
668
672
|
}
|
|
669
673
|
else if (typeof eventType === "string") {
|
|
670
|
-
eventTypeList = eventTypeList.concat(eventType.split(" "));
|
|
674
|
+
eventTypeList = eventTypeList.concat(eventType.split(" ").filter((eventTypeItem) => eventTypeItem !== ""));
|
|
675
|
+
}
|
|
676
|
+
// 子元素选择器
|
|
677
|
+
let selectorList = [];
|
|
678
|
+
if (Array.isArray(selector)) {
|
|
679
|
+
selectorList = selectorList.concat(selector.filter((selectorItem) => typeof selectorItem === "string" && selectorItem.toString() !== ""));
|
|
680
|
+
}
|
|
681
|
+
else if (typeof selector === "string") {
|
|
682
|
+
selectorList.push(selector);
|
|
671
683
|
}
|
|
672
|
-
|
|
673
|
-
let
|
|
674
|
-
|
|
684
|
+
// 事件回调
|
|
685
|
+
let listenerCallBack = callback;
|
|
686
|
+
// 事件配置
|
|
687
|
+
let listenerOption = {
|
|
675
688
|
capture: false,
|
|
676
689
|
once: false,
|
|
677
690
|
passive: false,
|
|
691
|
+
isComposedPath: false,
|
|
678
692
|
};
|
|
679
693
|
if (typeof selector === "function") {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
694
|
+
// 这是为没有selector的情况
|
|
695
|
+
// 那么它就是callback
|
|
696
|
+
listenerCallBack = selector;
|
|
697
|
+
listenerOption = getOption(args, 3, listenerOption);
|
|
684
698
|
}
|
|
685
699
|
else {
|
|
686
|
-
|
|
687
|
-
|
|
700
|
+
// 这是存在selector的情况
|
|
701
|
+
listenerOption = getOption(args, 4, listenerOption);
|
|
688
702
|
}
|
|
689
703
|
/**
|
|
690
704
|
* 如果是once,那么删除该监听和元素上的事件和监听
|
|
691
705
|
*/
|
|
692
706
|
function checkOptionOnceToRemoveEventListener() {
|
|
693
|
-
if (
|
|
707
|
+
if (listenerOption.once) {
|
|
694
708
|
DOMUtilsContext.off(element, eventType, selector, callback, option);
|
|
695
709
|
}
|
|
696
710
|
}
|
|
697
711
|
elementList.forEach((elementItem) => {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
712
|
+
/**
|
|
713
|
+
* 事件回调
|
|
714
|
+
* @param event
|
|
715
|
+
*/
|
|
716
|
+
function domUtilsEventCallBack(event) {
|
|
717
|
+
if (selectorList.length) {
|
|
718
|
+
/* 存在子元素选择器 */
|
|
719
|
+
// 这时候的this和target都是子元素选择器的元素
|
|
720
|
+
let eventTarget = listenerOption.isComposedPath
|
|
721
|
+
? event.composedPath()[0]
|
|
722
|
+
: event.target;
|
|
723
|
+
let totalParent = elementItem;
|
|
724
|
+
if (popsUtils.isWin(totalParent)) {
|
|
725
|
+
if (totalParent === PopsCore.document) {
|
|
726
|
+
totalParent = PopsCore.document.documentElement;
|
|
727
|
+
}
|
|
709
728
|
}
|
|
710
|
-
|
|
711
|
-
|
|
729
|
+
let findValue = selectorList.find((selectorItem) => {
|
|
730
|
+
// 判断目标元素是否匹配选择器
|
|
731
|
+
if (DOMUtilsContext.matches(eventTarget, selectorItem)) {
|
|
732
|
+
/* 当前目标可以被selector所匹配到 */
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
712
735
|
/* 在上层与主元素之间寻找可以被selector所匹配到的 */
|
|
713
|
-
let
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
736
|
+
let $closestMatches = DOMUtilsContext.closest(eventTarget, selectorItem);
|
|
737
|
+
if ($closestMatches && totalParent?.contains($closestMatches)) {
|
|
738
|
+
eventTarget = $closestMatches;
|
|
739
|
+
return true;
|
|
740
|
+
}
|
|
741
|
+
return false;
|
|
742
|
+
});
|
|
743
|
+
if (findValue) {
|
|
744
|
+
// 这里尝试使用defineProperty修改event的target值
|
|
745
|
+
try {
|
|
746
|
+
OriginPrototype.Object.defineProperty(event, "target", {
|
|
747
|
+
get() {
|
|
748
|
+
return eventTarget;
|
|
749
|
+
},
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
catch (error) { }
|
|
753
|
+
listenerCallBack.call(eventTarget, event, eventTarget);
|
|
721
754
|
checkOptionOnceToRemoveEventListener();
|
|
722
755
|
}
|
|
723
756
|
}
|
|
724
757
|
else {
|
|
725
|
-
|
|
758
|
+
// 这时候的this指向监听的元素
|
|
759
|
+
listenerCallBack.call(elementItem, event);
|
|
726
760
|
checkOptionOnceToRemoveEventListener();
|
|
727
761
|
}
|
|
728
762
|
}
|
|
729
763
|
/* 遍历事件名设置元素事件 */
|
|
730
764
|
eventTypeList.forEach((eventName) => {
|
|
731
|
-
elementItem.addEventListener(eventName,
|
|
732
|
-
if (_callback_ && _callback_.delegate) {
|
|
733
|
-
elementItem.setAttribute("data-delegate", _selector_);
|
|
734
|
-
}
|
|
765
|
+
elementItem.addEventListener(eventName, domUtilsEventCallBack, listenerOption);
|
|
735
766
|
/* 获取对象上的事件 */
|
|
736
|
-
let elementEvents = elementItem
|
|
767
|
+
let elementEvents = Reflect.get(elementItem, SymbolEvents) || {};
|
|
737
768
|
/* 初始化对象上的xx事件 */
|
|
738
769
|
elementEvents[eventName] = elementEvents[eventName] || [];
|
|
739
770
|
elementEvents[eventName].push({
|
|
740
|
-
selector:
|
|
741
|
-
option:
|
|
742
|
-
callback:
|
|
743
|
-
originCallBack:
|
|
771
|
+
selector: selectorList,
|
|
772
|
+
option: listenerOption,
|
|
773
|
+
callback: domUtilsEventCallBack,
|
|
774
|
+
originCallBack: listenerCallBack,
|
|
744
775
|
});
|
|
745
776
|
/* 覆盖事件 */
|
|
746
|
-
elementItem
|
|
777
|
+
Reflect.set(elementItem, SymbolEvents, elementEvents);
|
|
747
778
|
});
|
|
748
779
|
});
|
|
749
780
|
}
|
|
@@ -755,18 +786,20 @@ System.register('pops', [], (function (exports) {
|
|
|
755
786
|
* @param option
|
|
756
787
|
*/
|
|
757
788
|
function getOption(args1, startIndex, option) {
|
|
758
|
-
|
|
759
|
-
|
|
789
|
+
let currentParam = args1[startIndex];
|
|
790
|
+
if (typeof currentParam === "boolean") {
|
|
791
|
+
option.capture = currentParam;
|
|
760
792
|
}
|
|
761
|
-
else if (typeof
|
|
762
|
-
"capture" in
|
|
763
|
-
option.capture =
|
|
793
|
+
else if (typeof currentParam === "object" &&
|
|
794
|
+
"capture" in currentParam) {
|
|
795
|
+
option.capture = currentParam.capture;
|
|
764
796
|
}
|
|
765
797
|
return option;
|
|
766
798
|
}
|
|
799
|
+
let DOMUtilsContext = this;
|
|
767
800
|
let args = arguments;
|
|
768
801
|
if (typeof element === "string") {
|
|
769
|
-
element =
|
|
802
|
+
element = DOMUtilsContext.selectorAll(element);
|
|
770
803
|
}
|
|
771
804
|
if (element == null) {
|
|
772
805
|
return;
|
|
@@ -781,37 +814,53 @@ System.register('pops', [], (function (exports) {
|
|
|
781
814
|
}
|
|
782
815
|
let eventTypeList = [];
|
|
783
816
|
if (Array.isArray(eventType)) {
|
|
784
|
-
eventTypeList = eventTypeList.concat(eventType);
|
|
817
|
+
eventTypeList = eventTypeList.concat(eventType.filter((eventTypeItem) => typeof eventTypeItem === "string" && eventTypeItem.toString() !== ""));
|
|
785
818
|
}
|
|
786
819
|
else if (typeof eventType === "string") {
|
|
787
|
-
eventTypeList = eventTypeList.concat(eventType.split(" "));
|
|
820
|
+
eventTypeList = eventTypeList.concat(eventType.split(" ").filter((eventTypeItem) => eventTypeItem !== ""));
|
|
821
|
+
}
|
|
822
|
+
// 子元素选择器
|
|
823
|
+
let selectorList = [];
|
|
824
|
+
if (Array.isArray(selector)) {
|
|
825
|
+
selectorList = selectorList.concat(selector.filter((selectorItem) => typeof selectorItem === "string" && selectorItem.toString() !== ""));
|
|
826
|
+
}
|
|
827
|
+
else if (typeof selector === "string") {
|
|
828
|
+
selectorList.push(selector);
|
|
788
829
|
}
|
|
789
|
-
/**
|
|
790
|
-
* 子元素选择器
|
|
791
|
-
*/
|
|
792
|
-
let _selector_ = selector;
|
|
793
830
|
/**
|
|
794
831
|
* 事件的回调函数
|
|
795
832
|
*/
|
|
796
|
-
let
|
|
833
|
+
let listenerCallBack = callback;
|
|
797
834
|
/**
|
|
798
835
|
* 事件的配置
|
|
799
836
|
*/
|
|
800
|
-
let
|
|
837
|
+
let listenerOption = {
|
|
801
838
|
capture: false,
|
|
802
839
|
};
|
|
803
840
|
if (typeof selector === "function") {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
841
|
+
// 这是为没有selector的情况
|
|
842
|
+
// 那么它就是callback
|
|
843
|
+
listenerCallBack = selector;
|
|
844
|
+
listenerOption = getOption(args, 3, listenerOption);
|
|
808
845
|
}
|
|
809
846
|
else {
|
|
810
|
-
|
|
847
|
+
// 这是存在selector的情况
|
|
848
|
+
listenerOption = getOption(args, 4, listenerOption);
|
|
849
|
+
}
|
|
850
|
+
// 是否移除所有事件
|
|
851
|
+
let isRemoveAll = false;
|
|
852
|
+
if (args.length === 2) {
|
|
853
|
+
// 目标函数、事件名
|
|
854
|
+
isRemoveAll = true;
|
|
855
|
+
}
|
|
856
|
+
else if ((args.length === 3 && typeof args[2] === "string") ||
|
|
857
|
+
Array.isArray(args[2])) {
|
|
858
|
+
// 目标函数、事件名、子元素选择器
|
|
859
|
+
isRemoveAll = true;
|
|
811
860
|
}
|
|
812
861
|
elementList.forEach((elementItem) => {
|
|
813
862
|
/* 获取对象上的事件 */
|
|
814
|
-
let elementEvents = elementItem
|
|
863
|
+
let elementEvents = Reflect.get(elementItem, SymbolEvents) || {};
|
|
815
864
|
eventTypeList.forEach((eventName) => {
|
|
816
865
|
let handlers = elementEvents[eventName] || [];
|
|
817
866
|
if (typeof filter === "function") {
|
|
@@ -819,19 +868,25 @@ System.register('pops', [], (function (exports) {
|
|
|
819
868
|
}
|
|
820
869
|
for (let index = 0; index < handlers.length; index++) {
|
|
821
870
|
let handler = handlers[index];
|
|
822
|
-
let flag =
|
|
823
|
-
if (
|
|
824
|
-
|
|
825
|
-
|
|
871
|
+
let flag = true;
|
|
872
|
+
if (flag &&
|
|
873
|
+
listenerCallBack &&
|
|
874
|
+
handler.originCallBack !== listenerCallBack) {
|
|
875
|
+
// callback不同
|
|
876
|
+
flag = false;
|
|
826
877
|
}
|
|
827
|
-
if (
|
|
828
|
-
handler.
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
878
|
+
if (flag && selectorList.length && Array.isArray(handler.selector)) {
|
|
879
|
+
if (JSON.stringify(handler.selector) !== JSON.stringify(selectorList)) {
|
|
880
|
+
// 子元素选择器不同
|
|
881
|
+
flag = false;
|
|
882
|
+
}
|
|
832
883
|
}
|
|
833
|
-
if (flag) {
|
|
834
|
-
|
|
884
|
+
if (flag && listenerOption.capture !== handler.option.capture) {
|
|
885
|
+
// 事件的配置项不同
|
|
886
|
+
flag = false;
|
|
887
|
+
}
|
|
888
|
+
if (flag || isRemoveAll) {
|
|
889
|
+
elementItem.removeEventListener(eventName, handler.callback, handler.option);
|
|
835
890
|
handlers.splice(index--, 1);
|
|
836
891
|
}
|
|
837
892
|
}
|
|
@@ -840,7 +895,7 @@ System.register('pops', [], (function (exports) {
|
|
|
840
895
|
popsUtils.delete(elementEvents, eventType);
|
|
841
896
|
}
|
|
842
897
|
});
|
|
843
|
-
elementItem
|
|
898
|
+
Reflect.set(elementItem, SymbolEvents, elementEvents);
|
|
844
899
|
});
|
|
845
900
|
}
|
|
846
901
|
/**
|
|
@@ -1245,6 +1300,177 @@ System.register('pops', [], (function (exports) {
|
|
|
1245
1300
|
});
|
|
1246
1301
|
}
|
|
1247
1302
|
}
|
|
1303
|
+
selector(selector) {
|
|
1304
|
+
return this.selectorAll(selector)[0];
|
|
1305
|
+
}
|
|
1306
|
+
selectorAll(selector) {
|
|
1307
|
+
selector = selector.trim();
|
|
1308
|
+
if (selector.match(/[^\s]{1}:empty$/gi)) {
|
|
1309
|
+
// empty 语法
|
|
1310
|
+
selector = selector.replace(/:empty$/gi, "");
|
|
1311
|
+
return Array.from(PopsCore.document.querySelectorAll(selector)).filter(($ele) => {
|
|
1312
|
+
return $ele?.innerHTML?.trim() === "";
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
|
|
1316
|
+
selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
|
|
1317
|
+
// contains 语法
|
|
1318
|
+
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
1319
|
+
let text = textMatch[2];
|
|
1320
|
+
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
1321
|
+
return Array.from(PopsCore.document.querySelectorAll(selector)).filter(($ele) => {
|
|
1322
|
+
// @ts-ignore
|
|
1323
|
+
return ($ele?.textContent || $ele?.innerText)?.includes(text);
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
|
|
1327
|
+
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
|
|
1328
|
+
// regexp 语法
|
|
1329
|
+
let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
|
|
1330
|
+
let pattern = textMatch[2];
|
|
1331
|
+
let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
|
|
1332
|
+
let flags = "";
|
|
1333
|
+
if (flagMatch) {
|
|
1334
|
+
pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
|
|
1335
|
+
flags = flagMatch[3];
|
|
1336
|
+
}
|
|
1337
|
+
let regexp = new RegExp(pattern, flags);
|
|
1338
|
+
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
1339
|
+
return Array.from(PopsCore.document.querySelectorAll(selector)).filter(($ele) => {
|
|
1340
|
+
// @ts-ignore
|
|
1341
|
+
return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
else {
|
|
1345
|
+
// 普通语法
|
|
1346
|
+
return Array.from(PopsCore.document.querySelectorAll(selector));
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* 匹配元素,可使用以下的额外语法
|
|
1351
|
+
*
|
|
1352
|
+
* + :contains([text]) 作用: 找到包含指定文本内容的指定元素
|
|
1353
|
+
* + :empty 作用:找到既没有文本内容也没有子元素的指定元素
|
|
1354
|
+
* + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
|
|
1355
|
+
* @param $el 元素
|
|
1356
|
+
* @param selector 选择器
|
|
1357
|
+
* @example
|
|
1358
|
+
* DOMUtils.matches("div:contains('测试')")
|
|
1359
|
+
* > true
|
|
1360
|
+
* @example
|
|
1361
|
+
* DOMUtils.matches("div:empty")
|
|
1362
|
+
* > true
|
|
1363
|
+
* @example
|
|
1364
|
+
* DOMUtils.matches("div:regexp('^xxxx$')")
|
|
1365
|
+
* > true
|
|
1366
|
+
* @example
|
|
1367
|
+
* DOMUtils.matches("div:regexp(/^xxx/ig)")
|
|
1368
|
+
* > false
|
|
1369
|
+
*/
|
|
1370
|
+
matches($el, selector) {
|
|
1371
|
+
selector = selector.trim();
|
|
1372
|
+
if ($el == null) {
|
|
1373
|
+
return false;
|
|
1374
|
+
}
|
|
1375
|
+
if (selector.match(/[^\s]{1}:empty$/gi)) {
|
|
1376
|
+
// empty 语法
|
|
1377
|
+
selector = selector.replace(/:empty$/gi, "");
|
|
1378
|
+
return $el.matches(selector) && $el?.innerHTML?.trim() === "";
|
|
1379
|
+
}
|
|
1380
|
+
else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
|
|
1381
|
+
selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
|
|
1382
|
+
// contains 语法
|
|
1383
|
+
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
1384
|
+
let text = textMatch[2];
|
|
1385
|
+
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
1386
|
+
// @ts-ignore
|
|
1387
|
+
let content = $el?.textContent || $el?.innerText;
|
|
1388
|
+
if (typeof content !== "string") {
|
|
1389
|
+
content = "";
|
|
1390
|
+
}
|
|
1391
|
+
return $el.matches(selector) && content?.includes(text);
|
|
1392
|
+
}
|
|
1393
|
+
else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
|
|
1394
|
+
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
|
|
1395
|
+
// regexp 语法
|
|
1396
|
+
let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
|
|
1397
|
+
let pattern = textMatch[2];
|
|
1398
|
+
let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
|
|
1399
|
+
let flags = "";
|
|
1400
|
+
if (flagMatch) {
|
|
1401
|
+
pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
|
|
1402
|
+
flags = flagMatch[3];
|
|
1403
|
+
}
|
|
1404
|
+
let regexp = new RegExp(pattern, flags);
|
|
1405
|
+
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
1406
|
+
// @ts-ignore
|
|
1407
|
+
let content = $el?.textContent || $el?.innerText;
|
|
1408
|
+
if (typeof content !== "string") {
|
|
1409
|
+
content = "";
|
|
1410
|
+
}
|
|
1411
|
+
return $el.matches(selector) && Boolean(content?.match(regexp));
|
|
1412
|
+
}
|
|
1413
|
+
else {
|
|
1414
|
+
// 普通语法
|
|
1415
|
+
return $el.matches(selector);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
closest($el, selector) {
|
|
1419
|
+
selector = selector.trim();
|
|
1420
|
+
if (selector.match(/[^\s]{1}:empty$/gi)) {
|
|
1421
|
+
// empty 语法
|
|
1422
|
+
selector = selector.replace(/:empty$/gi, "");
|
|
1423
|
+
let $closest = $el?.closest(selector);
|
|
1424
|
+
if ($closest && $closest?.innerHTML?.trim() === "") {
|
|
1425
|
+
return $closest;
|
|
1426
|
+
}
|
|
1427
|
+
return null;
|
|
1428
|
+
}
|
|
1429
|
+
else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
|
|
1430
|
+
selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
|
|
1431
|
+
// contains 语法
|
|
1432
|
+
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
1433
|
+
let text = textMatch[2];
|
|
1434
|
+
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
1435
|
+
let $closest = $el?.closest(selector);
|
|
1436
|
+
if ($closest) {
|
|
1437
|
+
// @ts-ignore
|
|
1438
|
+
let content = $el?.textContent || $el?.innerText;
|
|
1439
|
+
if (typeof content === "string" && content.includes(text)) {
|
|
1440
|
+
return $closest;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
return null;
|
|
1444
|
+
}
|
|
1445
|
+
else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
|
|
1446
|
+
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
|
|
1447
|
+
// regexp 语法
|
|
1448
|
+
let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
|
|
1449
|
+
let pattern = textMatch[2];
|
|
1450
|
+
let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
|
|
1451
|
+
let flags = "";
|
|
1452
|
+
if (flagMatch) {
|
|
1453
|
+
pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
|
|
1454
|
+
flags = flagMatch[3];
|
|
1455
|
+
}
|
|
1456
|
+
let regexp = new RegExp(pattern, flags);
|
|
1457
|
+
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
1458
|
+
let $closest = $el?.closest(selector);
|
|
1459
|
+
if ($closest) {
|
|
1460
|
+
// @ts-ignore
|
|
1461
|
+
let content = $el?.textContent || $el?.innerText;
|
|
1462
|
+
if (typeof content === "string" && content.match(regexp)) {
|
|
1463
|
+
return $closest;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return null;
|
|
1467
|
+
}
|
|
1468
|
+
else {
|
|
1469
|
+
// 普通语法
|
|
1470
|
+
let $closest = $el?.closest(selector);
|
|
1471
|
+
return $closest;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1248
1474
|
}
|
|
1249
1475
|
class PopsDOMUtils extends PopsDOMUtilsEvent {
|
|
1250
1476
|
/** 获取 animationend 在各个浏览器的兼容名 */
|
|
@@ -9799,8 +10025,9 @@ System.register('pops', [], (function (exports) {
|
|
|
9799
10025
|
/**
|
|
9800
10026
|
* contextmenu事件
|
|
9801
10027
|
* @param event
|
|
10028
|
+
* @param selectorTarget
|
|
9802
10029
|
*/
|
|
9803
|
-
contextMenuEvent(event) {
|
|
10030
|
+
contextMenuEvent(event, selectorTarget) {
|
|
9804
10031
|
if (config.preventDefault) {
|
|
9805
10032
|
popsDOMUtils.preventEvent(event);
|
|
9806
10033
|
}
|
|
@@ -9808,7 +10035,7 @@ System.register('pops', [], (function (exports) {
|
|
|
9808
10035
|
if (PopsContextMenu.rootElement) {
|
|
9809
10036
|
PopsContextMenu.closeAllMenu(PopsContextMenu.rootElement);
|
|
9810
10037
|
}
|
|
9811
|
-
let rootElement = PopsContextMenu.showMenu(event, config.data);
|
|
10038
|
+
let rootElement = PopsContextMenu.showMenu(event, config.data, selectorTarget);
|
|
9812
10039
|
PopsContextMenu.rootElement = rootElement;
|
|
9813
10040
|
if (config.only) {
|
|
9814
10041
|
PopsHandler.handlePush(PopsType, {
|
|
@@ -9848,14 +10075,14 @@ System.register('pops', [], (function (exports) {
|
|
|
9848
10075
|
* 动画结束触发的事件
|
|
9849
10076
|
*/
|
|
9850
10077
|
function transitionEndEvent(event) {
|
|
9851
|
-
popsDOMUtils.off(element, popsDOMUtils.getTransitionEndNameList(),
|
|
10078
|
+
popsDOMUtils.off(element, popsDOMUtils.getTransitionEndNameList(), transitionEndEvent, {
|
|
9852
10079
|
capture: true,
|
|
9853
10080
|
});
|
|
9854
10081
|
element.remove();
|
|
9855
10082
|
}
|
|
9856
10083
|
if (element.classList.contains(`pops-${PopsType}-anim-show`)) {
|
|
9857
10084
|
/* 有动画 */
|
|
9858
|
-
popsDOMUtils.on(element, popsDOMUtils.getTransitionEndNameList(),
|
|
10085
|
+
popsDOMUtils.on(element, popsDOMUtils.getTransitionEndNameList(), transitionEndEvent, {
|
|
9859
10086
|
capture: true,
|
|
9860
10087
|
});
|
|
9861
10088
|
element.classList.remove(`pops-${PopsType}-anim-show`);
|
|
@@ -9946,13 +10173,14 @@ System.register('pops', [], (function (exports) {
|
|
|
9946
10173
|
* 显示菜单
|
|
9947
10174
|
* @param menuEvent 触发的事件
|
|
9948
10175
|
* @param _config_
|
|
10176
|
+
* @param menuListenerRootNode 右键菜单监听的元素
|
|
9949
10177
|
*/
|
|
9950
|
-
showMenu(menuEvent, _config_) {
|
|
10178
|
+
showMenu(menuEvent, _config_, menuListenerRootNode) {
|
|
9951
10179
|
let menuElement = this.getMenuContainerElement(false);
|
|
9952
10180
|
Reflect.set(menuElement, "__menuData__", {
|
|
9953
10181
|
child: [],
|
|
9954
10182
|
});
|
|
9955
|
-
PopsContextMenu.addMenuLiELement(menuEvent, menuElement, menuElement, _config_);
|
|
10183
|
+
PopsContextMenu.addMenuLiELement(menuEvent, menuElement, menuElement, _config_, menuListenerRootNode);
|
|
9956
10184
|
/* 先隐藏 */
|
|
9957
10185
|
popsDOMUtils.css(menuElement, {
|
|
9958
10186
|
display: "none",
|
|
@@ -9984,8 +10212,9 @@ System.register('pops', [], (function (exports) {
|
|
|
9984
10212
|
* @param _config_
|
|
9985
10213
|
* @param rootElement 根菜单元素
|
|
9986
10214
|
* @param targetLiElement 父li项元素
|
|
10215
|
+
* @param menuListenerRootNode 右键菜单监听的元素
|
|
9987
10216
|
*/
|
|
9988
|
-
showClildMenu(menuEvent, posInfo, _config_, rootElement, targetLiElement) {
|
|
10217
|
+
showClildMenu(menuEvent, posInfo, _config_, rootElement, targetLiElement, menuListenerRootNode) {
|
|
9989
10218
|
let menuElement = this.getMenuContainerElement(true);
|
|
9990
10219
|
Reflect.set(menuElement, "__menuData__", {
|
|
9991
10220
|
parent: targetLiElement,
|
|
@@ -9994,7 +10223,7 @@ System.register('pops', [], (function (exports) {
|
|
|
9994
10223
|
// 根菜单数据
|
|
9995
10224
|
let rootElementMenuData = Reflect.get(rootElement, "__menuData__");
|
|
9996
10225
|
rootElementMenuData.child.push(menuElement);
|
|
9997
|
-
PopsContextMenu.addMenuLiELement(menuEvent, rootElement, menuElement, _config_);
|
|
10226
|
+
PopsContextMenu.addMenuLiELement(menuEvent, rootElement, menuElement, _config_, menuListenerRootNode);
|
|
9998
10227
|
/* 先隐藏 */
|
|
9999
10228
|
popsDOMUtils.css(menuElement, {
|
|
10000
10229
|
display: "none",
|
|
@@ -10019,8 +10248,9 @@ System.register('pops', [], (function (exports) {
|
|
|
10019
10248
|
* @param rootElement 根元素
|
|
10020
10249
|
* @param menuElement 菜单元素
|
|
10021
10250
|
* @param _config_ 配置
|
|
10251
|
+
* @param menuListenerRootNode 右键菜单监听的元素
|
|
10022
10252
|
*/
|
|
10023
|
-
addMenuLiELement(menuEvent, rootElement, menuElement, _config_) {
|
|
10253
|
+
addMenuLiELement(menuEvent, rootElement, menuElement, _config_, menuListenerRootNode) {
|
|
10024
10254
|
let menuEventTarget = menuEvent.target;
|
|
10025
10255
|
let menuULElement = menuElement.querySelector("ul");
|
|
10026
10256
|
_config_.forEach((item) => {
|
|
@@ -10074,7 +10304,7 @@ System.register('pops', [], (function (exports) {
|
|
|
10074
10304
|
let childMenu = PopsContextMenu.showClildMenu(menuEvent, {
|
|
10075
10305
|
clientX: rect.left + popsDOMUtils.outerWidth(menuLiElement),
|
|
10076
10306
|
clientY: rect.top,
|
|
10077
|
-
}, item.item, rootElement, menuLiElement);
|
|
10307
|
+
}, item.item, rootElement, menuLiElement, menuListenerRootNode);
|
|
10078
10308
|
menuLiElement.__menuData__ = {
|
|
10079
10309
|
child: childMenu,
|
|
10080
10310
|
};
|
|
@@ -10086,12 +10316,15 @@ System.register('pops', [], (function (exports) {
|
|
|
10086
10316
|
*/
|
|
10087
10317
|
async function liElementClickEvent(clickEvent) {
|
|
10088
10318
|
if (typeof item.callback === "function") {
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10319
|
+
try {
|
|
10320
|
+
OriginPrototype.Object.defineProperty(menuEvent, "target", {
|
|
10321
|
+
get() {
|
|
10322
|
+
return menuEventTarget;
|
|
10323
|
+
},
|
|
10324
|
+
});
|
|
10325
|
+
}
|
|
10326
|
+
catch (error) { }
|
|
10327
|
+
let callbackResult = await item.callback(clickEvent, menuEvent, menuLiElement, menuListenerRootNode);
|
|
10095
10328
|
if (typeof callbackResult === "boolean" &&
|
|
10096
10329
|
callbackResult == false) {
|
|
10097
10330
|
return;
|
|
@@ -10728,7 +10961,7 @@ System.register('pops', [], (function (exports) {
|
|
|
10728
10961
|
/** 配置 */
|
|
10729
10962
|
config = {
|
|
10730
10963
|
/** 版本号 */
|
|
10731
|
-
version: "2025.6.
|
|
10964
|
+
version: "2025.6.6",
|
|
10732
10965
|
cssText: PopsCSS,
|
|
10733
10966
|
/** icon图标的svg代码 */
|
|
10734
10967
|
iconSVG: PopsIcon.$data,
|