@envive-ai/react-widgets-v3 0.3.21 → 0.3.23

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 (91) hide show
  1. package/dist/debug/chatEmbed.cjs +1 -1
  2. package/dist/debug/chatEmbed.js +1 -1
  3. package/dist/debug/reportIssue.cjs +1 -1
  4. package/dist/debug/reportIssue.js +1 -1
  5. package/dist/hocs/withBaseWidget/types.d.cts +5 -6
  6. package/dist/hocs/withBaseWidget/types.d.ts +5 -6
  7. package/dist/hocs/withBaseWidget/withBaseWidget.cjs +37 -43
  8. package/dist/hocs/withBaseWidget/withBaseWidget.d.cts +2 -2
  9. package/dist/hocs/withBaseWidget/withBaseWidget.d.ts +2 -2
  10. package/dist/hocs/withBaseWidget/withBaseWidget.js +39 -45
  11. package/dist/packages/widgets/dist/SearchResults/SearchResultsWidget.d.ts +2 -2
  12. package/dist/packages/widgets/dist/SearchZeroState/SearchZeroStateWidget.d.ts +2 -2
  13. package/dist/packages/widgets/dist/SuggestionBar/SuggestionBar.d.ts +2 -2
  14. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.cjs +34 -8
  15. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.cts +3 -3
  16. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.ts +3 -3
  17. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.js +35 -9
  18. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.cjs +13 -5
  19. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.cts +3 -3
  20. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.ts +3 -3
  21. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.js +13 -5
  22. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.cjs +32 -15
  23. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.cts +3 -3
  24. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.ts +3 -3
  25. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.js +35 -18
  26. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.cjs +36 -32
  27. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.cts +2 -2
  28. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.js +37 -33
  29. package/dist/widgets/FloatingChatWidget/hooks/useAutoPopup.cjs +2 -2
  30. package/dist/widgets/FloatingChatWidget/hooks/useAutoPopup.js +2 -2
  31. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.cjs +7 -1
  32. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.js +7 -1
  33. package/dist/widgets/ProductCardWidget/ProductCardWidget.cjs +31 -15
  34. package/dist/widgets/ProductCardWidget/ProductCardWidget.d.cts +2 -2
  35. package/dist/widgets/ProductCardWidget/ProductCardWidget.d.ts +2 -2
  36. package/dist/widgets/ProductCardWidget/ProductCardWidget.js +33 -17
  37. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.cjs +33 -16
  38. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.cts +3 -3
  39. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.ts +3 -3
  40. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.js +36 -19
  41. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.cjs +3 -12
  42. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.cts +2 -2
  43. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.ts +2 -2
  44. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.js +5 -14
  45. package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.d.cts +2 -2
  46. package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.d.ts +2 -2
  47. package/dist/widgets/SocialProofWidget/SocialProofWidget.cjs +34 -17
  48. package/dist/widgets/SocialProofWidget/SocialProofWidget.d.cts +3 -3
  49. package/dist/widgets/SocialProofWidget/SocialProofWidget.d.ts +3 -3
  50. package/dist/widgets/SocialProofWidget/SocialProofWidget.js +37 -20
  51. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.cjs +2 -11
  52. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.cts +2 -2
  53. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.ts +2 -2
  54. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.js +4 -13
  55. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.cts +2 -2
  56. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.ts +2 -2
  57. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.cjs +31 -14
  58. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.cts +3 -3
  59. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.ts +3 -3
  60. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.js +34 -17
  61. package/dist/widgets/dist/SearchResults/SearchResultsWidget.d.cts +2 -2
  62. package/dist/widgets/dist/SearchZeroState/SearchZeroStateWidget.d.cts +2 -2
  63. package/dist/widgets/dist/SuggestionBar/SuggestionBar.d.cts +2 -2
  64. package/dist/widgets/hooks/useGetWidgetStatus.cjs +1 -1
  65. package/dist/widgets/hooks/useGetWidgetStatus.js +1 -1
  66. package/dist/widgets/utils/functions.cjs +1 -1
  67. package/dist/widgets/utils/functions.js +1 -1
  68. package/package.json +1 -1
  69. package/src/hocs/withBaseWidget/__tests__/withBaseWidget.test.tsx +68 -302
  70. package/src/hocs/withBaseWidget/types.ts +6 -6
  71. package/src/hocs/withBaseWidget/withBaseWidget.tsx +46 -61
  72. package/src/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.tsx +33 -0
  73. package/src/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.tsx +9 -1
  74. package/src/widgets/ChatPreviewWidget/ChatPreviewWidget.tsx +34 -13
  75. package/src/widgets/ChatPreviewWidget/__tests__/ChatPreviewWidget.test.tsx +11 -5
  76. package/src/widgets/FloatingChatWidget/FloatingChatWidget.tsx +56 -38
  77. package/src/widgets/FloatingChatWidget/__tests__/FloatingChatWidget.test.tsx +11 -5
  78. package/src/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.tsx +8 -0
  79. package/src/widgets/ProductCardWidget/ProductCardWidget.tsx +37 -15
  80. package/src/widgets/ProductCardWidget/__tests__/ProductCardWidget.test.tsx +12 -8
  81. package/src/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.tsx +35 -13
  82. package/src/widgets/PromptButtonCarouselWithImageWidget/__tests__/PromptButtonCarouselWithImageWidget.test.tsx +19 -8
  83. package/src/widgets/PromptCarouselWidget/PromptCarouselWidget.tsx +1 -12
  84. package/src/widgets/PromptCarouselWidget/__tests__/PromptCarouselWidget.test.tsx +21 -8
  85. package/src/widgets/SocialProofWidget/SocialProofWidget.tsx +34 -12
  86. package/src/widgets/SocialProofWidget/__tests__/SocialProofWidget.test.tsx +19 -8
  87. package/src/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.tsx +1 -12
  88. package/src/widgets/TitledPromptCarouselWidget/__tests__/TitledPromptCarouselWidget.test.tsx +19 -8
  89. package/src/widgets/TypingAnimationWidget/TypingAnimationWidget.tsx +37 -14
  90. package/src/widgets/TypingAnimationWidget/__tests__/TypingAnimationWidget.test.tsx +19 -8
  91. package/src/widgets/__tests__/trackEventCanary.test.ts +1 -1
@@ -3,10 +3,10 @@ const require_MessageContent = require('./MessageContent.cjs');
3
3
  let react = require("react");
4
4
  react = require_rolldown_runtime.__toESM(react);
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
6
- let __envive_ai_react_hooks_atoms_chat = require("@envive-ai/react-hooks/atoms/chat");
7
6
  let jotai = require("jotai");
8
7
  let __envive_ai_react_hooks_application_models = require("@envive-ai/react-hooks/application/models");
9
8
  let __envive_ai_react_toolkit_v3_PromptCarousel = require("@envive-ai/react-toolkit-v3/PromptCarousel");
9
+ let __envive_ai_react_hooks_atoms_chat = require("@envive-ai/react-hooks/atoms/chat");
10
10
  let classnames = require("classnames");
11
11
  classnames = require_rolldown_runtime.__toESM(classnames);
12
12
 
@@ -1,10 +1,10 @@
1
1
  import { MessageContent } from "./MessageContent.js";
2
2
  import React from "react";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
- import { chatAtom } from "@envive-ai/react-hooks/atoms/chat";
5
4
  import { useAtomValue } from "jotai";
6
5
  import { MessageType } from "@envive-ai/react-hooks/application/models";
7
6
  import { PromptCarousel, PromptCarouselRows } from "@envive-ai/react-toolkit-v3/PromptCarousel";
7
+ import { chatAtom } from "@envive-ai/react-hooks/atoms/chat";
8
8
  import classNames from "classnames";
9
9
 
10
10
  //#region src/debug/chatEmbed.tsx
@@ -5,9 +5,9 @@ const require_GenericSelect = require('./GenericSelect.cjs');
5
5
  const require_chatEmbed = require('./chatEmbed.cjs');
6
6
  let react = require("react");
7
7
  let react_jsx_runtime = require("react/jsx-runtime");
8
- let __envive_ai_react_hooks_atoms_chat = require("@envive-ai/react-hooks/atoms/chat");
9
8
  let jotai = require("jotai");
10
9
  let __envive_ai_react_hooks_application_models = require("@envive-ai/react-hooks/application/models");
10
+ let __envive_ai_react_hooks_atoms_chat = require("@envive-ai/react-hooks/atoms/chat");
11
11
  let __envive_ai_react_hooks_atoms_app = require("@envive-ai/react-hooks/atoms/app");
12
12
  let classnames = require("classnames");
13
13
  classnames = require_rolldown_runtime.__toESM(classnames);
@@ -3,9 +3,9 @@ import { GenericSelect } from "./GenericSelect.js";
3
3
  import chatEmbed_default from "./chatEmbed.js";
4
4
  import { useCallback, useEffect, useState } from "react";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
- import { chatAtom, lastAssistantMessageAtom } from "@envive-ai/react-hooks/atoms/chat";
7
6
  import { useAtomValue } from "jotai";
8
7
  import { MessageType } from "@envive-ai/react-hooks/application/models";
8
+ import { chatAtom, lastAssistantMessageAtom } from "@envive-ai/react-hooks/atoms/chat";
9
9
  import { userIdAtom } from "@envive-ai/react-hooks/atoms/app";
10
10
  import { ReportSessionRequestReportPriorityEnum, ReportSessionRequestReportTypeEnum } from "@spiffy-ai/commerce-api-client";
11
11
  import classNames from "classnames";
@@ -1,5 +1,4 @@
1
1
  import { RefObject } from "react";
2
- import { SpiffyMetricsEventName } from "@envive-ai/react-hooks/contexts/amplitudeContext";
3
2
  import { HardcopyResponse } from "@envive-ai/react-hooks/contexts/hardcopyContext";
4
3
  import { OrgUIConfigV3, WidgetConfigV3, WidgetTypeV3 } from "@envive-ai/react-hooks/contexts/typesV3";
5
4
 
@@ -18,11 +17,6 @@ interface BaseWidgetProps {
18
17
  isUiConfigLoading?: boolean;
19
18
  }
20
19
  interface WithBaseWidgetOptions {
21
- /**
22
- * The Amplitude event name to track when the widget becomes visible.
23
- * Defaults to a generic component visible event if not provided.
24
- */
25
- visibilityEventName?: SpiffyMetricsEventName;
26
20
  /**
27
21
  * Additional properties to include with the visibility event.
28
22
  */
@@ -32,6 +26,11 @@ interface WithBaseWidgetOptions {
32
26
  * Defaults to '0px'.
33
27
  */
34
28
  rootMargin?: string;
29
+ /**
30
+ * Whether to defer loading of the widget until it is visible.
31
+ * Defaults to true
32
+ */
33
+ deferLoading?: boolean;
35
34
  }
36
35
  //#endregion
37
36
  export { BaseWidgetProps, WithBaseWidgetOptions };
@@ -1,5 +1,4 @@
1
1
  import { RefObject } from "react";
2
- import { SpiffyMetricsEventName } from "@envive-ai/react-hooks/contexts/amplitudeContext";
3
2
  import { HardcopyResponse } from "@envive-ai/react-hooks/contexts/hardcopyContext";
4
3
  import { OrgUIConfigV3, WidgetConfigV3, WidgetTypeV3 } from "@envive-ai/react-hooks/contexts/typesV3";
5
4
 
@@ -18,11 +17,6 @@ interface BaseWidgetProps {
18
17
  isUiConfigLoading?: boolean;
19
18
  }
20
19
  interface WithBaseWidgetOptions {
21
- /**
22
- * The Amplitude event name to track when the widget becomes visible.
23
- * Defaults to a generic component visible event if not provided.
24
- */
25
- visibilityEventName?: SpiffyMetricsEventName;
26
20
  /**
27
21
  * Additional properties to include with the visibility event.
28
22
  */
@@ -32,6 +26,11 @@ interface WithBaseWidgetOptions {
32
26
  * Defaults to '0px'.
33
27
  */
34
28
  rootMargin?: string;
29
+ /**
30
+ * Whether to defer loading of the widget until it is visible.
31
+ * Defaults to true
32
+ */
33
+ deferLoading?: boolean;
35
34
  }
36
35
  //#endregion
37
36
  export { BaseWidgetProps, WithBaseWidgetOptions };
@@ -1,6 +1,7 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  let react = require("react");
3
3
  let __envive_ai_react_hooks_contexts_amplitudeContext = require("@envive-ai/react-hooks/contexts/amplitudeContext");
4
+ let __envive_ai_react_hooks_hooks_TrackComponentVisibleEvent = require("@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent");
4
5
  let __envive_ai_react_hooks_contexts_hardcopyContext = require("@envive-ai/react-hooks/contexts/hardcopyContext");
5
6
  let __envive_ai_react_hooks_contexts_pageContext = require("@envive-ai/react-hooks/contexts/pageContext");
6
7
  let __envive_ai_react_hooks_contexts_widgetConfigContext = require("@envive-ai/react-hooks/contexts/widgetConfigContext");
@@ -12,9 +13,9 @@ function withBaseWidget(Widget, options) {
12
13
  const WrappedWidget = (props) => {
13
14
  const { widgetConfigId, widgetType } = props;
14
15
  const widgetRef = (0, react.useRef)(null);
15
- const hasTrackedEvent = (0, react.useRef)(false);
16
- const { trackEvent, isReady } = (0, __envive_ai_react_hooks_contexts_amplitudeContext.useAmplitude)();
16
+ const { isReady } = (0, __envive_ai_react_hooks_contexts_amplitudeContext.useAmplitude)();
17
17
  const [hardcopyContent, setHardcopyContent] = (0, react.useState)(void 0);
18
+ const hardcopyFetchedRef = (0, react.useRef)(false);
18
19
  const { getHardcopy, isLoading: isHardcopyLoading } = (0, __envive_ai_react_hooks_contexts_hardcopyContext.useHardcopy)();
19
20
  const { userEvent, isLoading: isPageLoading } = (0, __envive_ai_react_hooks_contexts_pageContext.usePage)();
20
21
  const [widgetConfig, setWidgetConfig] = (0, react.useState)(void 0);
@@ -22,75 +23,68 @@ function withBaseWidget(Widget, options) {
22
23
  const [uiConfig, setUiConfig] = (0, react.useState)(void 0);
23
24
  const { getUiConfig, isLoading: isUiConfigLoading } = (0, __envive_ai_react_hooks_contexts_uiConfigContext.useUiConfig)();
24
25
  const isLoading = isHardcopyLoading || isPageLoading || isWidgetConfigLoading || isUiConfigLoading;
25
- (0, react.useEffect)(() => {
26
- if (!isReady || hasTrackedEvent.current || !widgetRef.current) return;
27
- const observer = new IntersectionObserver(([entry]) => {
28
- if (entry.isIntersecting && !hasTrackedEvent.current) {
29
- trackEvent({
30
- eventName: options?.visibilityEventName || __envive_ai_react_hooks_contexts_amplitudeContext.SpiffyMetricsEventName.ChatComponentVisible,
31
- eventProps: {
32
- widget_config_id: widgetConfigId,
33
- widget_type: widgetType,
34
- ...options?.visibilityEventProps
35
- }
36
- });
37
- hasTrackedEvent.current = true;
38
- observer.disconnect();
39
- }
40
- }, { rootMargin: options?.rootMargin || "0px" });
41
- observer.observe(widgetRef.current);
42
- return () => {
43
- observer.disconnect();
44
- };
26
+ const { isVisible } = (0, __envive_ai_react_hooks_hooks_TrackComponentVisibleEvent.useTrackComponentVisibleEvent)(widgetRef, {
27
+ widget_config_id: widgetConfigId,
28
+ widget_type: widgetType,
29
+ ...options?.visibilityEventProps
30
+ }, options?.rootMargin || "0px", isReady);
31
+ const startLoading = (0, react.useMemo)(() => {
32
+ if (options?.deferLoading === false) return true;
33
+ return isVisible && !!widgetConfigId && !!widgetType;
45
34
  }, [
46
- isReady,
35
+ isVisible,
47
36
  widgetConfigId,
48
- widgetType,
49
- trackEvent
37
+ widgetType
50
38
  ]);
51
39
  (0, react.useEffect)(() => {
52
- if (!widgetType || !userEvent) return;
40
+ if (!startLoading || hardcopyFetchedRef.current) return;
41
+ hardcopyFetchedRef.current = true;
53
42
  getHardcopy({
54
43
  widgetType,
55
44
  userEvent
56
45
  }).then(setHardcopyContent).catch(() => {});
57
46
  }, [
58
- widgetConfigId,
47
+ startLoading,
59
48
  widgetType,
60
49
  getHardcopy,
61
- userEvent
50
+ userEvent,
51
+ widgetConfigId
62
52
  ]);
63
53
  (0, react.useEffect)(() => {
54
+ if (!startLoading) return;
64
55
  getUiConfig().then(setUiConfig).catch(() => {});
65
56
  }, [
57
+ startLoading,
66
58
  getUiConfig,
67
59
  widgetConfigId,
68
60
  widgetType
69
61
  ]);
70
62
  (0, react.useEffect)(() => {
71
- if (!widgetConfigId || !widgetType) return;
63
+ if (!startLoading) return;
72
64
  getWidgetConfig({
73
65
  widgetConfigId,
74
66
  widgetType
75
- }).then(setWidgetConfig).catch((e) => {
76
- console.error("Error getting widget config", widgetConfigId, widgetType, e);
77
- });
67
+ }).then(setWidgetConfig).catch(() => {});
78
68
  }, [
69
+ startLoading,
79
70
  widgetConfigId,
80
71
  widgetType,
81
72
  getWidgetConfig
82
73
  ]);
83
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Widget, {
84
- ...props,
85
- isLoading,
86
- isHardcopyLoading,
87
- isPageLoading,
88
- isWidgetConfigLoading,
89
- isUiConfigLoading,
90
- uiConfig,
91
- widgetConfig,
92
- hardcopyContent,
93
- observedWidget: widgetRef
74
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
75
+ ref: widgetRef,
76
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Widget, {
77
+ ...props,
78
+ isLoading,
79
+ isHardcopyLoading,
80
+ isPageLoading,
81
+ isWidgetConfigLoading,
82
+ isUiConfigLoading,
83
+ uiConfig,
84
+ widgetConfig,
85
+ hardcopyContent,
86
+ observedWidget: widgetRef
87
+ })
94
88
  });
95
89
  };
96
90
  WrappedWidget.displayName = `withBaseWidget(${Widget.displayName || Widget.name || "Component"})`;
@@ -1,9 +1,9 @@
1
1
  import { BaseWidgetProps, WithBaseWidgetOptions } from "./types.cjs";
2
- import * as react_jsx_runtime5 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime18 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/hocs/withBaseWidget/withBaseWidget.d.ts
5
5
  declare function withBaseWidget<P extends BaseWidgetProps>(Widget: React.ComponentType<P>, options?: WithBaseWidgetOptions): {
6
- (props: P): react_jsx_runtime5.JSX.Element;
6
+ (props: P): react_jsx_runtime18.JSX.Element;
7
7
  displayName: string;
8
8
  };
9
9
  //#endregion
@@ -1,9 +1,9 @@
1
1
  import { BaseWidgetProps, WithBaseWidgetOptions } from "./types.js";
2
- import * as react_jsx_runtime18 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime17 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/hocs/withBaseWidget/withBaseWidget.d.ts
5
5
  declare function withBaseWidget<P extends BaseWidgetProps>(Widget: React.ComponentType<P>, options?: WithBaseWidgetOptions): {
6
- (props: P): react_jsx_runtime18.JSX.Element;
6
+ (props: P): react_jsx_runtime17.JSX.Element;
7
7
  displayName: string;
8
8
  };
9
9
  //#endregion
@@ -1,5 +1,6 @@
1
- import { useEffect, useRef, useState } from "react";
2
- import { SpiffyMetricsEventName, useAmplitude } from "@envive-ai/react-hooks/contexts/amplitudeContext";
1
+ import { useEffect, useMemo, useRef, useState } from "react";
2
+ import { useAmplitude } from "@envive-ai/react-hooks/contexts/amplitudeContext";
3
+ import { useTrackComponentVisibleEvent } from "@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent";
3
4
  import { useHardcopy } from "@envive-ai/react-hooks/contexts/hardcopyContext";
4
5
  import { usePage } from "@envive-ai/react-hooks/contexts/pageContext";
5
6
  import { useWidgetConfig } from "@envive-ai/react-hooks/contexts/widgetConfigContext";
@@ -11,9 +12,9 @@ function withBaseWidget(Widget, options) {
11
12
  const WrappedWidget = (props) => {
12
13
  const { widgetConfigId, widgetType } = props;
13
14
  const widgetRef = useRef(null);
14
- const hasTrackedEvent = useRef(false);
15
- const { trackEvent, isReady } = useAmplitude();
15
+ const { isReady } = useAmplitude();
16
16
  const [hardcopyContent, setHardcopyContent] = useState(void 0);
17
+ const hardcopyFetchedRef = useRef(false);
17
18
  const { getHardcopy, isLoading: isHardcopyLoading } = useHardcopy();
18
19
  const { userEvent, isLoading: isPageLoading } = usePage();
19
20
  const [widgetConfig, setWidgetConfig] = useState(void 0);
@@ -21,75 +22,68 @@ function withBaseWidget(Widget, options) {
21
22
  const [uiConfig, setUiConfig] = useState(void 0);
22
23
  const { getUiConfig, isLoading: isUiConfigLoading } = useUiConfig();
23
24
  const isLoading = isHardcopyLoading || isPageLoading || isWidgetConfigLoading || isUiConfigLoading;
24
- useEffect(() => {
25
- if (!isReady || hasTrackedEvent.current || !widgetRef.current) return;
26
- const observer = new IntersectionObserver(([entry]) => {
27
- if (entry.isIntersecting && !hasTrackedEvent.current) {
28
- trackEvent({
29
- eventName: options?.visibilityEventName || SpiffyMetricsEventName.ChatComponentVisible,
30
- eventProps: {
31
- widget_config_id: widgetConfigId,
32
- widget_type: widgetType,
33
- ...options?.visibilityEventProps
34
- }
35
- });
36
- hasTrackedEvent.current = true;
37
- observer.disconnect();
38
- }
39
- }, { rootMargin: options?.rootMargin || "0px" });
40
- observer.observe(widgetRef.current);
41
- return () => {
42
- observer.disconnect();
43
- };
25
+ const { isVisible } = useTrackComponentVisibleEvent(widgetRef, {
26
+ widget_config_id: widgetConfigId,
27
+ widget_type: widgetType,
28
+ ...options?.visibilityEventProps
29
+ }, options?.rootMargin || "0px", isReady);
30
+ const startLoading = useMemo(() => {
31
+ if (options?.deferLoading === false) return true;
32
+ return isVisible && !!widgetConfigId && !!widgetType;
44
33
  }, [
45
- isReady,
34
+ isVisible,
46
35
  widgetConfigId,
47
- widgetType,
48
- trackEvent
36
+ widgetType
49
37
  ]);
50
38
  useEffect(() => {
51
- if (!widgetType || !userEvent) return;
39
+ if (!startLoading || hardcopyFetchedRef.current) return;
40
+ hardcopyFetchedRef.current = true;
52
41
  getHardcopy({
53
42
  widgetType,
54
43
  userEvent
55
44
  }).then(setHardcopyContent).catch(() => {});
56
45
  }, [
57
- widgetConfigId,
46
+ startLoading,
58
47
  widgetType,
59
48
  getHardcopy,
60
- userEvent
49
+ userEvent,
50
+ widgetConfigId
61
51
  ]);
62
52
  useEffect(() => {
53
+ if (!startLoading) return;
63
54
  getUiConfig().then(setUiConfig).catch(() => {});
64
55
  }, [
56
+ startLoading,
65
57
  getUiConfig,
66
58
  widgetConfigId,
67
59
  widgetType
68
60
  ]);
69
61
  useEffect(() => {
70
- if (!widgetConfigId || !widgetType) return;
62
+ if (!startLoading) return;
71
63
  getWidgetConfig({
72
64
  widgetConfigId,
73
65
  widgetType
74
- }).then(setWidgetConfig).catch((e) => {
75
- console.error("Error getting widget config", widgetConfigId, widgetType, e);
76
- });
66
+ }).then(setWidgetConfig).catch(() => {});
77
67
  }, [
68
+ startLoading,
78
69
  widgetConfigId,
79
70
  widgetType,
80
71
  getWidgetConfig
81
72
  ]);
82
- return /* @__PURE__ */ jsx(Widget, {
83
- ...props,
84
- isLoading,
85
- isHardcopyLoading,
86
- isPageLoading,
87
- isWidgetConfigLoading,
88
- isUiConfigLoading,
89
- uiConfig,
90
- widgetConfig,
91
- hardcopyContent,
92
- observedWidget: widgetRef
73
+ return /* @__PURE__ */ jsx("span", {
74
+ ref: widgetRef,
75
+ children: /* @__PURE__ */ jsx(Widget, {
76
+ ...props,
77
+ isLoading,
78
+ isHardcopyLoading,
79
+ isPageLoading,
80
+ isWidgetConfigLoading,
81
+ isUiConfigLoading,
82
+ uiConfig,
83
+ widgetConfig,
84
+ hardcopyContent,
85
+ observedWidget: widgetRef
86
+ })
93
87
  });
94
88
  };
95
89
  WrappedWidget.displayName = `withBaseWidget(${Widget.displayName || Widget.name || "Component"})`;
@@ -1,8 +1,8 @@
1
- import * as react_jsx_runtime0 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
2
2
 
3
3
  //#region ../widgets/dist/SearchResults/SearchResultsWidget.d.ts
4
4
  //#region src/SearchResults/SearchResultsWidget.d.ts
5
- declare const SearchResultsWidget: () => react_jsx_runtime0.JSX.Element;
5
+ declare const SearchResultsWidget: () => react_jsx_runtime1.JSX.Element;
6
6
  //#endregion
7
7
 
8
8
  //#endregion
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime2 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
2
2
 
3
3
  //#region ../widgets/dist/SearchZeroState/SearchZeroStateWidget.d.ts
4
4
  //#region src/SearchZeroState/SearchZeroStateWidget.d.ts
@@ -11,7 +11,7 @@ declare const SearchZeroStateWidget: ({
11
11
  initialIsOpen,
12
12
  widgetConfigId,
13
13
  entryPointRef
14
- }: SearchZeroStateWidgetProps) => react_jsx_runtime2.JSX.Element;
14
+ }: SearchZeroStateWidgetProps) => react_jsx_runtime3.JSX.Element;
15
15
  //#endregion
16
16
 
17
17
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { SuggestionBarLocationForMetrics } from "./types.js";
2
- import * as react_jsx_runtime3 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
3
3
  import { SuggestionButtonVariant } from "@envive-ai/react-hooks/contexts/types";
4
4
  import { Message } from "postcss";
5
5
 
@@ -30,7 +30,7 @@ declare function SuggestionBar({
30
30
  buttonBorderRadius,
31
31
  handleReply,
32
32
  dataTestId
33
- }: Readonly<SuggestionBarProps>): react_jsx_runtime3.JSX.Element;
33
+ }: Readonly<SuggestionBarProps>): react_jsx_runtime2.JSX.Element;
34
34
  //#endregion
35
35
  //#endregion
36
36
  export { SuggestionBar };
@@ -5,18 +5,19 @@ const require_ChatPreviewLoadingWidget = require('../ChatPreviewLoadingWidget/Ch
5
5
  let react = require("react");
6
6
  let __envive_ai_react_hooks_contexts_amplitudeContext = require("@envive-ai/react-hooks/contexts/amplitudeContext");
7
7
  let react_jsx_runtime = require("react/jsx-runtime");
8
- let __envive_ai_react_hooks_atoms_chat = require("@envive-ai/react-hooks/atoms/chat");
9
- let __envive_ai_react_hooks_contexts_salesAgentContext = require("@envive-ai/react-hooks/contexts/salesAgentContext");
10
8
  let __envive_ai_react_hooks_contexts_typesV3 = require("@envive-ai/react-hooks/contexts/typesV3");
11
- let __envive_ai_react_hooks_hooks_ChatToggle = require("@envive-ai/react-hooks/hooks/ChatToggle");
12
9
  let jotai = require("jotai");
10
+ let __envive_ai_react_hooks_contexts_featureFlagServiceContext = require("@envive-ai/react-hooks/contexts/featureFlagServiceContext");
13
11
  let __envive_ai_react_hooks_application_models = require("@envive-ai/react-hooks/application/models");
14
- let __envive_ai_react_hooks_atoms_app = require("@envive-ai/react-hooks/atoms/app");
15
- let __envive_ai_react_hooks_hooks_WidgetInteraction = require("@envive-ai/react-hooks/hooks/WidgetInteraction");
12
+ let __envive_ai_react_hooks_contexts_salesAgentContext = require("@envive-ai/react-hooks/contexts/salesAgentContext");
13
+ let __envive_ai_react_hooks_hooks_ChatToggle = require("@envive-ai/react-hooks/hooks/ChatToggle");
16
14
  let __envive_ai_react_hooks_hooks_WidgetInteraction_types = require("@envive-ai/react-hooks/hooks/WidgetInteraction/types");
17
- let __envive_ai_react_toolkit_v3_ChatPreviewComparison = require("@envive-ai/react-toolkit-v3/ChatPreviewComparison");
18
15
  let __envive_ai_react_toolkit_v3_PromptCarousel = require("@envive-ai/react-toolkit-v3/PromptCarousel");
19
16
  let __envive_ai_react_toolkit_v3_Tokens = require("@envive-ai/react-toolkit-v3/Tokens");
17
+ let __envive_ai_react_hooks_atoms_chat = require("@envive-ai/react-hooks/atoms/chat");
18
+ let __envive_ai_react_hooks_atoms_app = require("@envive-ai/react-hooks/atoms/app");
19
+ let __envive_ai_react_hooks_hooks_WidgetInteraction = require("@envive-ai/react-hooks/hooks/WidgetInteraction");
20
+ let __envive_ai_react_toolkit_v3_ChatPreviewComparison = require("@envive-ai/react-toolkit-v3/ChatPreviewComparison");
20
21
 
21
22
  //#region src/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.tsx
22
23
  const ChatPreviewComparisonWidgetHandler = (props) => {
@@ -45,6 +46,9 @@ const ChatPreviewComparisonWidgetHandler = (props) => {
45
46
  };
46
47
  const logoSrc = uiConfig?.lookAndFeel?.widgetLogoSrc;
47
48
  const hideLogo = uiConfig?.lookAndFeel?.hideWidgetLogo;
49
+ const voiceInputEnabled = uiConfig?.lookAndFeel?.voiceInputEnabled;
50
+ const { featureFlagService } = (0, __envive_ai_react_hooks_contexts_featureFlagServiceContext.useFeatureFlagService)();
51
+ const isVoiceInputEnabled = featureFlagService?.isFeatureGateEnabled(__envive_ai_react_hooks_application_models.FeatureGates.IsVoiceInputEnabled) || voiceInputEnabled;
48
52
  const handlePromptButtonClick = (0, react.useCallback)((suggestion) => {
49
53
  onSuggestionClicked(suggestion, __envive_ai_react_hooks_application_models.ChatElementDisplayLocationV3.CHAT_PREVIEW_COMPARISON_PROMPT_BUTTON);
50
54
  openChat(__envive_ai_react_hooks_application_models.ChatElementDisplayLocationV3.CHAT_PREVIEW_COMPARISON_PROMPT_BUTTON);
@@ -60,6 +64,25 @@ const ChatPreviewComparisonWidgetHandler = (props) => {
60
64
  }
61
65
  });
62
66
  }, [openChat]);
67
+ const handleTranscriptionStarted = (0, react.useCallback)(() => {
68
+ trackWidgetInteraction({
69
+ eventName: __envive_ai_react_hooks_contexts_amplitudeContext.EnviveMetricsEventName.WidgetInteraction,
70
+ trigger: {
71
+ widget: __envive_ai_react_hooks_hooks_WidgetInteraction_types.WidgetInteractionComponent.POST_INTERACTION_COMPARISON,
72
+ widget_interaction: __envive_ai_react_hooks_hooks_WidgetInteraction_types.WidgetInteractionType.VOICE_TRANSCRIPTION_STARTED
73
+ }
74
+ });
75
+ }, []);
76
+ const handleTranscriptionCompleted = (0, react.useCallback)((transcript) => {
77
+ trackWidgetInteraction({
78
+ eventName: __envive_ai_react_hooks_contexts_amplitudeContext.EnviveMetricsEventName.WidgetInteraction,
79
+ trigger: {
80
+ widget: __envive_ai_react_hooks_hooks_WidgetInteraction_types.WidgetInteractionComponent.POST_INTERACTION_COMPARISON,
81
+ widget_interaction: __envive_ai_react_hooks_hooks_WidgetInteraction_types.WidgetInteractionType.VOICE_TRANSCRIPTION_COMPLETED,
82
+ widget_interaction_data: { transcription: transcript }
83
+ }
84
+ });
85
+ }, []);
63
86
  const handleLinkClick = (url) => {
64
87
  trackWidgetInteraction({
65
88
  eventName: __envive_ai_react_hooks_contexts_amplitudeContext.EnviveMetricsEventName.WidgetInteraction,
@@ -89,7 +112,8 @@ const ChatPreviewComparisonWidgetHandler = (props) => {
89
112
  promptButtons: suggestions,
90
113
  textFieldPlaceholderText: hardCopyContent?.textFieldPlaceholderText,
91
114
  images: images ?? [],
92
- logoSrc: logoSrc ?? void 0
115
+ logoSrc: logoSrc ?? void 0,
116
+ voiceInputEnabled: isVoiceInputEnabled
93
117
  };
94
118
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__envive_ai_react_toolkit_v3_ChatPreviewComparison.ChatPreviewComparison, {
95
119
  baseProps: { id },
@@ -104,7 +128,9 @@ const ChatPreviewComparisonWidgetHandler = (props) => {
104
128
  handlePromptButtonTouchStart: onTouchStart,
105
129
  handlePromptButtonTouchEnd: onTouchEnd,
106
130
  handleLinkClick,
107
- handleTextFieldClick
131
+ handleTextFieldClick,
132
+ onTranscriptionStarted: handleTranscriptionStarted,
133
+ onTranscriptionCompleted: handleTranscriptionCompleted
108
134
  }
109
135
  });
110
136
  };
@@ -1,9 +1,9 @@
1
1
  import { BaseWidgetProps } from "../../hocs/withBaseWidget/types.cjs";
2
- import * as react_jsx_runtime18 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime15 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.ts
5
5
  declare const ChatPreviewComparisonWidgetWithBaseWidget: {
6
- (props: BaseWidgetProps): react_jsx_runtime18.JSX.Element;
6
+ (props: BaseWidgetProps): react_jsx_runtime15.JSX.Element;
7
7
  displayName: string;
8
8
  };
9
9
  interface ChatPreviewComparisonWidgetProps {
@@ -12,7 +12,7 @@ interface ChatPreviewComparisonWidgetProps {
12
12
  declare const ChatPreviewComparisonWidget: {
13
13
  ({
14
14
  widgetConfigId
15
- }: ChatPreviewComparisonWidgetProps): react_jsx_runtime18.JSX.Element;
15
+ }: ChatPreviewComparisonWidgetProps): react_jsx_runtime15.JSX.Element;
16
16
  displayName: string;
17
17
  };
18
18
  //#endregion
@@ -1,9 +1,9 @@
1
1
  import { BaseWidgetProps } from "../../hocs/withBaseWidget/types.js";
2
- import * as react_jsx_runtime16 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime8 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.ts
5
5
  declare const ChatPreviewComparisonWidgetWithBaseWidget: {
6
- (props: BaseWidgetProps): react_jsx_runtime16.JSX.Element;
6
+ (props: BaseWidgetProps): react_jsx_runtime8.JSX.Element;
7
7
  displayName: string;
8
8
  };
9
9
  interface ChatPreviewComparisonWidgetProps {
@@ -12,7 +12,7 @@ interface ChatPreviewComparisonWidgetProps {
12
12
  declare const ChatPreviewComparisonWidget: {
13
13
  ({
14
14
  widgetConfigId
15
- }: ChatPreviewComparisonWidgetProps): react_jsx_runtime16.JSX.Element;
15
+ }: ChatPreviewComparisonWidgetProps): react_jsx_runtime8.JSX.Element;
16
16
  displayName: string;
17
17
  };
18
18
  //#endregion
@@ -4,18 +4,19 @@ import { ChatPreviewLoadingWidgetWithBaseWidget } from "../ChatPreviewLoadingWid
4
4
  import { useCallback, useMemo } from "react";
5
5
  import { EnviveMetricsEventName } from "@envive-ai/react-hooks/contexts/amplitudeContext";
6
6
  import { jsx } from "react/jsx-runtime";
7
- import { chatAtom, lastAssistantMessageAtom } from "@envive-ai/react-hooks/atoms/chat";
8
- import { useSalesAgent } from "@envive-ai/react-hooks/contexts/salesAgentContext";
9
7
  import { WidgetTypeV3 } from "@envive-ai/react-hooks/contexts/typesV3";
10
- import { useChatToggle } from "@envive-ai/react-hooks/hooks/ChatToggle";
11
8
  import { useAtomValue } from "jotai";
12
- import { ChatElementDisplayLocationV3, VariantTypeEnum } from "@envive-ai/react-hooks/application/models";
13
- import { variantInfoAtom } from "@envive-ai/react-hooks/atoms/app";
14
- import { useWidgetInteraction } from "@envive-ai/react-hooks/hooks/WidgetInteraction";
9
+ import { useFeatureFlagService } from "@envive-ai/react-hooks/contexts/featureFlagServiceContext";
10
+ import { ChatElementDisplayLocationV3, FeatureGates, VariantTypeEnum } from "@envive-ai/react-hooks/application/models";
11
+ import { useSalesAgent } from "@envive-ai/react-hooks/contexts/salesAgentContext";
12
+ import { useChatToggle } from "@envive-ai/react-hooks/hooks/ChatToggle";
15
13
  import { WidgetInteractionComponent, WidgetInteractionType } from "@envive-ai/react-hooks/hooks/WidgetInteraction/types";
16
- import { ChatPreviewComparison } from "@envive-ai/react-toolkit-v3/ChatPreviewComparison";
17
14
  import { usePromptCarouselAnalytics } from "@envive-ai/react-toolkit-v3/PromptCarousel";
18
15
  import { Theme } from "@envive-ai/react-toolkit-v3/Tokens";
16
+ import { chatAtom, lastAssistantMessageAtom } from "@envive-ai/react-hooks/atoms/chat";
17
+ import { variantInfoAtom } from "@envive-ai/react-hooks/atoms/app";
18
+ import { useWidgetInteraction } from "@envive-ai/react-hooks/hooks/WidgetInteraction";
19
+ import { ChatPreviewComparison } from "@envive-ai/react-toolkit-v3/ChatPreviewComparison";
19
20
 
20
21
  //#region src/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.tsx
21
22
  const ChatPreviewComparisonWidgetHandler = (props) => {
@@ -44,6 +45,9 @@ const ChatPreviewComparisonWidgetHandler = (props) => {
44
45
  };
45
46
  const logoSrc = uiConfig?.lookAndFeel?.widgetLogoSrc;
46
47
  const hideLogo = uiConfig?.lookAndFeel?.hideWidgetLogo;
48
+ const voiceInputEnabled = uiConfig?.lookAndFeel?.voiceInputEnabled;
49
+ const { featureFlagService } = useFeatureFlagService();
50
+ const isVoiceInputEnabled = featureFlagService?.isFeatureGateEnabled(FeatureGates.IsVoiceInputEnabled) || voiceInputEnabled;
47
51
  const handlePromptButtonClick = useCallback((suggestion) => {
48
52
  onSuggestionClicked(suggestion, ChatElementDisplayLocationV3.CHAT_PREVIEW_COMPARISON_PROMPT_BUTTON);
49
53
  openChat(ChatElementDisplayLocationV3.CHAT_PREVIEW_COMPARISON_PROMPT_BUTTON);
@@ -59,6 +63,25 @@ const ChatPreviewComparisonWidgetHandler = (props) => {
59
63
  }
60
64
  });
61
65
  }, [openChat]);
66
+ const handleTranscriptionStarted = useCallback(() => {
67
+ trackWidgetInteraction({
68
+ eventName: EnviveMetricsEventName.WidgetInteraction,
69
+ trigger: {
70
+ widget: WidgetInteractionComponent.POST_INTERACTION_COMPARISON,
71
+ widget_interaction: WidgetInteractionType.VOICE_TRANSCRIPTION_STARTED
72
+ }
73
+ });
74
+ }, []);
75
+ const handleTranscriptionCompleted = useCallback((transcript) => {
76
+ trackWidgetInteraction({
77
+ eventName: EnviveMetricsEventName.WidgetInteraction,
78
+ trigger: {
79
+ widget: WidgetInteractionComponent.POST_INTERACTION_COMPARISON,
80
+ widget_interaction: WidgetInteractionType.VOICE_TRANSCRIPTION_COMPLETED,
81
+ widget_interaction_data: { transcription: transcript }
82
+ }
83
+ });
84
+ }, []);
62
85
  const handleLinkClick = (url) => {
63
86
  trackWidgetInteraction({
64
87
  eventName: EnviveMetricsEventName.WidgetInteraction,
@@ -88,7 +111,8 @@ const ChatPreviewComparisonWidgetHandler = (props) => {
88
111
  promptButtons: suggestions,
89
112
  textFieldPlaceholderText: hardCopyContent?.textFieldPlaceholderText,
90
113
  images: images ?? [],
91
- logoSrc: logoSrc ?? void 0
114
+ logoSrc: logoSrc ?? void 0,
115
+ voiceInputEnabled: isVoiceInputEnabled
92
116
  };
93
117
  return /* @__PURE__ */ jsx(ChatPreviewComparison, {
94
118
  baseProps: { id },
@@ -103,7 +127,9 @@ const ChatPreviewComparisonWidgetHandler = (props) => {
103
127
  handlePromptButtonTouchStart: onTouchStart,
104
128
  handlePromptButtonTouchEnd: onTouchEnd,
105
129
  handleLinkClick,
106
- handleTextFieldClick
130
+ handleTextFieldClick,
131
+ onTranscriptionStarted: handleTranscriptionStarted,
132
+ onTranscriptionCompleted: handleTranscriptionCompleted
107
133
  }
108
134
  });
109
135
  };