@microsoft/omnichannel-chat-widget 1.8.3-main.ec1328d → 1.8.4-main.4478bbf

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.
Files changed (185) hide show
  1. package/lib/cjs/common/Constants.js +7 -0
  2. package/lib/cjs/common/facades/FacadeChatSDK.js +6 -0
  3. package/lib/cjs/common/telemetry/AppInsightsEvents.js +4 -5
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +46 -2
  5. package/lib/cjs/common/telemetry/loggers/appInsightsLogger.js +26 -10
  6. package/lib/cjs/common/utils/SecureEventBus.js +307 -0
  7. package/lib/cjs/common/utils/dispatchCustomEvent.js +25 -0
  8. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +16 -4
  9. package/lib/cjs/components/citationpanestateful/CitationDim.js +29 -0
  10. package/lib/cjs/components/citationpanestateful/CitationPaneStateful.js +199 -0
  11. package/lib/cjs/components/citationpanestateful/common/defaultProps/defaultCitationPaneProps.js +70 -0
  12. package/lib/cjs/components/confirmationpanestateful/interfaces/IConfirmationPaneLocalizedTexts.js +1 -0
  13. package/lib/cjs/components/headerstateful/HeaderStateful.js +8 -2
  14. package/lib/cjs/components/livechatwidget/LiveChatWidget.js +4 -4
  15. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.js +127 -0
  16. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +4 -5
  17. package/lib/cjs/components/livechatwidget/common/ChatWidgetEvents.js +15 -0
  18. package/lib/cjs/components/livechatwidget/common/PersistentConversationHandler.js +284 -0
  19. package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
  20. package/lib/cjs/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +18 -0
  21. package/lib/cjs/components/livechatwidget/common/endChat.js +28 -3
  22. package/lib/cjs/components/livechatwidget/common/getMockChatSDKIfApplicable.js +4 -3
  23. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -6
  24. package/lib/cjs/components/livechatwidget/common/overridePropsOnMockIfApplicable.js +2 -1
  25. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +2 -2
  26. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -3
  27. package/lib/cjs/components/livechatwidget/common/startChat.js +10 -5
  28. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +24 -4
  29. package/lib/cjs/components/livechatwidget/interfaces/IMockProps.js +8 -2
  30. package/lib/cjs/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
  31. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +41 -8
  32. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +29 -2
  33. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +12 -3
  34. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +122 -11
  35. package/lib/cjs/components/webchatcontainerstateful/common/DesignerChatAdapter.js +43 -14
  36. package/lib/cjs/components/webchatcontainerstateful/common/DesignerChatSDK.js +6 -1
  37. package/lib/cjs/components/webchatcontainerstateful/common/activities/botActivity.js +14 -0
  38. package/lib/cjs/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js +17 -0
  39. package/lib/cjs/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +97 -0
  40. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
  41. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +1 -1
  42. package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultWebChatStyles.js +1 -1
  43. package/lib/cjs/components/webchatcontainerstateful/common/utils/chatAdapterUtils.js +36 -2
  44. package/lib/cjs/components/webchatcontainerstateful/common/utils/fontUtils.js +28 -0
  45. package/lib/cjs/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +59 -0
  46. package/lib/cjs/components/webchatcontainerstateful/interfaces/ICitation.js +1 -0
  47. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +122 -0
  48. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.js +10 -0
  49. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +18 -0
  50. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1038 -0
  51. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +34 -0
  52. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +44 -0
  53. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +16 -2
  54. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultAvatarTextStyles.js +1 -1
  55. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.js +20 -0
  56. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageStyles.js +1 -1
  57. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +2 -2
  58. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.js +59 -0
  59. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +5 -3
  60. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -2
  61. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.js +97 -30
  62. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/queueOverflowHandlerMiddleware.js +2 -2
  63. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +46 -45
  64. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -0
  65. package/lib/cjs/contexts/createReducer.js +15 -0
  66. package/lib/cjs/firstresponselatency/FirstMessageTrackerFromBot.js +3 -2
  67. package/lib/cjs/firstresponselatency/FirstResponseLatencyTracker.js +6 -2
  68. package/lib/cjs/index.js +9 -1
  69. package/lib/cjs/plugins/newMessageEventHandler.js +4 -1
  70. package/lib/esm/common/Constants.js +7 -0
  71. package/lib/esm/common/facades/FacadeChatSDK.js +6 -0
  72. package/lib/esm/common/telemetry/AppInsightsEvents.js +4 -5
  73. package/lib/esm/common/telemetry/TelemetryConstants.js +44 -1
  74. package/lib/esm/common/telemetry/loggers/appInsightsLogger.js +27 -11
  75. package/lib/esm/common/utils/SecureEventBus.js +328 -0
  76. package/lib/esm/common/utils/dispatchCustomEvent.js +18 -0
  77. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +17 -5
  78. package/lib/esm/components/citationpanestateful/CitationDim.js +20 -0
  79. package/lib/esm/components/citationpanestateful/CitationPaneStateful.js +188 -0
  80. package/lib/esm/components/citationpanestateful/common/defaultProps/defaultCitationPaneProps.js +61 -0
  81. package/lib/esm/components/confirmationpanestateful/interfaces/IConfirmationPaneLocalizedTexts.js +1 -0
  82. package/lib/esm/components/headerstateful/HeaderStateful.js +9 -3
  83. package/lib/esm/components/livechatwidget/LiveChatWidget.js +4 -4
  84. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.js +120 -0
  85. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +4 -5
  86. package/lib/esm/components/livechatwidget/common/ChatWidgetEvents.js +8 -0
  87. package/lib/esm/components/livechatwidget/common/PersistentConversationHandler.js +277 -0
  88. package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
  89. package/lib/esm/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +11 -0
  90. package/lib/esm/components/livechatwidget/common/endChat.js +29 -4
  91. package/lib/esm/components/livechatwidget/common/getMockChatSDKIfApplicable.js +4 -3
  92. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +8 -6
  93. package/lib/esm/components/livechatwidget/common/overridePropsOnMockIfApplicable.js +2 -1
  94. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +2 -2
  95. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -3
  96. package/lib/esm/components/livechatwidget/common/startChat.js +12 -7
  97. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +23 -4
  98. package/lib/esm/components/livechatwidget/interfaces/IMockProps.js +3 -3
  99. package/lib/esm/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
  100. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +42 -9
  101. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +31 -4
  102. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +13 -4
  103. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +125 -12
  104. package/lib/esm/components/webchatcontainerstateful/common/DesignerChatAdapter.js +43 -14
  105. package/lib/esm/components/webchatcontainerstateful/common/DesignerChatSDK.js +6 -1
  106. package/lib/esm/components/webchatcontainerstateful/common/activities/botActivity.js +7 -0
  107. package/lib/esm/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js +9 -0
  108. package/lib/esm/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +90 -0
  109. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
  110. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +2 -2
  111. package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultWebChatStyles.js +1 -1
  112. package/lib/esm/components/webchatcontainerstateful/common/utils/chatAdapterUtils.js +32 -0
  113. package/lib/esm/components/webchatcontainerstateful/common/utils/fontUtils.js +21 -0
  114. package/lib/esm/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +51 -0
  115. package/lib/esm/components/webchatcontainerstateful/interfaces/ICitation.js +1 -0
  116. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +115 -0
  117. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.js +3 -0
  118. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +10 -0
  119. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1060 -0
  120. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +25 -0
  121. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +42 -0
  122. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +13 -0
  123. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultAvatarTextStyles.js +1 -1
  124. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.js +13 -0
  125. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultSystemMessageStyles.js +1 -1
  126. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +1 -1
  127. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.js +52 -0
  128. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +3 -2
  129. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +1 -1
  130. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.js +98 -30
  131. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/queueOverflowHandlerMiddleware.js +2 -2
  132. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +46 -45
  133. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -0
  134. package/lib/esm/contexts/createReducer.js +15 -0
  135. package/lib/esm/firstresponselatency/FirstMessageTrackerFromBot.js +3 -2
  136. package/lib/esm/firstresponselatency/FirstResponseLatencyTracker.js +6 -2
  137. package/lib/esm/index.js +1 -0
  138. package/lib/esm/plugins/newMessageEventHandler.js +4 -1
  139. package/lib/types/common/Constants.d.ts +6 -0
  140. package/lib/types/common/facades/FacadeChatSDK.d.ts +3 -1
  141. package/lib/types/common/telemetry/TelemetryConstants.d.ts +41 -2
  142. package/lib/types/common/utils/SecureEventBus.d.ts +159 -0
  143. package/lib/types/common/utils/dispatchCustomEvent.d.ts +2 -0
  144. package/lib/types/components/citationpanestateful/CitationDim.d.ts +5 -0
  145. package/lib/types/components/citationpanestateful/CitationPaneStateful.d.ts +4 -0
  146. package/lib/types/components/citationpanestateful/common/defaultProps/defaultCitationPaneProps.d.ts +11 -0
  147. package/lib/types/components/citationpanestateful/interfaces/ICitationPaneStatefulProps.d.ts +19 -0
  148. package/lib/types/components/confirmationpanestateful/common/defaultProps/defaultConfirmationPaneLocalizedTexts.d.ts +1 -1
  149. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulProps.d.ts +1 -1
  150. package/lib/types/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.d.ts +45 -0
  151. package/lib/types/components/livechatwidget/common/ChatWidgetEvents.d.ts +7 -0
  152. package/lib/types/components/livechatwidget/common/PersistentConversationHandler.d.ts +28 -0
  153. package/lib/types/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.d.ts +2 -0
  154. package/lib/types/components/livechatwidget/common/getMockChatSDKIfApplicable.d.ts +2 -1
  155. package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +1 -0
  156. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +5 -1
  157. package/lib/types/components/livechatwidget/interfaces/IMockProps.d.ts +5 -3
  158. package/lib/types/components/livechatwidget/interfaces/IPersistentChatHistoryProps.d.ts +7 -0
  159. package/lib/types/components/webchatcontainerstateful/common/DesignerChatAdapter.d.ts +4 -2
  160. package/lib/types/components/webchatcontainerstateful/common/DesignerChatSDK.d.ts +5 -0
  161. package/lib/types/components/webchatcontainerstateful/common/activities/botActivity.d.ts +7 -0
  162. package/lib/types/components/webchatcontainerstateful/common/activities/conversationDividerActivity.d.ts +10 -0
  163. package/lib/types/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.d.ts +2 -0
  164. package/lib/types/components/webchatcontainerstateful/common/utils/chatAdapterUtils.d.ts +6 -1
  165. package/lib/types/components/webchatcontainerstateful/common/utils/fontUtils.d.ts +10 -0
  166. package/lib/types/components/webchatcontainerstateful/hooks/usePersistentChatHistory.d.ts +4 -0
  167. package/lib/types/components/webchatcontainerstateful/interfaces/ICitation.d.ts +12 -0
  168. package/lib/types/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.d.ts +7 -0
  169. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.d.ts +3 -0
  170. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.d.ts +4 -0
  171. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.d.ts +326 -0
  172. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.d.ts +8 -0
  173. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -0
  174. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.d.ts +2 -0
  175. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.d.ts +2 -0
  176. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/citationsMiddleware.d.ts +3 -4
  177. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/queueOverflowHandlerMiddleware.d.ts +2 -2
  178. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -0
  179. package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +1 -0
  180. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +46 -45
  181. package/lib/types/index.d.ts +1 -0
  182. package/package.json +3 -3
  183. /package/lib/cjs/components/{confirmationpanestateful/interfaces/IConfirmationPaneLocalizedText.js → citationpanestateful/interfaces/ICitationPaneStatefulProps.js} +0 -0
  184. /package/lib/esm/components/{confirmationpanestateful/interfaces/IConfirmationPaneLocalizedText.js → citationpanestateful/interfaces/ICitationPaneStatefulProps.js} +0 -0
  185. /package/lib/types/components/confirmationpanestateful/interfaces/{IConfirmationPaneLocalizedText.d.ts → IConfirmationPaneLocalizedTexts.d.ts} +0 -0
@@ -0,0 +1,1038 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.LazyLoadHandler = void 0;
7
+ var _TelemetryConstants = require("../../../../../../common/telemetry/TelemetryConstants");
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
10
+ var _ChatWidgetEvents = _interopRequireDefault(require("../../../../../livechatwidget/common/ChatWidgetEvents"));
11
+ var _Constants = require("./Constants");
12
+ var _LoadInlineBannerActivity = _interopRequireDefault(require("./LoadInlineBannerActivity"));
13
+ var _TelemetryHelper = require("../../../../../../common/telemetry/TelemetryHelper");
14
+ var _utils = require("../../../../../../common/utils");
15
+ var _dispatchCustomEvent = _interopRequireDefault(require("../../../../../../common/utils/dispatchCustomEvent"));
16
+ var _SecureEventBus = _interopRequireDefault(require("../../../../../../common/utils/SecureEventBus"));
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
23
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
24
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
26
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
27
+ /**
28
+ * LazyLoadHandler - Static class managing all lazy loading functionality
29
+ *
30
+ * This class uses a singleton pattern with static methods to ensure consistent
31
+ * state management across component re-renders and widget lifecycle events.
32
+ *
33
+ * State Management:
34
+ * - initialized: Tracks if the IntersectionObserver has been set up
35
+ * - paused: Temporarily disables lazy loading (during initialization/loading)
36
+ * - pendingScrollAction: Prevents overlapping scroll operations
37
+ * - isReady: Indicates when the system is fully ready for user interactions
38
+ * - initializationQueue: Stores user actions while system initializes
39
+ *
40
+ * Reliability Features:
41
+ * - Retry mechanisms with exponential backoff
42
+ * - Scroll verification with tolerance checking
43
+ * - Multiple container detection strategies
44
+ * - Immediate user feedback during delays
45
+ * - Proper memory management and cleanup
46
+ */
47
+ let LazyLoadHandler = /*#__PURE__*/function () {
48
+ function LazyLoadHandler() {
49
+ _classCallCheck(this, LazyLoadHandler);
50
+ }
51
+ _createClass(LazyLoadHandler, null, [{
52
+ key: "logLifecycleEvent",
53
+ value:
54
+ // DOM element identifiers
55
+ // Main widget container
56
+ // Intersection trigger element
57
+
58
+ // Observer and initialization state
59
+ // Observer setup completion flag
60
+ // Temporary disable flag
61
+ // The intersection observer instance
62
+
63
+ // Scroll operation state
64
+ // Current scroll operation tracking
65
+ // Prevents concurrent scroll operations
66
+
67
+ // Timeout and queue management
68
+ // Tracks all setTimeout IDs for cleanup
69
+
70
+ // Flag to track if a reset is needed when component mounts
71
+
72
+ // Telemetry tracking - lifecycle events only
73
+
74
+ // Simple lifecycle logging without complex state tracking
75
+ function logLifecycleEvent(event, description, elapsedTime) {
76
+ try {
77
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
78
+ Event: event,
79
+ Description: description,
80
+ ...(elapsedTime && {
81
+ ElapsedTimeInMilliseconds: elapsedTime
82
+ })
83
+ });
84
+ } catch (error) {
85
+ // Silent fail - don't break functionality for telemetry issues
86
+ }
87
+ }
88
+
89
+ // Broadcast event subscription for marking reset needed when chat is closed/reopened
90
+ }, {
91
+ key: "setHasMoreHistoryAvailable",
92
+ value:
93
+ // Tracks if more history can be loaded
94
+
95
+ // Debug method to track what's changing hasMoreHistoryAvailable
96
+ function setHasMoreHistoryAvailable(value) {
97
+ LazyLoadHandler.hasMoreHistoryAvailable = value;
98
+ }
99
+
100
+ /**
101
+ * Direct reset method that can be called externally
102
+ * This bypasses the broadcast system for more reliable resets
103
+ */
104
+ }, {
105
+ key: "directReset",
106
+ value: function directReset() {
107
+ LazyLoadHandler.resetPending = true;
108
+ LazyLoadHandler.setHasMoreHistoryAvailable(true);
109
+ LazyLoadHandler.unmount();
110
+ }
111
+
112
+ /**
113
+ * Main initialization method for the lazy loading system
114
+ *
115
+ * This method sets up the IntersectionObserver that watches for when the trigger
116
+ * element becomes visible, indicating the user has scrolled near the top.
117
+ *
118
+ * Process:
119
+ * 1. Prevents duplicate initialization
120
+ * 2. Sets up intersection callback to handle visibility events
121
+ * 3. Finds appropriate scroll container with fallback strategies
122
+ * 4. Configures observer with optimal settings for chat history loading
123
+ * 5. Waits for target element availability with exponential backoff
124
+ *
125
+ * Observer Configuration:
126
+ * - root: The scrollable container (webchat or fallback)
127
+ * - rootMargin: 20px top margin to trigger slightly before element is visible
128
+ * - threshold: 0.05 (5%) visibility required to trigger
129
+ */
130
+ }, {
131
+ key: "useLazyLoadObserver",
132
+ value: function useLazyLoadObserver() {
133
+ // Auto-correct stale state: if hasMoreHistoryAvailable is false but we're trying to initialize, reset it
134
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
135
+ LazyLoadHandler.setHasMoreHistoryAvailable(true);
136
+ }
137
+
138
+ // Prevent duplicate initialization
139
+ if (LazyLoadHandler.initialized) {
140
+ return;
141
+ }
142
+
143
+ // Start initialization timing
144
+ LazyLoadHandler.initTimer = (0, _utils.createTimer)();
145
+ LazyLoadHandler.logLifecycleEvent(_TelemetryConstants.TelemetryEvent.LCWLazyLoadInitializationStarted, "LazyLoad observer initialization started");
146
+
147
+ // Reset readiness during initialization to handle user interactions
148
+ LazyLoadHandler.isReady = false;
149
+
150
+ /**
151
+ * Intersection Observer Callback
152
+ *
153
+ * Triggered when the target element's visibility changes.
154
+ * Guards against triggering during paused states or pending operations.
155
+ *
156
+ * @param entries - Array of intersection observer entries
157
+ */
158
+ const callback = entries => {
159
+ // Guard clauses: Don't trigger if paused, already processing, or no more history available
160
+ if (LazyLoadHandler.paused || LazyLoadHandler.pendingScrollAction || !LazyLoadHandler.hasMoreHistoryAvailable) {
161
+ return;
162
+ }
163
+ entries.forEach(entry => {
164
+ // Check if element is intersecting with any visibility
165
+ if (entry.isIntersecting && entry.intersectionRatio > 0) {
166
+ // Double-check history availability at trigger time
167
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
168
+ return;
169
+ }
170
+ LazyLoadHandler.handleLazyLoadTrigger();
171
+ }
172
+ });
173
+ };
174
+
175
+ /**
176
+ * Observer Setup Function
177
+ *
178
+ * Handles the complex process of finding the right container and
179
+ * setting up the intersection observer with proper configuration.
180
+ */
181
+ const setupObserver = () => {
182
+ // Find the scroll container using multiple strategies
183
+ const {
184
+ container: scrollContainer
185
+ } = LazyLoadHandler.findScrollContainer();
186
+ if (!scrollContainer) {
187
+ // Schedule retry with faster timeout for better responsiveness
188
+ const timeoutId = window.setTimeout(() => {
189
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
190
+ setupObserver();
191
+ }, 100); // Reduced from 200ms to 100ms for faster container detection
192
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
193
+ return;
194
+ }
195
+
196
+ // Configure intersection observer options
197
+ const options = {
198
+ root: scrollContainer,
199
+ // Container to observe within
200
+ rootMargin: "20px 0px 0px 0px",
201
+ // Trigger 20px before element is visible
202
+ threshold: 0.05 // Trigger when 5% of element is visible
203
+ };
204
+
205
+ const observer = new IntersectionObserver(callback, options);
206
+
207
+ // Wait for target element and finalize setup
208
+ LazyLoadHandler.waitForTargetElement(() => {
209
+ const targetElement = document.getElementById(LazyLoadHandler.targetId);
210
+ if (targetElement) {
211
+ observer.observe(targetElement);
212
+ LazyLoadHandler.observer = observer;
213
+ LazyLoadHandler.initialized = true;
214
+ LazyLoadHandler.isReady = true; // Mark system as ready
215
+
216
+ // Log successful initialization
217
+ LazyLoadHandler.logLifecycleEvent(_TelemetryConstants.TelemetryEvent.LCWLazyLoadInitializationCompleted, "LazyLoad observer initialization completed", LazyLoadHandler.initTimer.milliSecondsElapsed);
218
+
219
+ // Process any actions that were queued during initialization
220
+ LazyLoadHandler.processInitializationQueue();
221
+ }
222
+ });
223
+ };
224
+ setupObserver();
225
+ }
226
+
227
+ /**
228
+ * Waits for the target element to be available in the DOM
229
+ *
230
+ * Uses exponential backoff to retry finding the target element.
231
+ * This is necessary because the target element may not be immediately
232
+ * available when the observer is being set up.
233
+ *
234
+ * @param callback - Function to call when target element is found
235
+ * @param maxAttempts - Maximum number of retry attempts (default: 10)
236
+ * @param attempt - Current attempt number (default: 1)
237
+ */
238
+ }, {
239
+ key: "waitForTargetElement",
240
+ value: function waitForTargetElement(callback) {
241
+ let maxAttempts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
242
+ let attempt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
243
+ const targetElement = document.getElementById(LazyLoadHandler.targetId);
244
+
245
+ // Target found, execute callback
246
+ if (targetElement) {
247
+ callback();
248
+ return;
249
+ }
250
+
251
+ // Max attempts reached, log error
252
+ if (attempt >= maxAttempts) {
253
+ LazyLoadHandler.logLifecycleEvent(_TelemetryConstants.TelemetryEvent.LCWLazyLoadTargetElementNotFound, "Target element not found after max attempts");
254
+ return;
255
+ }
256
+
257
+ // Schedule retry with exponential backoff (50ms * attempt number for faster initial attempts)
258
+ const timeoutId = window.setTimeout(() => {
259
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
260
+ LazyLoadHandler.waitForTargetElement(callback, maxAttempts, attempt + 1);
261
+ }, 50 * attempt); // Reduced from 100ms to 50ms for faster element detection
262
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
263
+ }
264
+
265
+ /**
266
+ * Handles immediate scroll requests when system might not be ready
267
+ *
268
+ * This is crucial for handling minimize/maximize scenarios where users
269
+ * immediately scroll up before the observer is fully initialized.
270
+ *
271
+ * Two-Path Strategy:
272
+ * 1. If ready: Execute normal lazy load trigger
273
+ * 2. If not ready: Provide immediate feedback + queue action for later
274
+ *
275
+ * This ensures users always get visual feedback even during initialization delays.
276
+ */
277
+ }, {
278
+ key: "handleImmediateScrollRequest",
279
+ value: function handleImmediateScrollRequest() {
280
+ if (LazyLoadHandler.isReady) {
281
+ // System is ready, handle normally
282
+ LazyLoadHandler.handleLazyLoadTrigger();
283
+ } else {
284
+ // System not ready, provide immediate feedback and queue action
285
+ LazyLoadHandler.executeImmediateScrollFeedback();
286
+
287
+ // Queue the full lazy load action to execute when system is ready
288
+ LazyLoadHandler.initializationQueue.push(() => {
289
+ LazyLoadHandler.handleLazyLoadTrigger();
290
+ });
291
+
292
+ // Try to speed up initialization
293
+ LazyLoadHandler.expediteInitialization();
294
+ }
295
+ }
296
+
297
+ /**
298
+ * Provides immediate scroll feedback during initialization
299
+ *
300
+ * When the system isn't ready but user scrolls up, this provides
301
+ * immediate visual feedback (20px scroll) so the user knows their
302
+ * action was recognized.
303
+ */
304
+ }, {
305
+ key: "executeImmediateScrollFeedback",
306
+ value: function executeImmediateScrollFeedback() {
307
+ // Find container and validate scrollability
308
+ const {
309
+ container,
310
+ isScrollable
311
+ } = LazyLoadHandler.findScrollContainer();
312
+ if (container && isScrollable) {
313
+ const currentScrollTop = container.scrollTop;
314
+ const immediateScrollTarget = currentScrollTop + 20; // Small immediate scroll for feedback
315
+
316
+ // Use requestAnimationFrame for smooth scroll execution
317
+ requestAnimationFrame(() => {
318
+ if (container) {
319
+ container.scrollTop = immediateScrollTarget;
320
+ }
321
+ });
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Forces faster initialization attempts
327
+ *
328
+ * When user interacts before system is ready, this tries to
329
+ * speed up the initialization process.
330
+ */
331
+ }, {
332
+ key: "expediteInitialization",
333
+ value: function expediteInitialization() {
334
+ // Force faster initialization attempts if not already initialized
335
+ if (!LazyLoadHandler.initialized) {
336
+ LazyLoadHandler.useLazyLoadObserver();
337
+ }
338
+ }
339
+
340
+ /**
341
+ * Processes all queued actions once system is ready
342
+ *
343
+ * During initialization, user actions are queued. Once the system
344
+ * is ready, this processes all queued actions with small delays
345
+ * between them to prevent overwhelming the system.
346
+ */
347
+ }, {
348
+ key: "processInitializationQueue",
349
+ value: function processInitializationQueue() {
350
+ // Process all queued actions sequentially
351
+ while (LazyLoadHandler.initializationQueue.length > 0) {
352
+ const action = LazyLoadHandler.initializationQueue.shift();
353
+ if (action) {
354
+ // Add small delay between queued actions to prevent conflicts
355
+ const timeoutId = window.setTimeout(() => {
356
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
357
+ action();
358
+ }, 25); // Reduced from 100ms to 25ms for faster processing
359
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
360
+ }
361
+ }
362
+ }
363
+
364
+ /**
365
+ * Manually checks if target element is visible and triggers lazy load
366
+ *
367
+ * This is used when the intersection observer might not be ready yet
368
+ * but we need to check if the trigger element is already in view.
369
+ *
370
+ * Uses getBoundingClientRect() to calculate visibility manually.
371
+ */
372
+ }, {
373
+ key: "checkVisibilityAndTrigger",
374
+ value: function checkVisibilityAndTrigger() {
375
+ // Don't trigger if no more history is available
376
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
377
+ return;
378
+ }
379
+ const targetElement = document.getElementById(LazyLoadHandler.targetId);
380
+ if (!targetElement) {
381
+ return;
382
+ }
383
+ const {
384
+ container
385
+ } = LazyLoadHandler.findScrollContainer();
386
+ if (!container) {
387
+ return;
388
+ }
389
+
390
+ // Get bounding rectangles for visibility calculation
391
+ const targetRect = targetElement.getBoundingClientRect();
392
+ const containerRect = container.getBoundingClientRect();
393
+
394
+ // Check if target element intersects with container viewport
395
+ const isVisible = targetRect.top < containerRect.bottom &&
396
+ // Target top is above container bottom
397
+ targetRect.bottom > containerRect.top &&
398
+ // Target bottom is below container top
399
+ targetRect.left < containerRect.right &&
400
+ // Target left is before container right
401
+ targetRect.right > containerRect.left // Target right is after container left
402
+ ;
403
+
404
+ if (isVisible) {
405
+ LazyLoadHandler.handleImmediateScrollRequest();
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Main lazy load trigger handler
411
+ *
412
+ * This is the core method that executes when the trigger element becomes visible.
413
+ * It coordinates the entire lazy loading process:
414
+ *
415
+ * 1. Sets flags to prevent concurrent operations
416
+ * 2. Dispatches event to fetch more chat history
417
+ * 3. Waits for content to load
418
+ * 4. Executes scroll adjustment to maintain user position
419
+ *
420
+ * Timing: Uses 300ms delay to allow content loading before scroll adjustment
421
+ */
422
+ }, {
423
+ key: "handleLazyLoadTrigger",
424
+ value: function handleLazyLoadTrigger() {
425
+ // Final guard: Don't proceed if no more history is available
426
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
427
+ return;
428
+ }
429
+
430
+ // Set flags to prevent overlapping operations
431
+ LazyLoadHandler.pendingScrollAction = true; // Block new scroll actions
432
+ LazyLoadHandler.paused = true; // Pause intersection observer
433
+
434
+ // Dispatch custom event to trigger chat history fetching
435
+ // This event is handled by other parts of the chat system
436
+ (0, _dispatchCustomEvent.default)(_ChatWidgetEvents.default.FETCH_PERSISTENT_CHAT_HISTORY);
437
+
438
+ // Wait for content to load before performing scroll adjustment
439
+ // 200ms provides good balance between responsiveness and content loading
440
+ const timeoutId = window.setTimeout(() => {
441
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
442
+ LazyLoadHandler.executeReliableScroll();
443
+ }, 200); // Reduced from 300ms to 200ms for faster response
444
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
445
+ }
446
+
447
+ /**
448
+ * Executes reliable scroll with validation and retry logic
449
+ *
450
+ * This method implements a robust scroll system that:
451
+ * 1. Finds and validates the scroll container
452
+ * 2. Calculates target scroll position (current + 35px)
453
+ * 3. Sets up scroll state for tracking and retries
454
+ * 4. Initiates the scroll attempt process
455
+ *
456
+ * If no suitable container is found, schedules a retry.
457
+ */
458
+ }, {
459
+ key: "executeReliableScroll",
460
+ value: function executeReliableScroll() {
461
+ // Guard: Don't execute scroll if no more history is available
462
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
463
+ LazyLoadHandler.finishScrollAction();
464
+ return;
465
+ }
466
+
467
+ // Find container using multiple fallback strategies
468
+ const {
469
+ container,
470
+ isScrollable
471
+ } = LazyLoadHandler.findScrollContainer();
472
+ if (!container || !isScrollable) {
473
+ LazyLoadHandler.scheduleScrollRetry();
474
+ return;
475
+ }
476
+
477
+ // Calculate scroll positions
478
+ const initialScrollTop = container.scrollTop;
479
+ const targetScrollTop = initialScrollTop + 35; // 35px down to maintain position
480
+
481
+ // Set up scroll state for tracking and retries
482
+ LazyLoadHandler.scrollState = {
483
+ container,
484
+ initialScrollTop,
485
+ targetScrollTop,
486
+ attemptCount: 0,
487
+ maxAttempts: 5 // Allow up to 5 retry attempts
488
+ };
489
+
490
+ // Begin the scroll attempt process
491
+ LazyLoadHandler.attemptScroll();
492
+ }
493
+
494
+ /**
495
+ * Attempts to perform scroll with verification and retry logic
496
+ *
497
+ * This method implements a sophisticated scroll system:
498
+ *
499
+ * 1. Uses requestAnimationFrame for smooth execution
500
+ * 2. Performs the scroll operation
501
+ * 3. Verifies scroll actually occurred (5px tolerance)
502
+ * 4. Retries with exponential backoff if failed
503
+ * 5. Continues operation after max attempts
504
+ *
505
+ * The two-frame approach ensures scroll is applied and then verified
506
+ * after the browser has had time to process the scroll change.
507
+ */
508
+ }, {
509
+ key: "attemptScroll",
510
+ value: function attemptScroll() {
511
+ // Guard: Don't attempt scroll if no more history is available
512
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
513
+ LazyLoadHandler.finishScrollAction();
514
+ return;
515
+ }
516
+ if (!LazyLoadHandler.scrollState) {
517
+ LazyLoadHandler.finishScrollAction();
518
+ return;
519
+ }
520
+
521
+ // Extract current scroll state
522
+ const {
523
+ container,
524
+ targetScrollTop,
525
+ attemptCount,
526
+ maxAttempts
527
+ } = LazyLoadHandler.scrollState;
528
+ LazyLoadHandler.scrollState.attemptCount++;
529
+
530
+ // Perform scroll using requestAnimationFrame for smooth execution
531
+ // Frame 1: Apply the scroll
532
+ requestAnimationFrame(() => {
533
+ // Double-check history availability before applying scroll
534
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
535
+ LazyLoadHandler.finishScrollAction();
536
+ return;
537
+ }
538
+ if (container) {
539
+ container.scrollTop = targetScrollTop;
540
+ }
541
+
542
+ // Frame 2: Verify scroll occurred after browser has processed the change
543
+ requestAnimationFrame(() => {
544
+ // Triple-check history availability before verification
545
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
546
+ LazyLoadHandler.finishScrollAction();
547
+ return;
548
+ }
549
+ const actualScrollTop = container ? container.scrollTop : 0;
550
+ const scrollSucceeded = Math.abs(actualScrollTop - targetScrollTop) < 5; // 5px tolerance for success
551
+
552
+ if (scrollSucceeded) {
553
+ LazyLoadHandler.finishScrollAction();
554
+ } else if (attemptCount < maxAttempts) {
555
+ // Retry with exponential backoff (100ms * attempt number)
556
+ const timeoutId = window.setTimeout(() => {
557
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
558
+ LazyLoadHandler.attemptScroll();
559
+ }, 100 * attemptCount); // Exponential backoff
560
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
561
+ } else {
562
+ LazyLoadHandler.finishScrollAction();
563
+ }
564
+ });
565
+ });
566
+ }
567
+
568
+ /**
569
+ * Finishes scroll action and prepares for next cycle
570
+ *
571
+ * Cleans up scroll state and schedules the reset cycle.
572
+ * Uses delays to allow content stabilization before re-enabling
573
+ * the intersection observer for the next lazy load cycle.
574
+ */
575
+ }, {
576
+ key: "finishScrollAction",
577
+ value: function finishScrollAction() {
578
+ // Clean up scroll tracking state
579
+ LazyLoadHandler.scrollState = null;
580
+ LazyLoadHandler.pendingScrollAction = false;
581
+
582
+ // Schedule unpause and reset with delay for content stabilization
583
+ const timeoutId = window.setTimeout(() => {
584
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
585
+ LazyLoadHandler.paused = false; // Re-enable intersection observer
586
+ LazyLoadHandler.scheduleReset(); // Schedule next cycle reset
587
+ }, 500);
588
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
589
+ }
590
+
591
+ /**
592
+ * Schedules retry for failed scroll operations
593
+ *
594
+ * Used when scroll container is not available or scrollable.
595
+ * Provides a longer delay to allow container to become ready.
596
+ */
597
+ }, {
598
+ key: "scheduleScrollRetry",
599
+ value: function scheduleScrollRetry() {
600
+ // Don't schedule retry if no more history is available
601
+ if (!LazyLoadHandler.hasMoreHistoryAvailable) {
602
+ LazyLoadHandler.finishScrollAction();
603
+ return;
604
+ }
605
+ const timeoutId = window.setTimeout(() => {
606
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
607
+ // Only retry if we're still in a pending scroll action state and have more history
608
+ if (LazyLoadHandler.pendingScrollAction && LazyLoadHandler.hasMoreHistoryAvailable) {
609
+ LazyLoadHandler.executeReliableScroll();
610
+ }
611
+ }, 1000); // 1 second delay for container readiness
612
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
613
+ }
614
+
615
+ /**
616
+ * Schedules observer reset for next lazy load cycle
617
+ *
618
+ * After a lazy load operation completes, the observer needs to be reset
619
+ * to detect the next time the user scrolls to the top.
620
+ */
621
+ }, {
622
+ key: "scheduleReset",
623
+ value: function scheduleReset() {
624
+ const timeoutId = window.setTimeout(() => {
625
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
626
+ LazyLoadHandler.reset();
627
+ }, 1000); // 1 second delay before resetting for next cycle
628
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
629
+ }
630
+
631
+ /**
632
+ * Finds the appropriate scroll container using multiple strategies
633
+ *
634
+ * Container Detection Priority:
635
+ * 1. Primary: Specific webchat scroll container (.webchat__basic-transcript__scrollable)
636
+ * 2. Secondary: Widget root container (ms_lcw_webchat_root)
637
+ * 3. Tertiary: Any scrollable parent of the target element
638
+ * 4. Fallback: Best available container (even if not scrollable)
639
+ *
640
+ * Returns both the container and whether it's actually scrollable.
641
+ *
642
+ * @returns Object containing container element and scrollability status
643
+ */
644
+ }, {
645
+ key: "findScrollContainer",
646
+ value: function findScrollContainer() {
647
+ // Primary: Look for the specific webchat scroll container
648
+ const webchatContainer = document.querySelector(_Constants.LazyLoadActivityConstants.SCROLL_ID);
649
+ if (webchatContainer && LazyLoadHandler.isElementScrollable(webchatContainer)) {
650
+ return {
651
+ container: webchatContainer,
652
+ isScrollable: true
653
+ };
654
+ }
655
+
656
+ // Secondary: Try the root container
657
+ const rootContainer = document.getElementById(LazyLoadHandler.rootId);
658
+ if (rootContainer && LazyLoadHandler.isElementScrollable(rootContainer)) {
659
+ return {
660
+ container: rootContainer,
661
+ isScrollable: true
662
+ };
663
+ }
664
+
665
+ // Tertiary: Find any scrollable parent of the target element
666
+ const targetElement = document.getElementById(LazyLoadHandler.targetId);
667
+ if (targetElement) {
668
+ const scrollableParent = LazyLoadHandler.findScrollableParent(targetElement);
669
+ if (scrollableParent) {
670
+ return {
671
+ container: scrollableParent,
672
+ isScrollable: true
673
+ };
674
+ }
675
+ }
676
+
677
+ // Fallback: Return the best available container even if not scrollable
678
+ // This allows the system to continue functioning in edge cases
679
+ return {
680
+ container: webchatContainer || rootContainer || document.body,
681
+ isScrollable: false
682
+ };
683
+ }
684
+
685
+ /**
686
+ * Determines if an element is scrollable
687
+ *
688
+ * Checks two conditions:
689
+ * 1. Content overflow: scrollHeight > clientHeight (content extends beyond visible area)
690
+ * 2. CSS overflow settings: overflow/overflowY set to 'auto' or 'scroll'
691
+ *
692
+ * @param element - The element to check for scrollability
693
+ * @returns true if element is scrollable, false otherwise
694
+ */
695
+ }, {
696
+ key: "isElementScrollable",
697
+ value: function isElementScrollable(element) {
698
+ const style = window.getComputedStyle(element);
699
+ const hasScrollableContent = element.scrollHeight > element.clientHeight;
700
+ const hasScrollableOverflow = style.overflow === "auto" || style.overflow === "scroll" || style.overflowY === "auto" || style.overflowY === "scroll";
701
+ return hasScrollableContent && hasScrollableOverflow;
702
+ }
703
+
704
+ /**
705
+ * Traverses up the DOM tree to find a scrollable parent element
706
+ *
707
+ * Starting from the given element, walks up the parent chain
708
+ * until it finds a scrollable element or reaches document.body.
709
+ *
710
+ * @param element - Starting element to search from
711
+ * @returns Scrollable parent element or null if none found
712
+ */
713
+ }, {
714
+ key: "findScrollableParent",
715
+ value: function findScrollableParent(element) {
716
+ let parent = element.parentElement;
717
+ while (parent && parent !== document.body) {
718
+ if (LazyLoadHandler.isElementScrollable(parent)) {
719
+ return parent;
720
+ }
721
+ parent = parent.parentElement;
722
+ }
723
+ return null;
724
+ }
725
+
726
+ /**
727
+ * Legacy method - redirects to new reliable scroll system
728
+ *
729
+ * Maintained for backwards compatibility with existing code
730
+ * that might call this method directly.
731
+ */
732
+ }, {
733
+ key: "moveScrollDown",
734
+ value: function moveScrollDown() {
735
+ LazyLoadHandler.executeReliableScroll();
736
+ }
737
+
738
+ /**
739
+ * Legacy scroll adjustment method with enhancements
740
+ *
741
+ * Enhanced version of the original adjustScroll method:
742
+ * - Validates container scrollability before attempting scroll
743
+ * - Uses requestAnimationFrame for smooth execution
744
+ * - Provides logging for debugging
745
+ *
746
+ * @param scrollContainer - The container element to scroll
747
+ */
748
+ }, {
749
+ key: "adjustScroll",
750
+ value: function adjustScroll(scrollContainer) {
751
+ // Validate container is scrollable before attempting scroll
752
+ if (!LazyLoadHandler.isElementScrollable(scrollContainer)) {
753
+ return;
754
+ }
755
+ const currentScrollTop = scrollContainer.scrollTop;
756
+ const moveDownBy = 35; // Standard scroll adjustment amount
757
+ const targetScrollTop = currentScrollTop + moveDownBy;
758
+
759
+ // Use requestAnimationFrame for smooth scroll execution
760
+ requestAnimationFrame(() => {
761
+ scrollContainer.scrollTop = targetScrollTop;
762
+ });
763
+ }
764
+
765
+ /**
766
+ * Handles the NO_MORE_HISTORY_AVAILABLE event
767
+ *
768
+ * Called when there's no more chat history to load.
769
+ * Disables further lazy loading attempts and cleans up the observer.
770
+ * Also removes the trigger element from the DOM to prevent further triggering.
771
+ */
772
+ }, {
773
+ key: "handleNoMoreHistoryAvailable",
774
+ value: function handleNoMoreHistoryAvailable() {
775
+ LazyLoadHandler.setHasMoreHistoryAvailable(false);
776
+ LazyLoadHandler.paused = true;
777
+ LazyLoadHandler.pendingScrollAction = false; // Reset this to prevent stuck states
778
+
779
+ LazyLoadHandler.logLifecycleEvent(_TelemetryConstants.TelemetryEvent.LCWLazyLoadNoMoreHistory, "No more history available");
780
+
781
+ // Clear all pending timeouts to stop any scheduled operations
782
+ LazyLoadHandler.retryTimeouts.forEach(timeoutId => {
783
+ clearTimeout(timeoutId);
784
+ });
785
+ LazyLoadHandler.retryTimeouts.clear();
786
+
787
+ // Disconnect observer to prevent further triggering
788
+ if (LazyLoadHandler.observer) {
789
+ LazyLoadHandler.observer.disconnect();
790
+ LazyLoadHandler.observer = null;
791
+ }
792
+
793
+ // Clear scroll state
794
+ LazyLoadHandler.scrollState = null;
795
+ }
796
+
797
+ /**
798
+ * Resets the lazy load system for the next cycle
799
+ *
800
+ * This method prepares the system for the next lazy load operation:
801
+ * 1. Cleans up current state
802
+ * 2. Resets all flags and queues
803
+ * 3. Reinitializes the observer with faster timing
804
+ *
805
+ * Called after each lazy load cycle completes.
806
+ */
807
+ }, {
808
+ key: "reset",
809
+ value: function reset() {
810
+ LazyLoadHandler.unmount(); // Clean up current state
811
+ LazyLoadHandler.initialized = false; // Reset initialization flag
812
+ LazyLoadHandler.isReady = false; // Reset readiness flag
813
+ LazyLoadHandler.setHasMoreHistoryAvailable(true); // Reset history availability flag
814
+ LazyLoadHandler.initializationQueue = []; // Clear action queue
815
+ LazyLoadHandler.resetPending = false; // Clear pending reset flag
816
+
817
+ // Reinitialize with faster timing for better responsiveness
818
+ const timeoutId = window.setTimeout(() => {
819
+ LazyLoadHandler.retryTimeouts.delete(timeoutId);
820
+ LazyLoadHandler.useLazyLoadObserver();
821
+ }, 25); // Reduced from 50ms to 25ms for faster reset
822
+ LazyLoadHandler.retryTimeouts.add(timeoutId);
823
+ }
824
+
825
+ /**
826
+ * Comprehensive cleanup method
827
+ *
828
+ * Performs complete cleanup of all lazy load resources:
829
+ * - Clears all pending timeouts to prevent memory leaks
830
+ * - Removes intersection observer and event listeners
831
+ * - Resets all state variables to initial values
832
+ * - Clears action queue
833
+ *
834
+ * Critical for preventing memory leaks and ensuring clean component unmounting.
835
+ */
836
+ }, {
837
+ key: "unmount",
838
+ value: function unmount() {
839
+ LazyLoadHandler.retryTimeouts.forEach(timeoutId => {
840
+ clearTimeout(timeoutId);
841
+ });
842
+ LazyLoadHandler.retryTimeouts.clear();
843
+
844
+ // Clean up intersection observer
845
+ const targetElement = document.getElementById(LazyLoadHandler.targetId);
846
+ if (targetElement && LazyLoadHandler.observer) {
847
+ LazyLoadHandler.observer.unobserve(targetElement);
848
+ }
849
+
850
+ // Reset all state variables to initial values
851
+ LazyLoadHandler.observer = null;
852
+ LazyLoadHandler.initialized = false;
853
+ LazyLoadHandler.paused = false;
854
+ LazyLoadHandler.pendingScrollAction = false;
855
+ LazyLoadHandler.scrollState = null;
856
+ LazyLoadHandler.isReady = false;
857
+ LazyLoadHandler.initializationQueue = [];
858
+ // Note: Don't reset resetPending here as it needs to persist across unmount/mount cycles
859
+ }
860
+
861
+ /**
862
+ * Complete cleanup including broadcast event listener
863
+ *
864
+ * This method is used for final cleanup when the LazyLoadActivity component is being destroyed completely.
865
+ * It includes unsubscribing from broadcast events and performing complete cleanup.
866
+ * This is different from reset() which prepares the system for a new chat session.
867
+ */
868
+ }, {
869
+ key: "destroy",
870
+ value: function destroy() {
871
+ LazyLoadHandler.logLifecycleEvent(_TelemetryConstants.TelemetryEvent.LCWLazyLoadDestroyed, "LazyLoad component destroyed");
872
+ LazyLoadHandler.unmount();
873
+
874
+ // Clean up broadcast event subscription
875
+ if (LazyLoadHandler.resetEventListener) {
876
+ LazyLoadHandler.resetEventListener.unsubscribe();
877
+ }
878
+ }
879
+ }]);
880
+ return LazyLoadHandler;
881
+ }();
882
+ /**
883
+ * LazyLoadActivity React Component
884
+ *
885
+ * This component serves as the React wrapper for the LazyLoadHandler system.
886
+ * It renders the trigger element and manages the component lifecycle.
887
+ *
888
+ * Component Lifecycle:
889
+ * 1. Mount: Initializes lazy load observer and sets up scroll listener
890
+ * 2. Active: Monitors user scroll behavior and responds to interactions
891
+ * 3. Unmount: Cleans up all resources and prevents memory leaks
892
+ *
893
+ * Key Features:
894
+ * - Automatic initialization on mount
895
+ * - Scroll event monitoring for immediate responsiveness
896
+ * - Proper cleanup on unmount
897
+ * - Handles minimize/maximize scenarios
898
+ * - Reactive rendering based on history availability
899
+ */
900
+ exports.LazyLoadHandler = LazyLoadHandler;
901
+ _defineProperty(LazyLoadHandler, "rootId", "ms_lcw_webchat_root");
902
+ _defineProperty(LazyLoadHandler, "targetId", "lazy-load-trigger-element");
903
+ _defineProperty(LazyLoadHandler, "initialized", false);
904
+ _defineProperty(LazyLoadHandler, "paused", false);
905
+ _defineProperty(LazyLoadHandler, "observer", null);
906
+ _defineProperty(LazyLoadHandler, "scrollState", null);
907
+ _defineProperty(LazyLoadHandler, "pendingScrollAction", false);
908
+ _defineProperty(LazyLoadHandler, "retryTimeouts", new Set());
909
+ _defineProperty(LazyLoadHandler, "resetPending", false);
910
+ _defineProperty(LazyLoadHandler, "initTimer", (0, _utils.createTimer)());
911
+ _defineProperty(LazyLoadHandler, "resetEventListener", _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.PersistentConversationReset).subscribe(() => {
912
+ LazyLoadHandler.logLifecycleEvent(_TelemetryConstants.TelemetryEvent.LCWLazyLoadReset, "LazyLoad reset triggered");
913
+ LazyLoadHandler.resetPending = true;
914
+ LazyLoadHandler.setHasMoreHistoryAvailable(true); // Reset this immediately so activityMiddleware doesn't block rendering
915
+ LazyLoadHandler.unmount(); // Clean up current state immediately
916
+ }));
917
+ // Readiness and queue system (handles minimize/maximize scenarios)
918
+ _defineProperty(LazyLoadHandler, "isReady", false);
919
+ // System readiness flag
920
+ _defineProperty(LazyLoadHandler, "initializationQueue", []);
921
+ // Queue for actions during initialization
922
+ // History availability state
923
+ _defineProperty(LazyLoadHandler, "hasMoreHistoryAvailable", true);
924
+ const LazyLoadActivity = props => {
925
+ const [hasMoreHistory, setHasMoreHistory] = (0, _react.useState)(LazyLoadHandler.hasMoreHistoryAvailable);
926
+ (0, _react.useEffect)(() => {
927
+ LazyLoadHandler.logLifecycleEvent(_TelemetryConstants.TelemetryEvent.LCWLazyLoadActivityMounted, "LazyLoadActivity component mounted");
928
+
929
+ // Set up event listeners FIRST - before any early returns
930
+ // Event listener for NO_MORE_HISTORY_AVAILABLE
931
+ const handleNoMoreHistory = () => {
932
+ LazyLoadHandler.handleNoMoreHistoryAvailable();
933
+ // Update React state to trigger re-render and hide component
934
+ setHasMoreHistory(false);
935
+ };
936
+
937
+ // Event listener for PersistentConversationReset to sync React state
938
+ // This fixes the issue where banner doesn't appear in start chat + close chat + start chat sequence
939
+ // by ensuring React state (hasMoreHistory) is synchronized with handler state when reset occurs
940
+ const handlePersistentConversationReset = () => {
941
+ // Update React state to trigger re-render and show component for new chat session
942
+ setHasMoreHistory(true);
943
+ };
944
+
945
+ // Add secure event listener for no more history signal
946
+ const eventBus = _SecureEventBus.default.getInstance();
947
+ const unsubscribeNoMoreHistory = eventBus.subscribe(_ChatWidgetEvents.default.NO_MORE_HISTORY_AVAILABLE, handleNoMoreHistory);
948
+
949
+ // Add event listener for persistent conversation reset
950
+ const resetSubscription = _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.PersistentConversationReset).subscribe(handlePersistentConversationReset);
951
+
952
+ // Sync React state with handler state on mount in case they're out of sync
953
+ if (hasMoreHistory !== LazyLoadHandler.hasMoreHistoryAvailable) {
954
+ setHasMoreHistory(LazyLoadHandler.hasMoreHistoryAvailable);
955
+ }
956
+
957
+ // Check if a reset was pending from a previous chat session
958
+ if (LazyLoadHandler.resetPending) {
959
+ LazyLoadHandler.resetPending = false;
960
+ LazyLoadHandler.reset();
961
+
962
+ // Still need to return cleanup function even after reset
963
+ return () => {
964
+ unsubscribeNoMoreHistory();
965
+ resetSubscription.unsubscribe();
966
+ };
967
+ }
968
+
969
+ // Initialize the lazy load observer system
970
+ LazyLoadHandler.useLazyLoadObserver();
971
+
972
+ // Pause initially to prevent unexpected triggers during initialization
973
+ LazyLoadHandler.paused = true;
974
+
975
+ // Set up initialization completion with visibility check
976
+ const initTimeoutId = window.setTimeout(() => {
977
+ LazyLoadHandler.paused = false; // Enable lazy loading
978
+
979
+ // Check if target is already visible after initialization
980
+ // This handles cases where user scrolled during initialization
981
+ LazyLoadHandler.checkVisibilityAndTrigger();
982
+ }, 200); // Reduced from 500ms to 200ms for faster initial load
983
+
984
+ /**
985
+ * Scroll Event Handler for Immediate Responsiveness
986
+ *
987
+ * This listener provides immediate feedback when users scroll
988
+ * before the system is fully ready (e.g., after minimize/maximize).
989
+ *
990
+ * Uses passive event listener for better performance.
991
+ */
992
+ const handleScroll = () => {
993
+ if (!LazyLoadHandler.isReady) {
994
+ // System not ready, but user is scrolling - check if we should trigger
995
+ window.setTimeout(() => {
996
+ LazyLoadHandler.checkVisibilityAndTrigger();
997
+ }, 50); // Reduced from 100ms to 50ms for faster response
998
+ }
999
+ };
1000
+
1001
+ // Find container and attach scroll listener
1002
+ const {
1003
+ container
1004
+ } = LazyLoadHandler.findScrollContainer();
1005
+ if (container) {
1006
+ container.addEventListener("scroll", handleScroll, {
1007
+ passive: true
1008
+ });
1009
+ }
1010
+
1011
+ // Cleanup function - critical for preventing memory leaks
1012
+ return () => {
1013
+ clearTimeout(initTimeoutId);
1014
+
1015
+ // Remove event listeners
1016
+ unsubscribeNoMoreHistory();
1017
+ resetSubscription.unsubscribe();
1018
+ if (container) {
1019
+ container.removeEventListener("scroll", handleScroll);
1020
+ }
1021
+
1022
+ // Perform complete system cleanup including broadcast event listener
1023
+ LazyLoadHandler.destroy();
1024
+ };
1025
+ }, []); // Empty dependency array - only run on mount/unmount
1026
+
1027
+ // Don't render if no more history is available
1028
+ if (!hasMoreHistory) {
1029
+ return null;
1030
+ }
1031
+
1032
+ // Render the trigger element that the intersection observer watches
1033
+ return /*#__PURE__*/_react.default.createElement(_LoadInlineBannerActivity.default, _extends({}, props || {}, {
1034
+ id: LazyLoadHandler.targetId
1035
+ }));
1036
+ };
1037
+ var _default = LazyLoadActivity;
1038
+ exports.default = _default;