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