customer-chat-sdk 1.1.5 → 1.1.7

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.
@@ -13,7 +13,6 @@ interface IframeOptions {
13
13
  export declare class IframeManager {
14
14
  private config;
15
15
  private iframeElement;
16
- private overlayElement;
17
16
  private containerElement;
18
17
  private isOpen;
19
18
  private isCreated;
@@ -53,14 +52,9 @@ export declare class IframeManager {
53
52
  */
54
53
  sendToIframe(data: any): void;
55
54
  /**
56
- * 清理页面上孤立的遮罩层和容器元素(防止重复创建)
55
+ * 清理页面上孤立的容器元素(防止重复创建)
57
56
  */
58
57
  private cleanupOrphanedElements;
59
- /**
60
- * 创建遮罩层(PC模式使用)
61
- * @param showImmediately 是否立即显示,默认 false(用于 init() 时创建但不显示)
62
- */
63
- private createOverlay;
64
58
  /**
65
59
  * 创建iframe(默认隐藏状态,用于SSE连接)
66
60
  */
@@ -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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188
188
  this.iconElement = null;
189
- this.onClickCallback = null;
189
+ // 注意:不清空 onClickCallback,以便再次显示时能继续使用
190
190
  this.dragMoveHandler = null;
191
191
  this.dragEndHandler = null;
192
192
  if (this.debug) {
@@ -605,7 +605,6 @@ class IconManager {
605
605
  class IframeManager {
606
606
  constructor(config = {}) {
607
607
  this.iframeElement = null;
608
- this.overlayElement = null;
609
608
  this.containerElement = null; // 包装容器,包含iframe和关闭按钮
610
609
  this.isOpen = false;
611
610
  this.isCreated = false;
@@ -627,18 +626,11 @@ class IframeManager {
627
626
  */
628
627
  async init() {
629
628
  try {
630
- // 关键修复:在初始化前,先清理页面上所有旧的遮罩层和容器元素
629
+ // 关键修复:在初始化前,先清理页面上所有旧的容器元素
631
630
  // 防止切换模式或多次初始化时产生重复的元素
632
631
  this.cleanupOrphanedElements();
633
- // PC模式:预创建遮罩层(隐藏状态),避免后续移动DOM导致iframe重新加载
634
- const actualMode = this.getActualMode();
635
- const isPC = actualMode === 'popup';
636
- if (isPC) {
637
- // 创建遮罩层但不立即显示(showImmediately = false)
638
- this.createOverlay(false);
639
- }
640
632
  // 创建隐藏的iframe(预连接到SSE)
641
- // 注意:createIframe 会将容器添加到遮罩层(PC模式)或 body(移动端)
633
+ // 注意:createIframe 会将容器添加到 body
642
634
  this.createIframe();
643
635
  this.isCreated = true;
644
636
  if (this.debug) {
@@ -662,70 +654,24 @@ class IframeManager {
662
654
  throw new Error('Iframe not initialized. Call init() first.');
663
655
  }
664
656
  try {
665
- const actualMode = this.getActualMode();
666
- const isPC = actualMode === 'popup';
667
- // PC模式:创建或显示遮罩层
668
- if (isPC) {
669
- // 如果遮罩层不存在,创建并显示;如果已存在,直接显示
670
- this.createOverlay(true); // showImmediately = true,立即显示
671
- }
672
657
  // 显示已创建的容器
673
658
  // 关键优化:容器在 init() 时已经添加到正确位置,这里只改变样式,不移动 DOM
674
659
  // 这样可以避免 iframe 重新加载
675
660
  if (this.containerElement) {
676
661
  // 确保容器在 DOM 中(理论上已经在 init() 时添加,但为了安全)
677
662
  if (!this.containerElement.parentNode) {
678
- // 如果容器不在 DOM 中(异常情况),根据模式添加到正确位置
679
- if (isPC && this.overlayElement) {
680
- // PC模式:确保遮罩层在 DOM 中,然后将容器添加到遮罩层
681
- if (!this.overlayElement.parentNode) {
682
- document.body.appendChild(this.overlayElement);
683
- }
684
- this.overlayElement.appendChild(this.containerElement);
685
- }
686
- else {
687
- // 移动端模式:直接添加到 body
688
- document.body.appendChild(this.containerElement);
689
- }
690
- }
691
- // 注意:不再检查容器是否在遮罩层内,因为 init() 时已经正确放置
692
- // 如果移动容器会导致 iframe 重新加载,所以不移动
693
- if (isPC) {
694
- // PC模式:配置为居中弹窗样式
695
- Object.assign(this.containerElement.style, {
696
- position: 'fixed',
697
- top: '50%',
698
- left: '50%',
699
- transform: 'translate(-50%, -50%)',
700
- visibility: 'visible',
701
- opacity: '1',
702
- display: 'block'
703
- });
704
- // 显示遮罩层(确保在 DOM 中)
705
- if (this.overlayElement) {
706
- // 确保遮罩层在 DOM 中
707
- if (!this.overlayElement.parentNode) {
708
- document.body.appendChild(this.overlayElement);
709
- }
710
- // 显示遮罩层(只改变样式,不移动)
711
- Object.assign(this.overlayElement.style, {
712
- visibility: 'visible',
713
- opacity: '1',
714
- display: 'flex'
715
- });
716
- }
717
- }
718
- else {
719
- // 移动端模式:直接全屏显示,不需要遮罩层
720
- Object.assign(this.containerElement.style, {
721
- position: 'fixed',
722
- visibility: 'visible',
723
- opacity: '1',
724
- display: 'block'
725
- });
726
- // 禁用body滚动,防止出现滚动条
727
- this.preventBodyScroll(true);
663
+ // 如果容器不在 DOM 中(异常情况),直接添加到 body
664
+ document.body.appendChild(this.containerElement);
728
665
  }
666
+ // PC和移动端都使用全屏模式
667
+ Object.assign(this.containerElement.style, {
668
+ position: 'fixed',
669
+ visibility: 'visible',
670
+ opacity: '1',
671
+ display: 'block'
672
+ });
673
+ // 禁用body滚动,防止出现滚动条
674
+ this.preventBodyScroll(true);
729
675
  }
730
676
  this.isOpen = true;
731
677
  if (this.debug) {
@@ -757,22 +703,10 @@ class IframeManager {
757
703
  opacity: '0',
758
704
  display: 'none'
759
705
  });
760
- // 注意:不移动容器,保持容器在当前位置(遮罩层或 body),避免 iframe 重新加载
761
- }
762
- // 隐藏遮罩层但不移除(仅PC模式,避免重新创建导致 iframe 重新加载)
763
- if (this.overlayElement) {
764
- Object.assign(this.overlayElement.style, {
765
- visibility: 'hidden',
766
- opacity: '0',
767
- display: 'none'
768
- });
769
- // 不移除遮罩层,下次显示时直接显示即可
770
- }
771
- // 恢复body滚动(移动端模式)
772
- const actualModeForScroll = this.getActualMode();
773
- if (actualModeForScroll === 'fullscreen') {
774
- this.preventBodyScroll(false);
706
+ // 注意:不移动容器,保持容器在当前位置(body),避免 iframe 重新加载
775
707
  }
708
+ // 恢复body滚动
709
+ this.preventBodyScroll(false);
776
710
  this.isOpen = false;
777
711
  if (this.debug) {
778
712
  console.log('CustomerSDK iframe hidden (SSE still connected)');
@@ -793,16 +727,12 @@ class IframeManager {
793
727
  */
794
728
  destroy() {
795
729
  this.hide();
796
- // 移除容器和遮罩层
730
+ // 移除容器
797
731
  if (this.containerElement) {
798
732
  this.containerElement.remove();
799
733
  this.containerElement = null;
800
734
  this.iframeElement = null;
801
735
  }
802
- if (this.overlayElement) {
803
- this.overlayElement.remove();
804
- this.overlayElement = null;
805
- }
806
736
  this.isCreated = false;
807
737
  if (this.debug) {
808
738
  console.log('CustomerSDK container destroyed');
@@ -823,19 +753,9 @@ class IframeManager {
823
753
  }
824
754
  }
825
755
  /**
826
- * 清理页面上孤立的遮罩层和容器元素(防止重复创建)
756
+ * 清理页面上孤立的容器元素(防止重复创建)
827
757
  */
828
758
  cleanupOrphanedElements() {
829
- // 清理所有旧的遮罩层元素(不属于当前实例的)
830
- const existingOverlays = document.querySelectorAll('.customer-sdk-overlay');
831
- existingOverlays.forEach((overlay) => {
832
- if (overlay !== this.overlayElement) {
833
- overlay.remove();
834
- if (this.debug) {
835
- console.log('清理旧的遮罩层元素');
836
- }
837
- }
838
- });
839
759
  // 清理所有旧的容器元素(不属于当前实例的)
840
760
  const existingContainers = document.querySelectorAll('.customer-sdk-container');
841
761
  existingContainers.forEach((container) => {
@@ -847,55 +767,6 @@ class IframeManager {
847
767
  }
848
768
  });
849
769
  }
850
- /**
851
- * 创建遮罩层(PC模式使用)
852
- * @param showImmediately 是否立即显示,默认 false(用于 init() 时创建但不显示)
853
- */
854
- createOverlay(showImmediately = false) {
855
- // 如果遮罩层已存在
856
- if (this.overlayElement) {
857
- // 如果不在 DOM 中,添加到 DOM
858
- if (!this.overlayElement.parentNode) {
859
- document.body.appendChild(this.overlayElement);
860
- }
861
- // 根据参数决定是否显示
862
- if (showImmediately) {
863
- Object.assign(this.overlayElement.style, {
864
- visibility: 'visible',
865
- opacity: '1',
866
- display: 'flex'
867
- });
868
- }
869
- return;
870
- }
871
- // 创建新的遮罩层
872
- this.overlayElement = document.createElement('div');
873
- this.overlayElement.className = 'customer-sdk-overlay';
874
- Object.assign(this.overlayElement.style, {
875
- position: 'fixed',
876
- top: '0',
877
- left: '0',
878
- width: '100%',
879
- height: '100%',
880
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
881
- zIndex: '999998',
882
- display: showImmediately ? 'flex' : 'none', // 根据参数决定初始显示状态
883
- alignItems: 'center',
884
- justifyContent: 'center',
885
- cursor: this.config.allowClose ? 'pointer' : 'default',
886
- visibility: showImmediately ? 'visible' : 'hidden',
887
- opacity: showImmediately ? '1' : '0'
888
- });
889
- // 点击遮罩层关闭(只添加一次事件监听器)
890
- if (this.config.allowClose) {
891
- this.overlayElement.addEventListener('click', (e) => {
892
- if (e.target === this.overlayElement) {
893
- this.close();
894
- }
895
- });
896
- }
897
- document.body.appendChild(this.overlayElement);
898
- }
899
770
  /**
900
771
  * 创建iframe(默认隐藏状态,用于SSE连接)
901
772
  */
@@ -941,25 +812,26 @@ class IframeManager {
941
812
  // 根据设备类型设置模式
942
813
  const actualMode = this.getActualMode();
943
814
  const isPC = actualMode === 'popup';
944
- this.iframeElement.scrolling = isPC ? 'auto' : 'no'; // PC显示滚动条,移动端禁用
945
- // PC 模式:使用配置的宽度和高度
946
- // 移动端:使用全屏
815
+ this.iframeElement.scrolling = 'auto'; // PC和移动端都显示滚动条
816
+ // PC模式:使用配置的宽度,高度100%;移动端:100%宽度和高度
947
817
  const containerStyles = isPC ? {
948
- // PC 弹窗模式
818
+ // PC模式:配置的宽度,高度100%
949
819
  width: `${this.config.width || 450}px`,
950
- height: `${this.config.height || 600}px`,
820
+ height: '100%',
951
821
  maxWidth: '90vw',
952
- maxHeight: '90vh',
822
+ maxHeight: '100%',
953
823
  backgroundColor: '#ffffff',
954
- borderRadius: '12px',
955
- boxShadow: '0 20px 40px rgba(0, 0, 0, 0.15)',
824
+ borderRadius: '0',
825
+ boxShadow: 'none',
956
826
  border: 'none',
957
827
  position: 'fixed',
958
828
  zIndex: '999999',
959
- // PC模式:居中显示
960
- top: '50%',
829
+ // PC模式:水平居中,垂直占满
830
+ top: '0',
961
831
  left: '50%',
962
- transform: 'translate(-50%, -50%)',
832
+ bottom: '0',
833
+ right: 'auto',
834
+ transform: 'translateX(-50%)',
963
835
  overflow: 'hidden',
964
836
  // 初始隐藏的关键样式
965
837
  visibility: 'hidden',
@@ -995,35 +867,20 @@ class IframeManager {
995
867
  width: '100%',
996
868
  height: '100%',
997
869
  border: 'none',
998
- borderRadius: 'inherit',
999
- ...(isPC ? {} : {
1000
- // 移动端:彻底禁用滚动条
1001
- overflow: 'hidden',
1002
- scrollbarWidth: 'none', // Firefox
1003
- msOverflowStyle: 'none', // IE/Edge
1004
- WebkitScrollbar: 'none' // WebKit (Chrome/Safari)
1005
- })
870
+ borderRadius: 'inherit'
1006
871
  };
1007
872
  Object.assign(this.iframeElement.style, iframeStyles);
1008
873
  // 将iframe放入容器
1009
874
  this.containerElement.appendChild(this.iframeElement);
1010
875
  // 添加iframe加载事件监听(移动端样式优化)
1011
876
  this.iframeElement.addEventListener('load', () => {
1012
- // 仅在移动端注入自定义样式
877
+ // 移动端注入自定义样式
1013
878
  if (!isPC) {
1014
879
  this.injectMobileStyles();
1015
880
  }
1016
881
  });
1017
- // 关键优化:PC模式将容器添加到遮罩层(如果遮罩层已创建),避免后续移动DOM导致iframe重新加载
1018
- // 移动端直接添加到body
1019
- if (isPC && this.overlayElement) {
1020
- // PC模式:添加到遮罩层(遮罩层已在 init() 中创建)
1021
- this.overlayElement.appendChild(this.containerElement);
1022
- }
1023
- else {
1024
- // 移动端模式:直接添加到body
1025
- document.body.appendChild(this.containerElement);
1026
- }
882
+ // 关键优化:容器直接添加到body,避免后续移动DOM导致iframe重新加载
883
+ document.body.appendChild(this.containerElement);
1027
884
  if (this.debug) {
1028
885
  console.log('CustomerSDK container created (hidden, ready for SSE)');
1029
886
  }
@@ -20940,19 +20797,33 @@ class CustomerServiceSDK {
20940
20797
  * 初始化 SDK
20941
20798
  * @param config SDK配置
20942
20799
  * @param options UI选项(可选)
20800
+ * @param forceReinit 是否强制重新初始化(用于更新token等配置)
20943
20801
  * @returns 返回初始化信息(包含设备ID等)
20944
20802
  */
20945
- async init(config, options) {
20946
- if (this.isInitialized) {
20803
+ async init(config, options, forceReinit = false) {
20804
+ // 如果已经初始化且不强制重新初始化,返回之前保存的初始化信息
20805
+ if (this.isInitialized && !forceReinit) {
20947
20806
  if (this.debug) {
20948
- console.warn('CustomerSDK already initialized');
20807
+ console.warn('CustomerSDK already initialized, returning cached result. Use forceReinit=true to reinitialize.');
20949
20808
  }
20950
- // 如果已经初始化,返回之前保存的初始化信息
20951
20809
  if (this.initResult) {
20952
20810
  return this.initResult;
20953
20811
  }
20954
20812
  throw new Error('SDK already initialized but cannot retrieve initialization info');
20955
20813
  }
20814
+ // 如果需要强制重新初始化,先清理旧资源
20815
+ if (this.isInitialized && forceReinit) {
20816
+ if (this.debug) {
20817
+ console.log('Force reinitializing SDK...');
20818
+ }
20819
+ // 清理旧的 iframe 和截图管理器,但保留图标管理器(保持图标位置等状态)
20820
+ this.iframeManager?.destroy();
20821
+ this.screenshotManager?.destroy();
20822
+ this.iframeManager = null;
20823
+ this.screenshotManager = null;
20824
+ // 重置初始化标志,但保留图标管理器
20825
+ this.isInitialized = false;
20826
+ }
20956
20827
  this.config = config;
20957
20828
  this.debug = config.debug ?? false;
20958
20829
  try {
@@ -20993,9 +20864,9 @@ class CustomerServiceSDK {
20993
20864
  // checkScreenshot 消息由 ScreenshotManager 处理,不需要在这里处理
20994
20865
  },
20995
20866
  onClose: () => {
20996
- // iframe关闭时,清理图标拖动事件监听器,并重新启用图标点击
20867
+ // iframe关闭时,清理图标拖动事件监听器,并重新显示图标
20997
20868
  this.iconManager?.forceCleanupDragEvents();
20998
- this.iconManager?.enableClick();
20869
+ this.iconManager?.show();
20999
20870
  },
21000
20871
  ...options
21001
20872
  });
@@ -21005,9 +20876,9 @@ class CustomerServiceSDK {
21005
20876
  this.iconManager.onClick(() => {
21006
20877
  // 打开iframe时清除红点通知
21007
20878
  this.clearNotification();
20879
+ // 点击图标后隐藏图标
20880
+ this.iconManager?.hide();
21008
20881
  this.iframeManager?.show();
21009
- // iframe 打开后,禁用图标点击(防止重复打开)
21010
- this.iconManager?.disableClick();
21011
20882
  });
21012
20883
  // 初始化截图管理器(如果启用了截图功能)
21013
20884
  if (config.screenshot) {
@@ -21186,6 +21057,31 @@ class CustomerServiceSDK {
21186
21057
  console.log('📸 截图配置已更新:', options);
21187
21058
  }
21188
21059
  }
21060
+ /**
21061
+ * 更新 token(用于用户登录/退出场景)
21062
+ * 如果已初始化,会重新创建 iframe 并更新 URL
21063
+ * @param token 新的 token(传空字符串或 undefined 表示移除 token)
21064
+ * @param options UI选项(可选,用于重新初始化时的配置)
21065
+ * @returns 返回更新后的初始化信息
21066
+ */
21067
+ async updateToken(token, options) {
21068
+ if (!this.isInitialized) {
21069
+ throw new Error('SDK not initialized. Call init() first.');
21070
+ }
21071
+ if (!this.config) {
21072
+ throw new Error('SDK config not found');
21073
+ }
21074
+ // 更新配置中的 token
21075
+ const updatedConfig = {
21076
+ ...this.config,
21077
+ token: token && token.trim() !== '' ? token : undefined
21078
+ };
21079
+ if (this.debug) {
21080
+ console.log('Updating token:', token ? 'Token provided' : 'Token removed');
21081
+ }
21082
+ // 强制重新初始化以应用新的 token
21083
+ return await this.init(updatedConfig, options, true);
21084
+ }
21189
21085
  /**
21190
21086
  * 销毁 SDK
21191
21087
  */
@@ -21269,13 +21165,14 @@ let globalSDKInstance = null;
21269
21165
  * 初始化 Customer SDK
21270
21166
  * @param config SDK配置
21271
21167
  * @param options UI选项(可选)
21168
+ * @param forceReinit 是否强制重新初始化(用于更新token等配置)
21272
21169
  * @returns 返回初始化信息(包含设备ID等)
21273
21170
  */
21274
- const init = async (config, options) => {
21171
+ const init = async (config, options, forceReinit = false) => {
21275
21172
  if (!globalSDKInstance) {
21276
21173
  globalSDKInstance = new CustomerServiceSDK();
21277
21174
  }
21278
- return await globalSDKInstance.init(config, options);
21175
+ return await globalSDKInstance.init(config, options, forceReinit);
21279
21176
  };
21280
21177
  /**
21281
21178
  * 获取全局SDK实例
@@ -21384,6 +21281,16 @@ const updateScreenshotOptions = (options) => {
21384
21281
  const sdk = getInstance();
21385
21282
  sdk.updateScreenshotOptions(options);
21386
21283
  };
21284
+ /**
21285
+ * 更新 token(用于用户登录/退出场景)
21286
+ * @param token 新的 token(传空字符串或 undefined 表示移除 token)
21287
+ * @param options UI选项(可选)
21288
+ * @returns 返回更新后的初始化信息
21289
+ */
21290
+ const updateToken = async (token, options) => {
21291
+ const sdk = getInstance();
21292
+ return await sdk.updateToken(token, options);
21293
+ };
21387
21294
  // 默认导出
21388
21295
  var index = {
21389
21296
  init,
@@ -21406,6 +21313,7 @@ var index = {
21406
21313
  enableScreenshot,
21407
21314
  getScreenshotState,
21408
21315
  updateScreenshotOptions,
21316
+ updateToken,
21409
21317
  destroy
21410
21318
  };
21411
21319
 
@@ -21432,3 +21340,4 @@ exports.setScreenshotTarget = setScreenshotTarget;
21432
21340
  exports.showIcon = showIcon;
21433
21341
  exports.showNotification = showNotification;
21434
21342
  exports.updateScreenshotOptions = updateScreenshotOptions;
21343
+ exports.updateToken = updateToken;