customer-chat-sdk 1.1.2 → 1.1.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeManager.d.ts","sourceRoot":"","sources":["../../src/core/IframeManager.ts"],"names":[],"mappings":"AACA,UAAU,aAAa;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,OAAO,CAAA;IACtC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,IAAI,CAAA;IACpD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,aAAa,CAAiC;IACtD,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,KAAK,CAAiB;gBAElB,MAAM,GAAE,aAAkB;IActC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"IframeManager.d.ts","sourceRoot":"","sources":["../../src/core/IframeManager.ts"],"names":[],"mappings":"AACA,UAAU,aAAa;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,OAAO,CAAA;IACtC,KAAK,CAAC,EAAE,MAAM,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AAC,mBAAmB;IAwD3B;;OAEG;IACH,OAAO,CAAC,YAAY;CAMrB"}
|
package/dist/customer-sdk.cjs.js
CHANGED
|
@@ -627,7 +627,15 @@ class IframeManager {
|
|
|
627
627
|
*/
|
|
628
628
|
async init() {
|
|
629
629
|
try {
|
|
630
|
+
// PC模式:预创建遮罩层(隐藏状态),避免后续移动DOM导致iframe重新加载
|
|
631
|
+
const actualMode = this.getActualMode();
|
|
632
|
+
const isPC = actualMode === 'popup';
|
|
633
|
+
if (isPC) {
|
|
634
|
+
// 创建遮罩层但不立即显示(showImmediately = false)
|
|
635
|
+
this.createOverlay(false);
|
|
636
|
+
}
|
|
630
637
|
// 创建隐藏的iframe(预连接到SSE)
|
|
638
|
+
// 注意:createIframe 会将容器添加到遮罩层(PC模式)或 body(移动端)
|
|
631
639
|
this.createIframe();
|
|
632
640
|
this.isCreated = true;
|
|
633
641
|
if (this.debug) {
|
|
@@ -655,10 +663,30 @@ class IframeManager {
|
|
|
655
663
|
const isPC = actualMode === 'popup';
|
|
656
664
|
// PC模式:创建或显示遮罩层
|
|
657
665
|
if (isPC) {
|
|
658
|
-
|
|
666
|
+
// 如果遮罩层不存在,创建并显示;如果已存在,直接显示
|
|
667
|
+
this.createOverlay(true); // showImmediately = true,立即显示
|
|
659
668
|
}
|
|
660
669
|
// 显示已创建的容器
|
|
670
|
+
// 关键优化:容器在 init() 时已经添加到正确位置,这里只改变样式,不移动 DOM
|
|
671
|
+
// 这样可以避免 iframe 重新加载
|
|
661
672
|
if (this.containerElement) {
|
|
673
|
+
// 确保容器在 DOM 中(理论上已经在 init() 时添加,但为了安全)
|
|
674
|
+
if (!this.containerElement.parentNode) {
|
|
675
|
+
// 如果容器不在 DOM 中(异常情况),根据模式添加到正确位置
|
|
676
|
+
if (isPC && this.overlayElement) {
|
|
677
|
+
// PC模式:确保遮罩层在 DOM 中,然后将容器添加到遮罩层
|
|
678
|
+
if (!this.overlayElement.parentNode) {
|
|
679
|
+
document.body.appendChild(this.overlayElement);
|
|
680
|
+
}
|
|
681
|
+
this.overlayElement.appendChild(this.containerElement);
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
// 移动端模式:直接添加到 body
|
|
685
|
+
document.body.appendChild(this.containerElement);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
// 注意:不再检查容器是否在遮罩层内,因为 init() 时已经正确放置
|
|
689
|
+
// 如果移动容器会导致 iframe 重新加载,所以不移动
|
|
662
690
|
if (isPC) {
|
|
663
691
|
// PC模式:配置为居中弹窗样式
|
|
664
692
|
Object.assign(this.containerElement.style, {
|
|
@@ -670,17 +698,18 @@ class IframeManager {
|
|
|
670
698
|
opacity: '1',
|
|
671
699
|
display: 'block'
|
|
672
700
|
});
|
|
673
|
-
//
|
|
674
|
-
// 只有当容器不在遮罩层内时才移动,且确保遮罩层在 DOM 中
|
|
701
|
+
// 显示遮罩层(确保在 DOM 中)
|
|
675
702
|
if (this.overlayElement) {
|
|
676
|
-
//
|
|
703
|
+
// 确保遮罩层在 DOM 中
|
|
677
704
|
if (!this.overlayElement.parentNode) {
|
|
678
705
|
document.body.appendChild(this.overlayElement);
|
|
679
706
|
}
|
|
680
|
-
//
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
707
|
+
// 显示遮罩层(只改变样式,不移动)
|
|
708
|
+
Object.assign(this.overlayElement.style, {
|
|
709
|
+
visibility: 'visible',
|
|
710
|
+
opacity: '1',
|
|
711
|
+
display: 'flex'
|
|
712
|
+
});
|
|
684
713
|
}
|
|
685
714
|
}
|
|
686
715
|
else {
|
|
@@ -761,11 +790,16 @@ class IframeManager {
|
|
|
761
790
|
*/
|
|
762
791
|
destroy() {
|
|
763
792
|
this.hide();
|
|
793
|
+
// 移除容器和遮罩层
|
|
764
794
|
if (this.containerElement) {
|
|
765
795
|
this.containerElement.remove();
|
|
766
796
|
this.containerElement = null;
|
|
767
797
|
this.iframeElement = null;
|
|
768
798
|
}
|
|
799
|
+
if (this.overlayElement) {
|
|
800
|
+
this.overlayElement.remove();
|
|
801
|
+
this.overlayElement = null;
|
|
802
|
+
}
|
|
769
803
|
this.isCreated = false;
|
|
770
804
|
if (this.debug) {
|
|
771
805
|
console.log('CustomerSDK container destroyed');
|
|
@@ -787,25 +821,23 @@ class IframeManager {
|
|
|
787
821
|
}
|
|
788
822
|
/**
|
|
789
823
|
* 创建遮罩层(PC模式使用)
|
|
824
|
+
* @param showImmediately 是否立即显示,默认 false(用于 init() 时创建但不显示)
|
|
790
825
|
*/
|
|
791
|
-
createOverlay() {
|
|
792
|
-
//
|
|
793
|
-
if (this.overlayElement
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
opacity: '1',
|
|
807
|
-
display: 'flex'
|
|
808
|
-
});
|
|
826
|
+
createOverlay(showImmediately = false) {
|
|
827
|
+
// 如果遮罩层已存在
|
|
828
|
+
if (this.overlayElement) {
|
|
829
|
+
// 如果不在 DOM 中,添加到 DOM
|
|
830
|
+
if (!this.overlayElement.parentNode) {
|
|
831
|
+
document.body.appendChild(this.overlayElement);
|
|
832
|
+
}
|
|
833
|
+
// 根据参数决定是否显示
|
|
834
|
+
if (showImmediately) {
|
|
835
|
+
Object.assign(this.overlayElement.style, {
|
|
836
|
+
visibility: 'visible',
|
|
837
|
+
opacity: '1',
|
|
838
|
+
display: 'flex'
|
|
839
|
+
});
|
|
840
|
+
}
|
|
809
841
|
return;
|
|
810
842
|
}
|
|
811
843
|
// 创建新的遮罩层
|
|
@@ -819,10 +851,12 @@ class IframeManager {
|
|
|
819
851
|
height: '100%',
|
|
820
852
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
821
853
|
zIndex: '999998',
|
|
822
|
-
display: 'flex',
|
|
854
|
+
display: showImmediately ? 'flex' : 'none', // 根据参数决定初始显示状态
|
|
823
855
|
alignItems: 'center',
|
|
824
856
|
justifyContent: 'center',
|
|
825
|
-
cursor: this.config.allowClose ? 'pointer' : 'default'
|
|
857
|
+
cursor: this.config.allowClose ? 'pointer' : 'default',
|
|
858
|
+
visibility: showImmediately ? 'visible' : 'hidden',
|
|
859
|
+
opacity: showImmediately ? '1' : '0'
|
|
826
860
|
});
|
|
827
861
|
// 点击遮罩层关闭(只添加一次事件监听器)
|
|
828
862
|
if (this.config.allowClose) {
|
|
@@ -952,8 +986,16 @@ class IframeManager {
|
|
|
952
986
|
this.injectMobileStyles();
|
|
953
987
|
}
|
|
954
988
|
});
|
|
955
|
-
//
|
|
956
|
-
|
|
989
|
+
// 关键优化:PC模式将容器添加到遮罩层(如果遮罩层已创建),避免后续移动DOM导致iframe重新加载
|
|
990
|
+
// 移动端直接添加到body
|
|
991
|
+
if (isPC && this.overlayElement) {
|
|
992
|
+
// PC模式:添加到遮罩层(遮罩层已在 init() 中创建)
|
|
993
|
+
this.overlayElement.appendChild(this.containerElement);
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
// 移动端模式:直接添加到body
|
|
997
|
+
document.body.appendChild(this.containerElement);
|
|
998
|
+
}
|
|
957
999
|
if (this.debug) {
|
|
958
1000
|
console.log('CustomerSDK container created (hidden, ready for SSE)');
|
|
959
1001
|
}
|
package/dist/customer-sdk.esm.js
CHANGED
|
@@ -623,7 +623,15 @@ class IframeManager {
|
|
|
623
623
|
*/
|
|
624
624
|
async init() {
|
|
625
625
|
try {
|
|
626
|
+
// PC模式:预创建遮罩层(隐藏状态),避免后续移动DOM导致iframe重新加载
|
|
627
|
+
const actualMode = this.getActualMode();
|
|
628
|
+
const isPC = actualMode === 'popup';
|
|
629
|
+
if (isPC) {
|
|
630
|
+
// 创建遮罩层但不立即显示(showImmediately = false)
|
|
631
|
+
this.createOverlay(false);
|
|
632
|
+
}
|
|
626
633
|
// 创建隐藏的iframe(预连接到SSE)
|
|
634
|
+
// 注意:createIframe 会将容器添加到遮罩层(PC模式)或 body(移动端)
|
|
627
635
|
this.createIframe();
|
|
628
636
|
this.isCreated = true;
|
|
629
637
|
if (this.debug) {
|
|
@@ -651,10 +659,30 @@ class IframeManager {
|
|
|
651
659
|
const isPC = actualMode === 'popup';
|
|
652
660
|
// PC模式:创建或显示遮罩层
|
|
653
661
|
if (isPC) {
|
|
654
|
-
|
|
662
|
+
// 如果遮罩层不存在,创建并显示;如果已存在,直接显示
|
|
663
|
+
this.createOverlay(true); // showImmediately = true,立即显示
|
|
655
664
|
}
|
|
656
665
|
// 显示已创建的容器
|
|
666
|
+
// 关键优化:容器在 init() 时已经添加到正确位置,这里只改变样式,不移动 DOM
|
|
667
|
+
// 这样可以避免 iframe 重新加载
|
|
657
668
|
if (this.containerElement) {
|
|
669
|
+
// 确保容器在 DOM 中(理论上已经在 init() 时添加,但为了安全)
|
|
670
|
+
if (!this.containerElement.parentNode) {
|
|
671
|
+
// 如果容器不在 DOM 中(异常情况),根据模式添加到正确位置
|
|
672
|
+
if (isPC && this.overlayElement) {
|
|
673
|
+
// PC模式:确保遮罩层在 DOM 中,然后将容器添加到遮罩层
|
|
674
|
+
if (!this.overlayElement.parentNode) {
|
|
675
|
+
document.body.appendChild(this.overlayElement);
|
|
676
|
+
}
|
|
677
|
+
this.overlayElement.appendChild(this.containerElement);
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
// 移动端模式:直接添加到 body
|
|
681
|
+
document.body.appendChild(this.containerElement);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
// 注意:不再检查容器是否在遮罩层内,因为 init() 时已经正确放置
|
|
685
|
+
// 如果移动容器会导致 iframe 重新加载,所以不移动
|
|
658
686
|
if (isPC) {
|
|
659
687
|
// PC模式:配置为居中弹窗样式
|
|
660
688
|
Object.assign(this.containerElement.style, {
|
|
@@ -666,17 +694,18 @@ class IframeManager {
|
|
|
666
694
|
opacity: '1',
|
|
667
695
|
display: 'block'
|
|
668
696
|
});
|
|
669
|
-
//
|
|
670
|
-
// 只有当容器不在遮罩层内时才移动,且确保遮罩层在 DOM 中
|
|
697
|
+
// 显示遮罩层(确保在 DOM 中)
|
|
671
698
|
if (this.overlayElement) {
|
|
672
|
-
//
|
|
699
|
+
// 确保遮罩层在 DOM 中
|
|
673
700
|
if (!this.overlayElement.parentNode) {
|
|
674
701
|
document.body.appendChild(this.overlayElement);
|
|
675
702
|
}
|
|
676
|
-
//
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
703
|
+
// 显示遮罩层(只改变样式,不移动)
|
|
704
|
+
Object.assign(this.overlayElement.style, {
|
|
705
|
+
visibility: 'visible',
|
|
706
|
+
opacity: '1',
|
|
707
|
+
display: 'flex'
|
|
708
|
+
});
|
|
680
709
|
}
|
|
681
710
|
}
|
|
682
711
|
else {
|
|
@@ -757,11 +786,16 @@ class IframeManager {
|
|
|
757
786
|
*/
|
|
758
787
|
destroy() {
|
|
759
788
|
this.hide();
|
|
789
|
+
// 移除容器和遮罩层
|
|
760
790
|
if (this.containerElement) {
|
|
761
791
|
this.containerElement.remove();
|
|
762
792
|
this.containerElement = null;
|
|
763
793
|
this.iframeElement = null;
|
|
764
794
|
}
|
|
795
|
+
if (this.overlayElement) {
|
|
796
|
+
this.overlayElement.remove();
|
|
797
|
+
this.overlayElement = null;
|
|
798
|
+
}
|
|
765
799
|
this.isCreated = false;
|
|
766
800
|
if (this.debug) {
|
|
767
801
|
console.log('CustomerSDK container destroyed');
|
|
@@ -783,25 +817,23 @@ class IframeManager {
|
|
|
783
817
|
}
|
|
784
818
|
/**
|
|
785
819
|
* 创建遮罩层(PC模式使用)
|
|
820
|
+
* @param showImmediately 是否立即显示,默认 false(用于 init() 时创建但不显示)
|
|
786
821
|
*/
|
|
787
|
-
createOverlay() {
|
|
788
|
-
//
|
|
789
|
-
if (this.overlayElement
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
opacity: '1',
|
|
803
|
-
display: 'flex'
|
|
804
|
-
});
|
|
822
|
+
createOverlay(showImmediately = false) {
|
|
823
|
+
// 如果遮罩层已存在
|
|
824
|
+
if (this.overlayElement) {
|
|
825
|
+
// 如果不在 DOM 中,添加到 DOM
|
|
826
|
+
if (!this.overlayElement.parentNode) {
|
|
827
|
+
document.body.appendChild(this.overlayElement);
|
|
828
|
+
}
|
|
829
|
+
// 根据参数决定是否显示
|
|
830
|
+
if (showImmediately) {
|
|
831
|
+
Object.assign(this.overlayElement.style, {
|
|
832
|
+
visibility: 'visible',
|
|
833
|
+
opacity: '1',
|
|
834
|
+
display: 'flex'
|
|
835
|
+
});
|
|
836
|
+
}
|
|
805
837
|
return;
|
|
806
838
|
}
|
|
807
839
|
// 创建新的遮罩层
|
|
@@ -815,10 +847,12 @@ class IframeManager {
|
|
|
815
847
|
height: '100%',
|
|
816
848
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
817
849
|
zIndex: '999998',
|
|
818
|
-
display: 'flex',
|
|
850
|
+
display: showImmediately ? 'flex' : 'none', // 根据参数决定初始显示状态
|
|
819
851
|
alignItems: 'center',
|
|
820
852
|
justifyContent: 'center',
|
|
821
|
-
cursor: this.config.allowClose ? 'pointer' : 'default'
|
|
853
|
+
cursor: this.config.allowClose ? 'pointer' : 'default',
|
|
854
|
+
visibility: showImmediately ? 'visible' : 'hidden',
|
|
855
|
+
opacity: showImmediately ? '1' : '0'
|
|
822
856
|
});
|
|
823
857
|
// 点击遮罩层关闭(只添加一次事件监听器)
|
|
824
858
|
if (this.config.allowClose) {
|
|
@@ -948,8 +982,16 @@ class IframeManager {
|
|
|
948
982
|
this.injectMobileStyles();
|
|
949
983
|
}
|
|
950
984
|
});
|
|
951
|
-
//
|
|
952
|
-
|
|
985
|
+
// 关键优化:PC模式将容器添加到遮罩层(如果遮罩层已创建),避免后续移动DOM导致iframe重新加载
|
|
986
|
+
// 移动端直接添加到body
|
|
987
|
+
if (isPC && this.overlayElement) {
|
|
988
|
+
// PC模式:添加到遮罩层(遮罩层已在 init() 中创建)
|
|
989
|
+
this.overlayElement.appendChild(this.containerElement);
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
// 移动端模式:直接添加到body
|
|
993
|
+
document.body.appendChild(this.containerElement);
|
|
994
|
+
}
|
|
953
995
|
if (this.debug) {
|
|
954
996
|
console.log('CustomerSDK container created (hidden, ready for SSE)');
|
|
955
997
|
}
|