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