@cobbai/react-native-sdk 1.0.0-beta.0

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 (143) hide show
  1. package/CobbaiMobileRnSdk.podspec +22 -0
  2. package/LICENSE +32 -0
  3. package/README.md +386 -0
  4. package/dist/ChatPlaceholder.d.ts +13 -0
  5. package/dist/ChatPlaceholder.d.ts.map +1 -0
  6. package/dist/ChatPlaceholder.js +87 -0
  7. package/dist/CobbaiChatScreen.d.ts +4 -0
  8. package/dist/CobbaiChatScreen.d.ts.map +1 -0
  9. package/dist/CobbaiChatScreen.js +196 -0
  10. package/dist/CobbaiInAppBanner.d.ts +15 -0
  11. package/dist/CobbaiInAppBanner.d.ts.map +1 -0
  12. package/dist/CobbaiInAppBanner.js +159 -0
  13. package/dist/CobbaiLauncher.d.ts +19 -0
  14. package/dist/CobbaiLauncher.d.ts.map +1 -0
  15. package/dist/CobbaiLauncher.js +149 -0
  16. package/dist/CobbaiWebView.d.ts +28 -0
  17. package/dist/CobbaiWebView.d.ts.map +1 -0
  18. package/dist/CobbaiWebView.js +141 -0
  19. package/dist/adapters/expoAdapter.d.ts +85 -0
  20. package/dist/adapters/expoAdapter.d.ts.map +1 -0
  21. package/dist/adapters/expoAdapter.js +152 -0
  22. package/dist/adapters/firebaseAdapter.d.ts +41 -0
  23. package/dist/adapters/firebaseAdapter.d.ts.map +1 -0
  24. package/dist/adapters/firebaseAdapter.js +139 -0
  25. package/dist/adapters/iosRelayAdapter.d.ts +26 -0
  26. package/dist/adapters/iosRelayAdapter.d.ts.map +1 -0
  27. package/dist/adapters/iosRelayAdapter.js +101 -0
  28. package/dist/androidKeyboardFrame.d.ts +16 -0
  29. package/dist/androidKeyboardFrame.d.ts.map +1 -0
  30. package/dist/androidKeyboardFrame.js +34 -0
  31. package/dist/bridge/messages.d.ts +20 -0
  32. package/dist/bridge/messages.d.ts.map +1 -0
  33. package/dist/bridge/messages.js +20 -0
  34. package/dist/bridge/nativeEvent.d.ts +10 -0
  35. package/dist/bridge/nativeEvent.d.ts.map +1 -0
  36. package/dist/bridge/nativeEvent.js +15 -0
  37. package/dist/bridge/parser.d.ts +29 -0
  38. package/dist/bridge/parser.d.ts.map +1 -0
  39. package/dist/bridge/parser.js +109 -0
  40. package/dist/chatPresentation.d.ts +19 -0
  41. package/dist/chatPresentation.d.ts.map +1 -0
  42. package/dist/chatPresentation.js +51 -0
  43. package/dist/chatScreen/useInAppBannerQueue.d.ts +22 -0
  44. package/dist/chatScreen/useInAppBannerQueue.d.ts.map +1 -0
  45. package/dist/chatScreen/useInAppBannerQueue.js +60 -0
  46. package/dist/chatScreen/useKeyboardFrame.d.ts +14 -0
  47. package/dist/chatScreen/useKeyboardFrame.d.ts.map +1 -0
  48. package/dist/chatScreen/useKeyboardFrame.js +63 -0
  49. package/dist/chatScreen/useLauncherPresentation.d.ts +20 -0
  50. package/dist/chatScreen/useLauncherPresentation.d.ts.map +1 -0
  51. package/dist/chatScreen/useLauncherPresentation.js +76 -0
  52. package/dist/chatScreen/useNativeToWebSync.d.ts +17 -0
  53. package/dist/chatScreen/useNativeToWebSync.d.ts.map +1 -0
  54. package/dist/chatScreen/useNativeToWebSync.js +36 -0
  55. package/dist/chatScreen/usePushIntegration.d.ts +19 -0
  56. package/dist/chatScreen/usePushIntegration.d.ts.map +1 -0
  57. package/dist/chatScreen/usePushIntegration.js +129 -0
  58. package/dist/chatScreen/useReadyLifecycle.d.ts +33 -0
  59. package/dist/chatScreen/useReadyLifecycle.d.ts.map +1 -0
  60. package/dist/chatScreen/useReadyLifecycle.js +138 -0
  61. package/dist/chatScreen/useSheetPresentation.d.ts +25 -0
  62. package/dist/chatScreen/useSheetPresentation.d.ts.map +1 -0
  63. package/dist/chatScreen/useSheetPresentation.js +98 -0
  64. package/dist/chatUnavailable.d.ts +23 -0
  65. package/dist/chatUnavailable.d.ts.map +1 -0
  66. package/dist/chatUnavailable.js +36 -0
  67. package/dist/externalLinks.d.ts +4 -0
  68. package/dist/externalLinks.d.ts.map +1 -0
  69. package/dist/externalLinks.js +48 -0
  70. package/dist/host/buildHostHtml.d.ts +7 -0
  71. package/dist/host/buildHostHtml.d.ts.map +1 -0
  72. package/dist/host/buildHostHtml.js +101 -0
  73. package/dist/host/hostPageKey.d.ts +7 -0
  74. package/dist/host/hostPageKey.d.ts.map +1 -0
  75. package/dist/host/hostPageKey.js +18 -0
  76. package/dist/inAppBanner.d.ts +19 -0
  77. package/dist/inAppBanner.d.ts.map +1 -0
  78. package/dist/inAppBanner.js +42 -0
  79. package/dist/index.d.ts +10 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +32 -0
  82. package/dist/launcher.d.ts +25 -0
  83. package/dist/launcher.d.ts.map +1 -0
  84. package/dist/launcher.js +55 -0
  85. package/dist/launcherGlyph.d.ts +2 -0
  86. package/dist/launcherGlyph.d.ts.map +1 -0
  87. package/dist/launcherGlyph.js +5 -0
  88. package/dist/openChatScreen.d.ts +13 -0
  89. package/dist/openChatScreen.d.ts.map +1 -0
  90. package/dist/openChatScreen.js +63 -0
  91. package/dist/push.d.ts +59 -0
  92. package/dist/push.d.ts.map +1 -0
  93. package/dist/push.js +309 -0
  94. package/dist/pushIntegration.d.ts +76 -0
  95. package/dist/pushIntegration.d.ts.map +1 -0
  96. package/dist/pushIntegration.js +244 -0
  97. package/dist/pushLogout.d.ts +57 -0
  98. package/dist/pushLogout.d.ts.map +1 -0
  99. package/dist/pushLogout.js +225 -0
  100. package/dist/types.d.ts +42 -0
  101. package/dist/types.d.ts.map +1 -0
  102. package/dist/types.js +2 -0
  103. package/dist/version.d.ts +8 -0
  104. package/dist/version.d.ts.map +1 -0
  105. package/dist/version.js +10 -0
  106. package/ios/CobbaiPush.m +96 -0
  107. package/ios/CobbaiPushRelay.h +59 -0
  108. package/ios/CobbaiPushRelay.m +364 -0
  109. package/package.json +69 -0
  110. package/src/ChatPlaceholder.tsx +132 -0
  111. package/src/CobbaiChatScreen.tsx +348 -0
  112. package/src/CobbaiInAppBanner.tsx +237 -0
  113. package/src/CobbaiLauncher.tsx +223 -0
  114. package/src/CobbaiWebView.tsx +242 -0
  115. package/src/adapters/expoAdapter.ts +227 -0
  116. package/src/adapters/firebaseAdapter.ts +201 -0
  117. package/src/adapters/iosRelayAdapter.ts +137 -0
  118. package/src/androidKeyboardFrame.ts +56 -0
  119. package/src/bridge/messages.ts +24 -0
  120. package/src/bridge/nativeEvent.ts +12 -0
  121. package/src/bridge/parser.ts +159 -0
  122. package/src/chatPresentation.ts +73 -0
  123. package/src/chatScreen/useInAppBannerQueue.ts +91 -0
  124. package/src/chatScreen/useKeyboardFrame.ts +89 -0
  125. package/src/chatScreen/useLauncherPresentation.ts +121 -0
  126. package/src/chatScreen/useNativeToWebSync.ts +54 -0
  127. package/src/chatScreen/usePushIntegration.ts +191 -0
  128. package/src/chatScreen/useReadyLifecycle.ts +186 -0
  129. package/src/chatScreen/useSheetPresentation.ts +147 -0
  130. package/src/chatUnavailable.ts +58 -0
  131. package/src/externalLinks.ts +56 -0
  132. package/src/host/buildHostHtml.ts +117 -0
  133. package/src/host/hostPageKey.ts +17 -0
  134. package/src/inAppBanner.ts +58 -0
  135. package/src/index.ts +53 -0
  136. package/src/launcher.ts +79 -0
  137. package/src/launcherGlyph.ts +3 -0
  138. package/src/openChatScreen.ts +78 -0
  139. package/src/push.ts +424 -0
  140. package/src/pushIntegration.ts +338 -0
  141. package/src/pushLogout.ts +277 -0
  142. package/src/types.ts +46 -0
  143. package/src/version.ts +8 -0
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CobbaiChatScreen = CobbaiChatScreen;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const react_native_safe_area_context_1 = require("react-native-safe-area-context");
8
+ const CobbaiWebView_1 = require("./CobbaiWebView");
9
+ const hostPageKey_1 = require("./host/hostPageKey");
10
+ const androidKeyboardFrame_1 = require("./androidKeyboardFrame");
11
+ const chatPresentation_1 = require("./chatPresentation");
12
+ const ChatPlaceholder_1 = require("./ChatPlaceholder");
13
+ const CobbaiInAppBanner_1 = require("./CobbaiInAppBanner");
14
+ const buildHostHtml_1 = require("./host/buildHostHtml");
15
+ const openChatScreen_1 = require("./openChatScreen");
16
+ const push_1 = require("./push");
17
+ const pushLogout_1 = require("./pushLogout");
18
+ const chatUnavailable_1 = require("./chatUnavailable");
19
+ const launcher_1 = require("./launcher");
20
+ const CobbaiLauncher_1 = require("./CobbaiLauncher");
21
+ const useInAppBannerQueue_1 = require("./chatScreen/useInAppBannerQueue");
22
+ const useKeyboardFrame_1 = require("./chatScreen/useKeyboardFrame");
23
+ const useLauncherPresentation_1 = require("./chatScreen/useLauncherPresentation");
24
+ const useNativeToWebSync_1 = require("./chatScreen/useNativeToWebSync");
25
+ const usePushIntegration_1 = require("./chatScreen/usePushIntegration");
26
+ const useReadyLifecycle_1 = require("./chatScreen/useReadyLifecycle");
27
+ const useSheetPresentation_1 = require("./chatScreen/useSheetPresentation");
28
+ function CobbaiChatScreen(props) {
29
+ const { config, prewarm = true, launcherVisible = true, launcherBottomOffset, inAppBanner = true, } = props;
30
+ // Latest config for callbacks read from effects and stable handlers: an integrator passing a
31
+ // new `config` object on each render must not restart the ready timer or re-subscribe handlers.
32
+ const configRef = (0, react_1.useRef)(config);
33
+ configRef.current = config;
34
+ const webViewRef = (0, react_1.useRef)(null);
35
+ const [unreadTotal, setUnreadTotal] = (0, react_1.useState)(null);
36
+ const hasReportedUnreadRef = (0, react_1.useRef)(false);
37
+ const lastReportedUnreadRef = (0, react_1.useRef)(null);
38
+ const { top, right, bottom, left } = (0, react_native_safe_area_context_1.useSafeAreaInsets)();
39
+ const safeArea = (0, react_1.useMemo)(() => (0, buildHostHtml_1.normalizeSafeAreaInsets)({ top, right, bottom, left }), [top, right, bottom, left]);
40
+ // Frozen on first render: the host HTML must not be rebuilt when insets change.
41
+ const initialSafeAreaRef = (0, react_1.useRef)((0, chatPresentation_1.toSheetSafeAreaInsetsForWeb)(safeArea));
42
+ // Runs when the close slide ends; the hooks it calls into are declared below.
43
+ const handleSheetDismissed = () => {
44
+ resetKeyboardMetrics();
45
+ if (!prewarm) {
46
+ // The WebView unmounts with the sheet: the next open waits for a fresh ready.
47
+ resetReady();
48
+ setUnreadTotal(null);
49
+ }
50
+ };
51
+ const pageKey = (0, hostPageKey_1.hostPageKey)(config);
52
+ const { visible, presented, overlayTranslateY, backdropOpacity } = (0, useSheetPresentation_1.useSheetPresentation)({
53
+ onDismissed: handleSheetDismissed,
54
+ });
55
+ const shouldRenderWebView = (0, chatPresentation_1.shouldRenderChatSurface)(prewarm, visible, presented);
56
+ const chatSurfaceOnScreen = (0, chatPresentation_1.isChatSurfaceOnScreen)(visible, presented);
57
+ const { ready, failed, readySignal, webViewGeneration, handleReady, handleError, handleProcessGone, retry, resetReady, } = (0, useReadyLifecycle_1.useReadyLifecycle)({ visible, configRef, pageKey });
58
+ // Another page (user switch, new token…): the previous user's total is dropped until the new
59
+ // page reports its own, which always reaches onUnreadCountChange even if equal to the old one.
60
+ const unreadPageKeyRef = (0, react_1.useRef)(pageKey);
61
+ (0, react_1.useEffect)(() => {
62
+ if (unreadPageKeyRef.current === pageKey) {
63
+ return;
64
+ }
65
+ unreadPageKeyRef.current = pageKey;
66
+ setUnreadTotal(null);
67
+ hasReportedUnreadRef.current = false;
68
+ lastReportedUnreadRef.current = null;
69
+ }, [pageKey]);
70
+ const { keyboardFrame, resetKeyboardMetrics } = (0, useKeyboardFrame_1.useKeyboardFrame)({
71
+ visible,
72
+ chatSurfaceOnScreen,
73
+ });
74
+ const { activeBanner, queueInAppBanner, handleBannerAutoHide, handleBannerPress } = (0, useInAppBannerQueue_1.useInAppBannerQueue)({
75
+ enabled: inAppBanner,
76
+ chatSurfaceOnScreen,
77
+ });
78
+ const safeAreaForWeb = (0, react_1.useMemo)(() => (0, chatPresentation_1.toSheetSafeAreaInsetsForWeb)((0, androidKeyboardFrame_1.withKeyboardSafeAreaBottom)(safeArea, keyboardFrame.isApplied)), [keyboardFrame.isApplied, safeArea]);
79
+ // Effects run in hook order: keep this before usePushIntegration so that, on ready,
80
+ // cobbai:visibility reaches the page before cobbai:push-token and cobbai:open-conversation
81
+ // (the chat page counts as hidden until its first visibility message).
82
+ (0, useNativeToWebSync_1.useNativeToWebSync)({ webViewRef, visible, ready, readySignal, safeAreaForWeb });
83
+ (0, usePushIntegration_1.usePushIntegration)({
84
+ chatId: config.chatId,
85
+ webViewRef,
86
+ ready,
87
+ readySignal,
88
+ failed,
89
+ shouldRenderWebView,
90
+ chatSurfaceOnScreen,
91
+ });
92
+ const placeholderState = (0, chatUnavailable_1.deriveChatPlaceholderState)({ visible, ready, failed });
93
+ const { loaderMounted, loaderOpacity } = (0, useSheetPresentation_1.useLoaderFade)(placeholderState !== 'hidden', visible);
94
+ const { launcherAppearance, setLauncherAppearance, showLauncher, launcherOpacity } = (0, useLauncherPresentation_1.useLauncherPresentation)({
95
+ prewarm,
96
+ launcherVisible,
97
+ visible,
98
+ presented,
99
+ });
100
+ const handleClose = (0, react_1.useCallback)(() => {
101
+ var _a, _b;
102
+ const pendingOpen = (0, push_1.getPushStoreSnapshot)().pendingOpen;
103
+ if (pendingOpen) {
104
+ (0, push_1.clearPendingOpen)(pendingOpen);
105
+ }
106
+ (0, openChatScreen_1.closeChatScreenInternal)();
107
+ (_b = (_a = configRef.current).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
108
+ }, []);
109
+ (0, react_1.useEffect)(() => {
110
+ if (react_native_1.Platform.OS !== 'android' || !visible) {
111
+ return;
112
+ }
113
+ const subscription = react_native_1.BackHandler.addEventListener('hardwareBackPress', () => {
114
+ handleClose();
115
+ return true;
116
+ });
117
+ return () => {
118
+ subscription.remove();
119
+ };
120
+ }, [handleClose, visible]);
121
+ const handleNewMessage = (event) => {
122
+ var _a;
123
+ (_a = config.onNewMessage) === null || _a === void 0 ? void 0 : _a.call(config, {
124
+ ...event,
125
+ chatVisible: visible,
126
+ });
127
+ if (!event.preview) {
128
+ return;
129
+ }
130
+ queueInAppBanner({
131
+ chatId: config.chatId,
132
+ conversationId: event.conversationId,
133
+ messageId: event.messageId,
134
+ senderName: event.senderName,
135
+ preview: event.preview,
136
+ source: 'live',
137
+ });
138
+ };
139
+ const handlePushTokenRegistered = (registration) => {
140
+ (0, pushLogout_1.rememberUnregisterSecret)({
141
+ baseUrl: configRef.current.baseUrl,
142
+ chatId: configRef.current.chatId,
143
+ token: registration.token,
144
+ provider: registration.provider,
145
+ secret: registration.unregisterSecret,
146
+ });
147
+ };
148
+ const handleUnread = (total) => {
149
+ var _a;
150
+ setUnreadTotal(total);
151
+ if (!hasReportedUnreadRef.current || lastReportedUnreadRef.current !== total) {
152
+ hasReportedUnreadRef.current = true;
153
+ lastReportedUnreadRef.current = total;
154
+ (_a = config.onUnreadCountChange) === null || _a === void 0 ? void 0 : _a.call(config, total);
155
+ }
156
+ };
157
+ const overlayStyle = (0, react_1.useMemo)(() => [
158
+ styles.overlay,
159
+ { top: safeArea.top },
160
+ keyboardFrame.isApplied ? { bottom: keyboardFrame.overlayBottomInset } : null,
161
+ ], [keyboardFrame.isApplied, keyboardFrame.overlayBottomInset, safeArea.top]);
162
+ const normalizedLauncherBottomOffset = (0, react_1.useMemo)(() => (0, launcher_1.resolveLauncherBottomOffset)(launcherBottomOffset, safeArea.bottom), [launcherBottomOffset, safeArea.bottom]);
163
+ const launcherAccessibilityLabel = (0, react_1.useMemo)(() => (0, launcher_1.getLauncherAccessibilityLabel)(config.locale), [config.locale]);
164
+ const launcherUnreadAccessibilityText = (0, react_1.useMemo)(() => (0, launcher_1.getLauncherUnreadAccessibilityText)(config.locale, unreadTotal), [config.locale, unreadTotal]);
165
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [launcherAppearance ? ((0, jsx_runtime_1.jsx)(CobbaiLauncher_1.CobbaiLauncher, { appearance: launcherAppearance, unreadTotal: unreadTotal, isVisible: showLauncher, right: safeArea.right + launcher_1.LAUNCHER_EDGE_OFFSET, bottom: normalizedLauncherBottomOffset + launcher_1.LAUNCHER_EDGE_OFFSET, opacity: launcherOpacity, accessibilityLabel: launcherAccessibilityLabel, accessibilityValue: launcherUnreadAccessibilityText
166
+ ? {
167
+ text: launcherUnreadAccessibilityText,
168
+ }
169
+ : undefined, onPress: () => {
170
+ (0, openChatScreen_1.openChatScreen)();
171
+ } })) : null, inAppBanner ? ((0, jsx_runtime_1.jsx)(CobbaiInAppBanner_1.CobbaiInAppBanner, { banner: activeBanner, locale: config.locale, safeArea: safeArea, launcherAppearance: launcherAppearance, onAutoHide: handleBannerAutoHide, onPress: handleBannerPress })) : null, shouldRenderWebView ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { style: [styles.backdrop, { opacity: backdropOpacity }], pointerEvents: visible ? 'auto' : 'none', accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", accessible: false }), (0, jsx_runtime_1.jsxs)(react_native_1.Animated.View, { style: [overlayStyle, { transform: [{ translateY: overlayTranslateY }] }], pointerEvents: visible ? 'auto' : 'none', accessibilityElementsHidden: !visible, importantForAccessibility: visible ? 'auto' : 'no-hide-descendants',
172
+ // iOS: while open, VoiceOver stays inside the chat instead of reaching the app behind it
173
+ accessibilityViewIsModal: visible, children: [(0, jsx_runtime_1.jsx)(CobbaiWebView_1.CobbaiWebView, { config: config, generation: webViewGeneration, initialSafeArea: initialSafeAreaRef.current, onReady: handleReady, onClose: handleClose, onError: handleError, onNewMessage: handleNewMessage, onUnread: handleUnread, onPushTokenRegistered: handlePushTokenRegistered, onLauncherAppearance: setLauncherAppearance, onProcessGone: handleProcessGone, onWebViewRef: (ref) => {
174
+ webViewRef.current = ref;
175
+ } }), loaderMounted ? ((0, jsx_runtime_1.jsx)(ChatPlaceholder_1.ChatPlaceholder, { mode: placeholderState === 'unavailable' ? 'unavailable' : 'loading', locale: config.locale, opacity: loaderOpacity, onClose: handleClose, onRetry: retry })) : null] })] })) : null] }));
176
+ }
177
+ const styles = react_native_1.StyleSheet.create({
178
+ backdrop: {
179
+ position: 'absolute',
180
+ top: 0,
181
+ right: 0,
182
+ bottom: 0,
183
+ left: 0,
184
+ backgroundColor: 'rgba(0, 0, 0, 0.4)',
185
+ zIndex: 2147483646,
186
+ },
187
+ overlay: {
188
+ position: 'absolute',
189
+ top: 0,
190
+ right: 0,
191
+ bottom: 0,
192
+ left: 0,
193
+ backgroundColor: 'transparent',
194
+ zIndex: 2147483647,
195
+ },
196
+ });
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { type LauncherAppearance } from './launcher';
3
+ import { type CobbaiInAppBannerPayload } from './inAppBanner';
4
+ import type { CobbaiSafeAreaInsets } from './types';
5
+ type CobbaiInAppBannerProps = {
6
+ banner: CobbaiInAppBannerPayload | null;
7
+ locale?: string;
8
+ safeArea: CobbaiSafeAreaInsets;
9
+ launcherAppearance: LauncherAppearance | null;
10
+ onPress: (banner: CobbaiInAppBannerPayload) => void;
11
+ onAutoHide: () => void;
12
+ };
13
+ export declare function CobbaiInAppBanner(props: CobbaiInAppBannerProps): React.JSX.Element | null;
14
+ export {};
15
+ //# sourceMappingURL=CobbaiInAppBanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CobbaiInAppBanner.d.ts","sourceRoot":"","sources":["../src/CobbaiInAppBanner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqC,MAAM,OAAO,CAAC;AAY1D,OAAO,EAA+B,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAQL,KAAK,wBAAwB,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,wBAAwB,GAAG,IAAI,CAAC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC9C,OAAO,EAAE,CAAC,MAAM,EAAE,wBAAwB,KAAK,IAAI,CAAC;IACpD,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAuJzF"}
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CobbaiInAppBanner = CobbaiInAppBanner;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const launcherGlyph_1 = require("./launcherGlyph");
8
+ const launcher_1 = require("./launcher");
9
+ const inAppBanner_1 = require("./inAppBanner");
10
+ function CobbaiInAppBanner(props) {
11
+ const { banner, locale, safeArea, launcherAppearance, onPress, onAutoHide } = props;
12
+ const opacity = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
13
+ const translateY = (0, react_1.useRef)(new react_native_1.Animated.Value(-16)).current;
14
+ const previousMessageKeyRef = (0, react_1.useRef)(null);
15
+ const autoHideTimerRef = (0, react_1.useRef)(null);
16
+ // The show/hide cycle is keyed on the message only. Reading the rest through refs keeps a parent
17
+ // re-render (new callback identity, locale, …) from restarting the auto-hide timer or snapping a
18
+ // fading banner back to full opacity.
19
+ const messageKey = banner
20
+ ? (0, inAppBanner_1.getInAppBannerMessageKey)(banner.conversationId, banner.messageId)
21
+ : null;
22
+ const bannerRef = (0, react_1.useRef)(banner);
23
+ const localeRef = (0, react_1.useRef)(locale);
24
+ const onAutoHideRef = (0, react_1.useRef)(onAutoHide);
25
+ bannerRef.current = banner;
26
+ localeRef.current = locale;
27
+ onAutoHideRef.current = onAutoHide;
28
+ const clearAutoHideTimer = () => {
29
+ if (!autoHideTimerRef.current) {
30
+ return;
31
+ }
32
+ clearTimeout(autoHideTimerRef.current);
33
+ autoHideTimerRef.current = null;
34
+ };
35
+ (0, react_1.useEffect)(() => {
36
+ return () => {
37
+ clearAutoHideTimer();
38
+ };
39
+ }, []);
40
+ (0, react_1.useEffect)(() => {
41
+ clearAutoHideTimer();
42
+ opacity.stopAnimation();
43
+ translateY.stopAnimation();
44
+ const currentBanner = bannerRef.current;
45
+ if (!currentBanner || messageKey == null) {
46
+ previousMessageKeyRef.current = null;
47
+ opacity.setValue(0);
48
+ translateY.setValue(-16);
49
+ return;
50
+ }
51
+ const hadBanner = previousMessageKeyRef.current != null;
52
+ previousMessageKeyRef.current = messageKey;
53
+ if (!hadBanner) {
54
+ opacity.setValue(0);
55
+ translateY.setValue(-16);
56
+ react_native_1.Animated.parallel([
57
+ react_native_1.Animated.timing(opacity, {
58
+ toValue: 1,
59
+ duration: inAppBanner_1.IN_APP_BANNER_APPEAR_DURATION_MS,
60
+ useNativeDriver: true,
61
+ }),
62
+ react_native_1.Animated.timing(translateY, {
63
+ toValue: 0,
64
+ duration: inAppBanner_1.IN_APP_BANNER_APPEAR_DURATION_MS,
65
+ useNativeDriver: true,
66
+ }),
67
+ ]).start();
68
+ if (react_native_1.Platform.OS === 'ios') {
69
+ const label = (0, inAppBanner_1.getInAppBannerAccessibilityLabel)(currentBanner, localeRef.current);
70
+ void react_native_1.AccessibilityInfo.announceForAccessibility(label);
71
+ }
72
+ }
73
+ else {
74
+ opacity.setValue(1);
75
+ translateY.setValue(0);
76
+ }
77
+ autoHideTimerRef.current = setTimeout(() => {
78
+ react_native_1.Animated.timing(opacity, {
79
+ toValue: 0,
80
+ duration: inAppBanner_1.IN_APP_BANNER_FADE_OUT_DURATION_MS,
81
+ useNativeDriver: true,
82
+ }).start(({ finished }) => {
83
+ if (!finished) {
84
+ return;
85
+ }
86
+ onAutoHideRef.current();
87
+ });
88
+ }, inAppBanner_1.IN_APP_BANNER_AUTO_HIDE_DURATION_MS);
89
+ return clearAutoHideTimer;
90
+ }, [messageKey, opacity, translateY]);
91
+ const appearance = launcherAppearance !== null && launcherAppearance !== void 0 ? launcherAppearance : launcher_1.DEFAULT_LAUNCHER_APPEARANCE;
92
+ const containerStyle = (0, react_1.useMemo)(() => [
93
+ styles.container,
94
+ {
95
+ top: safeArea.top + 8,
96
+ left: safeArea.left + 12,
97
+ right: safeArea.right + 12,
98
+ opacity,
99
+ transform: [{ translateY }],
100
+ },
101
+ ], [opacity, safeArea.left, safeArea.right, safeArea.top, translateY]);
102
+ if (!banner) {
103
+ return null;
104
+ }
105
+ const sender = (0, inAppBanner_1.resolveInAppBannerSender)(banner.senderName, locale);
106
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { style: containerStyle, pointerEvents: "box-none", children: (0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { testID: "cobbai-in-app-banner", accessibilityRole: "button", accessibilityLabel: (0, inAppBanner_1.getInAppBannerAccessibilityLabel)(banner, locale), accessibilityHint: (0, inAppBanner_1.getInAppBannerOpenHint)(locale), accessibilityLiveRegion: react_native_1.Platform.OS === 'android' ? 'polite' : undefined, onPress: () => {
107
+ onPress(banner);
108
+ }, style: styles.card, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: [styles.avatar, { backgroundColor: appearance.backgroundColor }], children: (0, jsx_runtime_1.jsx)(react_native_1.Image, { source: { uri: launcherGlyph_1.CHAT_BUTTON_GLYPH_URI }, resizeMode: "contain", accessible: false, importantForAccessibility: "no", style: [styles.glyph, { tintColor: appearance.textColor }] }) }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.textContainer, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.sender, numberOfLines: 1, children: sender }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.preview, numberOfLines: 2, children: banner.preview })] })] }) }));
109
+ }
110
+ const styles = react_native_1.StyleSheet.create({
111
+ container: {
112
+ position: 'absolute',
113
+ zIndex: 2147483644,
114
+ alignItems: 'center',
115
+ },
116
+ card: {
117
+ width: '100%',
118
+ maxWidth: 560,
119
+ borderRadius: 14,
120
+ padding: 12,
121
+ backgroundColor: '#FFFFFF',
122
+ flexDirection: 'row',
123
+ alignItems: 'center',
124
+ shadowColor: '#000000',
125
+ shadowOpacity: 0.18,
126
+ shadowRadius: 12,
127
+ shadowOffset: {
128
+ width: 0,
129
+ height: 4,
130
+ },
131
+ elevation: 8,
132
+ },
133
+ avatar: {
134
+ width: 36,
135
+ height: 36,
136
+ borderRadius: 18,
137
+ alignItems: 'center',
138
+ justifyContent: 'center',
139
+ flexShrink: 0,
140
+ },
141
+ glyph: {
142
+ width: 22,
143
+ height: 22,
144
+ },
145
+ textContainer: {
146
+ flex: 1,
147
+ marginLeft: 10,
148
+ },
149
+ sender: {
150
+ color: '#111827',
151
+ fontSize: 14,
152
+ fontWeight: '600',
153
+ },
154
+ preview: {
155
+ marginTop: 2,
156
+ color: '#374151',
157
+ fontSize: 14,
158
+ },
159
+ });
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { Animated } from 'react-native';
3
+ import { type LauncherAppearance } from './launcher';
4
+ type CobbaiLauncherProps = {
5
+ appearance: LauncherAppearance;
6
+ unreadTotal: number | null;
7
+ isVisible: boolean;
8
+ right: number;
9
+ bottom: number;
10
+ opacity: Animated.Value;
11
+ accessibilityLabel: string;
12
+ accessibilityValue?: {
13
+ text: string;
14
+ };
15
+ onPress: () => void;
16
+ };
17
+ export declare function CobbaiLauncher(props: CobbaiLauncherProps): React.JSX.Element;
18
+ export {};
19
+ //# sourceMappingURL=CobbaiLauncher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CobbaiLauncher.d.ts","sourceRoot":"","sources":["../src/CobbaiLauncher.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqC,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAA8C,MAAM,cAAc,CAAC;AACpF,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAGpB,KAAK,mBAAmB,GAAG;IACzB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAiJ5E"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CobbaiLauncher = CobbaiLauncher;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const launcher_1 = require("./launcher");
8
+ const launcherGlyph_1 = require("./launcherGlyph");
9
+ function CobbaiLauncher(props) {
10
+ const { appearance, unreadTotal, isVisible, right, bottom, opacity, accessibilityLabel, accessibilityValue, onPress, } = props;
11
+ const badgeScale = (0, react_1.useRef)(new react_native_1.Animated.Value(1)).current;
12
+ const badgeOpacity = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
13
+ const previousUnreadTotalRef = (0, react_1.useRef)(0);
14
+ const badgeWasVisibleRef = (0, react_1.useRef)(false);
15
+ const badgeText = (0, react_1.useMemo)(() => (0, launcher_1.formatUnreadBadge)(unreadTotal), [unreadTotal]);
16
+ const badgeIsVisible = badgeText.length > 0;
17
+ (0, react_1.useEffect)(() => {
18
+ const currentTotal = typeof unreadTotal === 'number' ? unreadTotal : 0;
19
+ if (!badgeIsVisible) {
20
+ badgeScale.stopAnimation();
21
+ badgeOpacity.stopAnimation();
22
+ badgeScale.setValue(1);
23
+ badgeOpacity.setValue(0);
24
+ badgeWasVisibleRef.current = false;
25
+ previousUnreadTotalRef.current = currentTotal;
26
+ return;
27
+ }
28
+ if (!badgeWasVisibleRef.current) {
29
+ badgeScale.stopAnimation();
30
+ badgeOpacity.stopAnimation();
31
+ badgeScale.setValue(0.6);
32
+ badgeOpacity.setValue(0);
33
+ react_native_1.Animated.parallel([
34
+ react_native_1.Animated.timing(badgeScale, {
35
+ toValue: 1,
36
+ duration: launcher_1.LAUNCHER_BADGE_APPEAR_DURATION_MS,
37
+ easing: react_native_1.Easing.out(react_native_1.Easing.cubic),
38
+ useNativeDriver: true,
39
+ }),
40
+ react_native_1.Animated.timing(badgeOpacity, {
41
+ toValue: 1,
42
+ duration: launcher_1.LAUNCHER_BADGE_APPEAR_DURATION_MS,
43
+ easing: react_native_1.Easing.out(react_native_1.Easing.cubic),
44
+ useNativeDriver: true,
45
+ }),
46
+ ]).start();
47
+ }
48
+ else if (currentTotal > previousUnreadTotalRef.current) {
49
+ badgeScale.stopAnimation();
50
+ badgeScale.setValue(1);
51
+ badgeOpacity.stopAnimation();
52
+ badgeOpacity.setValue(1);
53
+ const pulseHalfDuration = Math.round(launcher_1.LAUNCHER_BADGE_PULSE_DURATION_MS / 2);
54
+ react_native_1.Animated.sequence([
55
+ react_native_1.Animated.timing(badgeScale, {
56
+ toValue: 1.14,
57
+ duration: pulseHalfDuration,
58
+ easing: react_native_1.Easing.out(react_native_1.Easing.cubic),
59
+ useNativeDriver: true,
60
+ }),
61
+ react_native_1.Animated.timing(badgeScale, {
62
+ toValue: 1,
63
+ duration: launcher_1.LAUNCHER_BADGE_PULSE_DURATION_MS - pulseHalfDuration,
64
+ easing: react_native_1.Easing.in(react_native_1.Easing.cubic),
65
+ useNativeDriver: true,
66
+ }),
67
+ ]).start();
68
+ }
69
+ else {
70
+ badgeOpacity.stopAnimation();
71
+ badgeOpacity.setValue(1);
72
+ badgeScale.stopAnimation();
73
+ badgeScale.setValue(1);
74
+ }
75
+ badgeWasVisibleRef.current = true;
76
+ previousUnreadTotalRef.current = currentTotal;
77
+ }, [badgeIsVisible, badgeOpacity, badgeScale, unreadTotal]);
78
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.Animated.View, { style: [
79
+ styles.container,
80
+ {
81
+ right,
82
+ bottom,
83
+ opacity,
84
+ },
85
+ ], pointerEvents: isVisible ? 'box-none' : 'none', accessibilityElementsHidden: !isVisible, importantForAccessibility: isVisible ? 'auto' : 'no-hide-descendants', children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { testID: "cobbai-launcher", disabled: !isVisible, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityValue: accessibilityValue, accessibilityElementsHidden: !isVisible, importantForAccessibility: isVisible ? 'auto' : 'no-hide-descendants', onPress: onPress, style: ({ pressed }) => [
86
+ styles.button,
87
+ {
88
+ backgroundColor: appearance.backgroundColor,
89
+ opacity: pressed ? 0.85 : 1,
90
+ },
91
+ ], children: (0, jsx_runtime_1.jsx)(react_native_1.Image, { source: { uri: launcherGlyph_1.CHAT_BUTTON_GLYPH_URI }, resizeMode: "contain", accessible: false, importantForAccessibility: "no", style: [styles.glyph, { tintColor: appearance.textColor }] }) }), badgeIsVisible ? ((0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { testID: "cobbai-launcher-badge", pointerEvents: "none", accessible: false, importantForAccessibility: "no", style: [
92
+ styles.badge,
93
+ {
94
+ opacity: badgeOpacity,
95
+ transform: [{ scale: badgeScale }],
96
+ },
97
+ ], children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.badgeText, children: badgeText }) })) : null] }));
98
+ }
99
+ const styles = react_native_1.StyleSheet.create({
100
+ container: {
101
+ position: 'absolute',
102
+ width: launcher_1.LAUNCHER_WRAPPER_SIZE,
103
+ height: launcher_1.LAUNCHER_WRAPPER_SIZE,
104
+ overflow: 'visible',
105
+ zIndex: 2147483645,
106
+ },
107
+ button: {
108
+ width: launcher_1.LAUNCHER_WRAPPER_SIZE,
109
+ height: launcher_1.LAUNCHER_WRAPPER_SIZE,
110
+ borderTopLeftRadius: 16,
111
+ borderTopRightRadius: 16,
112
+ borderBottomRightRadius: 16,
113
+ borderBottomLeftRadius: 0,
114
+ alignItems: 'center',
115
+ justifyContent: 'center',
116
+ shadowColor: launcher_1.LAUNCHER_SHADOW_COLOR,
117
+ shadowOpacity: 0.9,
118
+ shadowRadius: 4,
119
+ shadowOffset: {
120
+ width: 0,
121
+ height: 0,
122
+ },
123
+ elevation: 6,
124
+ },
125
+ glyph: {
126
+ width: launcher_1.LAUNCHER_GLYPH_SIZE,
127
+ height: launcher_1.LAUNCHER_GLYPH_SIZE,
128
+ },
129
+ badge: {
130
+ position: 'absolute',
131
+ top: -4,
132
+ right: -4,
133
+ minWidth: 18,
134
+ height: 18,
135
+ paddingHorizontal: 4,
136
+ borderRadius: 999,
137
+ alignItems: 'center',
138
+ justifyContent: 'center',
139
+ backgroundColor: '#E25959',
140
+ },
141
+ badgeText: {
142
+ color: '#FFFFFF',
143
+ fontSize: 10,
144
+ fontWeight: '700',
145
+ includeFontPadding: false,
146
+ textAlign: 'center',
147
+ textAlignVertical: 'center',
148
+ },
149
+ });
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import WebView from 'react-native-webview';
3
+ import { type ValidatedPushTokenRegisteredPayload, type ValidatedNewMessagePayload } from './bridge/parser';
4
+ import type { LauncherAppearance } from './launcher';
5
+ import type { CobbaiChatConfig, CobbaiError, CobbaiSafeAreaInsets } from './types';
6
+ export type CobbaiWebViewRef = WebView<unknown>;
7
+ export type ProcessGoneEvent = {
8
+ platform: 'android' | 'ios';
9
+ didCrash?: boolean;
10
+ };
11
+ type CobbaiWebViewProps = {
12
+ config: CobbaiChatConfig;
13
+ generation: number;
14
+ /** Captured once for first paint; later changes travel over the bridge, not through the HTML. */
15
+ initialSafeArea?: CobbaiSafeAreaInsets;
16
+ onReady: () => void;
17
+ onClose: () => void;
18
+ onError: (error: CobbaiError) => void;
19
+ onNewMessage: (message: ValidatedNewMessagePayload) => void;
20
+ onUnread: (total: number) => void;
21
+ onPushTokenRegistered: (registration: ValidatedPushTokenRegisteredPayload) => void;
22
+ onLauncherAppearance: (appearance: LauncherAppearance) => void;
23
+ onProcessGone: (event: ProcessGoneEvent) => void;
24
+ onWebViewRef: (ref: CobbaiWebViewRef | null) => void;
25
+ };
26
+ export declare function CobbaiWebView(props: CobbaiWebViewProps): React.JSX.Element;
27
+ export {};
28
+ //# sourceMappingURL=CobbaiWebView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CobbaiWebView.d.ts","sourceRoot":"","sources":["../src/CobbaiWebView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAEvC,OAAO,OAAqC,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAGL,KAAK,mCAAmC,EAIxC,KAAK,0BAA0B,EAChC,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAInF,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,SAAS,GAAG,KAAK,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,iGAAiG;IACjG,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACtC,YAAY,EAAE,CAAC,OAAO,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAC5D,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,qBAAqB,EAAE,CAAC,YAAY,EAAE,mCAAmC,KAAK,IAAI,CAAC;IACnF,oBAAoB,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACjD,YAAY,EAAE,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,KAAK,IAAI,CAAC;CACtD,CAAC;AAaF,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAuK1E"}