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