@sagepilot-ai/react-native-sdk 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -6
- package/android/build.gradle +53 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotInsetsChangeEvent.java +26 -0
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotInsetsView.java +78 -0
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotInsetsViewManager.java +59 -0
- package/android/src/main/java/ai/sagepilot/reactnativesdk/SagepilotReactNativeSdkPackage.java +20 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SagepilotInsetsViewManagerDelegate.java +25 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SagepilotInsetsViewManagerInterface.java +10 -0
- package/dist/{index.d.cts → index.d.mts} +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +247 -87
- package/dist/{index.cjs → index.mjs} +215 -110
- package/package.json +18 -8
- package/react-native.config.js +5 -1
- package/src/specs/SagepilotInsetsViewNativeComponent.ts +17 -0
- package/android/.gitkeep +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
SagepilotChat: () => SagepilotChat,
|
|
34
|
+
SagepilotChatError: () => SagepilotChatError,
|
|
35
|
+
SagepilotChatProvider: () => SagepilotChatProvider,
|
|
36
|
+
createAsyncStorageCacheStorage: () => createAsyncStorageCacheStorage,
|
|
37
|
+
createKeychainTokenStorage: () => createKeychainTokenStorage,
|
|
38
|
+
useSagepilotChat: () => useSagepilotChat
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
|
|
1
42
|
// src/core/errors/SagepilotChatError.ts
|
|
2
43
|
var SagepilotChatError = class extends Error {
|
|
3
44
|
constructor(code, message, options = {}) {
|
|
@@ -15,7 +56,7 @@ var SagepilotChatError = class extends Error {
|
|
|
15
56
|
|
|
16
57
|
// src/core/config/constants.ts
|
|
17
58
|
var SDK_NAME = "@sagepilot-ai/react-native-sdk";
|
|
18
|
-
var SDK_VERSION = "0.2.
|
|
59
|
+
var SDK_VERSION = "0.2.3";
|
|
19
60
|
var DEFAULT_HOST = "https://app.sagepilot.ai";
|
|
20
61
|
var DEFAULT_WIDGET_HOST = "https://app.sagepilot.ai";
|
|
21
62
|
var CUSTOMER_API_PREFIX = "/customer-api/v1";
|
|
@@ -701,9 +742,9 @@ var SagepilotReactNativeChat = class {
|
|
|
701
742
|
this.hostedChatView = { screen: "messages" };
|
|
702
743
|
return this.showHostedChat();
|
|
703
744
|
}
|
|
704
|
-
presentMessageComposer(message) {
|
|
745
|
+
presentMessageComposer(message, options) {
|
|
705
746
|
this.requireConfigured();
|
|
706
|
-
this.hostedChatView = { screen: "composer", message };
|
|
747
|
+
this.hostedChatView = { screen: "composer", message, mode: options?.mode ?? "auto" };
|
|
707
748
|
return this.showHostedChat();
|
|
708
749
|
}
|
|
709
750
|
dismiss() {
|
|
@@ -799,8 +840,13 @@ var SagepilotReactNativeChat = class {
|
|
|
799
840
|
}
|
|
800
841
|
url.searchParams.set("session_id", session.session_id);
|
|
801
842
|
url.searchParams.set("wid", this.workspaceId);
|
|
843
|
+
if (this.legacyWidgetJwt) {
|
|
844
|
+
url.searchParams.set("jwt", this.legacyWidgetJwt);
|
|
845
|
+
}
|
|
802
846
|
if (this.hostedChatView.screen === "composer") {
|
|
803
|
-
|
|
847
|
+
if (this.hostedChatView.mode === "new") {
|
|
848
|
+
url.searchParams.set("new", "true");
|
|
849
|
+
}
|
|
804
850
|
if (this.hostedChatView.message) {
|
|
805
851
|
url.searchParams.set("topic", this.hostedChatView.message);
|
|
806
852
|
}
|
|
@@ -826,6 +872,16 @@ var SagepilotReactNativeChat = class {
|
|
|
826
872
|
"})();"
|
|
827
873
|
].join("\n");
|
|
828
874
|
}
|
|
875
|
+
getHostedIdentityMessage() {
|
|
876
|
+
if (!this.legacyWidgetJwt) return null;
|
|
877
|
+
return {
|
|
878
|
+
type: "identity_update",
|
|
879
|
+
data: {
|
|
880
|
+
jwt: this.legacyWidgetJwt,
|
|
881
|
+
chat_id: this.session?.conversation_id ?? void 0
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
}
|
|
829
885
|
handleHostedBridgeMessage(message) {
|
|
830
886
|
if (!message) return false;
|
|
831
887
|
if (message.type === "close_widget") {
|
|
@@ -1020,7 +1076,9 @@ var SagepilotChat = {
|
|
|
1020
1076
|
stopUnreadPolling: () => internalSagepilotChat.stopUnreadPolling(),
|
|
1021
1077
|
present: () => internalSagepilotChat.present(),
|
|
1022
1078
|
presentMessages: () => internalSagepilotChat.presentMessages(),
|
|
1023
|
-
presentMessageComposer: (message) =>
|
|
1079
|
+
presentMessageComposer: (message, options) => {
|
|
1080
|
+
return internalSagepilotChat.presentMessageComposer(message, options);
|
|
1081
|
+
},
|
|
1024
1082
|
dismiss: () => internalSagepilotChat.dismiss(),
|
|
1025
1083
|
hide: () => internalSagepilotChat.hide(),
|
|
1026
1084
|
toggle: () => internalSagepilotChat.toggle(),
|
|
@@ -1046,18 +1104,9 @@ function createAsyncStorageCacheStorage(asyncStorage) {
|
|
|
1046
1104
|
}
|
|
1047
1105
|
|
|
1048
1106
|
// src/ui/SagepilotChatProvider.ts
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
Modal,
|
|
1053
|
-
Platform,
|
|
1054
|
-
Pressable,
|
|
1055
|
-
SafeAreaView,
|
|
1056
|
-
StyleSheet,
|
|
1057
|
-
Text,
|
|
1058
|
-
View
|
|
1059
|
-
} from "react-native";
|
|
1060
|
-
import { WebView } from "react-native-webview";
|
|
1107
|
+
var import_react = require("react");
|
|
1108
|
+
var import_react_native = require("react-native");
|
|
1109
|
+
var import_react_native_webview = require("react-native-webview");
|
|
1061
1110
|
|
|
1062
1111
|
// src/core/webview/mobileBridge.ts
|
|
1063
1112
|
function isHostedBridgeMessage(value) {
|
|
@@ -1138,6 +1187,28 @@ var mobileWebViewBridgeScript = `
|
|
|
1138
1187
|
} catch (error) {}
|
|
1139
1188
|
}, true);
|
|
1140
1189
|
|
|
1190
|
+
document.addEventListener("focusin", function (event) {
|
|
1191
|
+
try {
|
|
1192
|
+
var target = event.target && event.target.closest
|
|
1193
|
+
? event.target
|
|
1194
|
+
: event.target && event.target.parentElement;
|
|
1195
|
+
if (target && target.closest && target.closest("input, textarea, [contenteditable='true']")) {
|
|
1196
|
+
sendToReactNative({ type: "sagepilot:keyboard_focus" });
|
|
1197
|
+
}
|
|
1198
|
+
} catch (error) {}
|
|
1199
|
+
}, true);
|
|
1200
|
+
|
|
1201
|
+
document.addEventListener("focusout", function (event) {
|
|
1202
|
+
try {
|
|
1203
|
+
var target = event.target && event.target.closest
|
|
1204
|
+
? event.target
|
|
1205
|
+
: event.target && event.target.parentElement;
|
|
1206
|
+
if (target && target.closest && target.closest("input, textarea, [contenteditable='true']")) {
|
|
1207
|
+
sendToReactNative({ type: "sagepilot:keyboard_blur" });
|
|
1208
|
+
}
|
|
1209
|
+
} catch (error) {}
|
|
1210
|
+
}, true);
|
|
1211
|
+
|
|
1141
1212
|
ensureViewport();
|
|
1142
1213
|
injectMobileStyles();
|
|
1143
1214
|
sendToReactNative({ type: "sagepilot:ready" });
|
|
@@ -1145,6 +1216,10 @@ var mobileWebViewBridgeScript = `
|
|
|
1145
1216
|
})();
|
|
1146
1217
|
`;
|
|
1147
1218
|
|
|
1219
|
+
// src/specs/SagepilotInsetsViewNativeComponent.ts
|
|
1220
|
+
var import_codegenNativeComponent = __toESM(require("react-native/Libraries/Utilities/codegenNativeComponent"));
|
|
1221
|
+
var SagepilotInsetsViewNativeComponent_default = (0, import_codegenNativeComponent.default)("SagepilotInsetsView");
|
|
1222
|
+
|
|
1148
1223
|
// src/ui/SagepilotChatProvider.ts
|
|
1149
1224
|
function readPresentationState() {
|
|
1150
1225
|
return {
|
|
@@ -1162,6 +1237,20 @@ function getInjectedWebViewScript() {
|
|
|
1162
1237
|
mobileWebViewBridgeScript
|
|
1163
1238
|
].filter(Boolean).join("\n");
|
|
1164
1239
|
}
|
|
1240
|
+
function getHostedIdentityDispatchScript() {
|
|
1241
|
+
const message = internalSagepilotChat.getHostedIdentityMessage();
|
|
1242
|
+
if (!message) return "";
|
|
1243
|
+
return [
|
|
1244
|
+
internalSagepilotChat.getHostedAuthScript(),
|
|
1245
|
+
"(function(){",
|
|
1246
|
+
"try {",
|
|
1247
|
+
`var message = ${JSON.stringify(message)};`,
|
|
1248
|
+
"window.dispatchEvent(new MessageEvent('message', { data: message, origin: window.location.origin, source: window.parent || window }));",
|
|
1249
|
+
"} catch (_) {}",
|
|
1250
|
+
"true;",
|
|
1251
|
+
"})();"
|
|
1252
|
+
].filter(Boolean).join("\n");
|
|
1253
|
+
}
|
|
1165
1254
|
function readUrlOrigin(url) {
|
|
1166
1255
|
if (!url) return null;
|
|
1167
1256
|
try {
|
|
@@ -1173,33 +1262,78 @@ function readUrlOrigin(url) {
|
|
|
1173
1262
|
var hostedChatWebViewProps = {
|
|
1174
1263
|
allowFileAccess: true,
|
|
1175
1264
|
allowFileAccessFromFileURLs: true,
|
|
1265
|
+
bounces: false,
|
|
1176
1266
|
domStorageEnabled: true,
|
|
1177
1267
|
javaScriptEnabled: true,
|
|
1268
|
+
overScrollMode: "never",
|
|
1269
|
+
scrollEnabled: import_react_native.Platform.OS !== "android",
|
|
1178
1270
|
setSupportMultipleWindows: false,
|
|
1179
1271
|
sharedCookiesEnabled: true,
|
|
1180
1272
|
thirdPartyCookiesEnabled: true
|
|
1181
1273
|
};
|
|
1274
|
+
var AndroidInsetsView = import_react_native.Platform.OS === "android" ? SagepilotInsetsViewNativeComponent_default : import_react_native.View;
|
|
1275
|
+
var emptyAndroidInsets = { top: 0, bottom: 0 };
|
|
1182
1276
|
function SagepilotChatProvider({
|
|
1183
1277
|
children,
|
|
1184
1278
|
closeLabel = "Close",
|
|
1185
1279
|
loadingLabel = "Loading chat"
|
|
1186
1280
|
}) {
|
|
1187
|
-
const [state, setState] = useState(readPresentationState);
|
|
1188
|
-
|
|
1281
|
+
const [state, setState] = (0, import_react.useState)(readPresentationState);
|
|
1282
|
+
const [androidModalInsets, setAndroidModalInsets] = (0, import_react.useState)(emptyAndroidInsets);
|
|
1283
|
+
const webFrameRef = (0, import_react.useRef)(null);
|
|
1284
|
+
const nativeWebViewRef = (0, import_react.useRef)(null);
|
|
1285
|
+
(0, import_react.useEffect)(() => {
|
|
1189
1286
|
return internalSagepilotChat.onStateChange(() => {
|
|
1190
1287
|
setState(readPresentationState());
|
|
1191
1288
|
});
|
|
1192
1289
|
}, []);
|
|
1290
|
+
const handleAndroidInsetsChange = (0, import_react.useCallback)((event) => {
|
|
1291
|
+
const nextBottomInset = event.nativeEvent?.bottom;
|
|
1292
|
+
const nextTopInset = event.nativeEvent?.top;
|
|
1293
|
+
if (typeof nextBottomInset !== "number" || typeof nextTopInset !== "number" || !Number.isFinite(nextBottomInset) || !Number.isFinite(nextTopInset)) return;
|
|
1294
|
+
setAndroidModalInsets({
|
|
1295
|
+
top: Math.max(0, nextTopInset),
|
|
1296
|
+
bottom: Math.max(0, nextBottomInset)
|
|
1297
|
+
});
|
|
1298
|
+
}, []);
|
|
1193
1299
|
const showCloseButton = state.presentation?.showCloseButton ?? false;
|
|
1194
1300
|
const presentationStyle = state.presentation?.style ?? "sheet";
|
|
1195
1301
|
const isFullScreenModal = presentationStyle === "fullScreen";
|
|
1196
1302
|
const animationType = presentationStyle === "fullScreen" || presentationStyle === "push" ? "slide" : "fade";
|
|
1197
|
-
const ModalContainer = Platform.OS === "ios" && isFullScreenModal ? SafeAreaView : View;
|
|
1303
|
+
const ModalContainer = import_react_native.Platform.OS === "ios" && isFullScreenModal ? import_react_native.SafeAreaView : import_react_native.View;
|
|
1304
|
+
const NativeModalContainer = import_react_native.Platform.OS === "android" ? AndroidInsetsView : ModalContainer;
|
|
1305
|
+
const ChatContentContainer = import_react_native.Platform.OS === "ios" ? import_react_native.KeyboardAvoidingView : import_react_native.View;
|
|
1306
|
+
const nativeModalContainerProps = import_react_native.Platform.OS === "android" ? { style: styles.container, onInsetsChange: handleAndroidInsetsChange } : { style: styles.container };
|
|
1307
|
+
const chatContentContainerProps = import_react_native.Platform.OS === "ios" ? {
|
|
1308
|
+
behavior: "padding",
|
|
1309
|
+
enabled: true,
|
|
1310
|
+
keyboardVerticalOffset: 0,
|
|
1311
|
+
style: styles.modalContent
|
|
1312
|
+
} : {
|
|
1313
|
+
style: [
|
|
1314
|
+
styles.modalContent,
|
|
1315
|
+
import_react_native.Platform.OS === "android" ? {
|
|
1316
|
+
paddingTop: androidModalInsets.top,
|
|
1317
|
+
paddingBottom: androidModalInsets.bottom
|
|
1318
|
+
} : null
|
|
1319
|
+
].filter(Boolean)
|
|
1320
|
+
};
|
|
1198
1321
|
const handleWebViewMessage = (event) => {
|
|
1199
1322
|
internalSagepilotChat.handleHostedBridgeMessage(parseHostedBridgeMessage(event.nativeEvent?.data));
|
|
1200
1323
|
};
|
|
1201
|
-
|
|
1202
|
-
|
|
1324
|
+
const postIdentityToWebFrame = () => {
|
|
1325
|
+
const message = internalSagepilotChat.getHostedIdentityMessage();
|
|
1326
|
+
const targetOrigin = readUrlOrigin(state.conversationUrl);
|
|
1327
|
+
if (!message || !targetOrigin) return;
|
|
1328
|
+
webFrameRef.current?.contentWindow?.postMessage(message, targetOrigin);
|
|
1329
|
+
};
|
|
1330
|
+
const postIdentityToNativeWebView = () => {
|
|
1331
|
+
const script = getHostedIdentityDispatchScript();
|
|
1332
|
+
if (!script || !nativeWebViewRef.current) return;
|
|
1333
|
+
nativeWebViewRef.current.injectJavaScript(script);
|
|
1334
|
+
};
|
|
1335
|
+
(0, import_react.useEffect)(() => {
|
|
1336
|
+
if (import_react_native.Platform.OS !== "web" || typeof window === "undefined") return;
|
|
1203
1337
|
const trustedWidgetOrigin = readUrlOrigin(state.conversationUrl);
|
|
1204
1338
|
if (!trustedWidgetOrigin) return;
|
|
1205
1339
|
const handleWindowMessage = (event) => {
|
|
@@ -1209,96 +1343,114 @@ function SagepilotChatProvider({
|
|
|
1209
1343
|
window.addEventListener("message", handleWindowMessage);
|
|
1210
1344
|
return () => window.removeEventListener("message", handleWindowMessage);
|
|
1211
1345
|
}, [state.conversationUrl]);
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1346
|
+
(0, import_react.useEffect)(() => {
|
|
1347
|
+
if (import_react_native.Platform.OS !== "web" || !state.isPresented) return;
|
|
1348
|
+
postIdentityToWebFrame();
|
|
1349
|
+
}, [state.isPresented, state.conversationUrl, state.configured]);
|
|
1350
|
+
(0, import_react.useEffect)(() => {
|
|
1351
|
+
if (import_react_native.Platform.OS === "web" || !state.isPresented) return;
|
|
1352
|
+
postIdentityToNativeWebView();
|
|
1353
|
+
}, [state.isPresented, state.conversationUrl, state.configured]);
|
|
1354
|
+
if (import_react_native.Platform.OS === "web") {
|
|
1355
|
+
return (0, import_react.createElement)(
|
|
1356
|
+
import_react_native.View,
|
|
1215
1357
|
{ style: styles.root },
|
|
1216
1358
|
children,
|
|
1217
|
-
state.configured && !state.isPresented && state.shouldPreload && state.preloadUrl ? createElement("iframe", {
|
|
1359
|
+
state.configured && !state.isPresented && state.shouldPreload && state.preloadUrl ? (0, import_react.createElement)("iframe", {
|
|
1218
1360
|
src: state.preloadUrl,
|
|
1219
1361
|
style: styles.webPreloadFrame,
|
|
1220
1362
|
title: "Sagepilot chat preload"
|
|
1221
1363
|
}) : null,
|
|
1222
|
-
state.configured && state.isPresented && state.conversationUrl ? createElement(
|
|
1223
|
-
View,
|
|
1364
|
+
state.configured && state.isPresented && state.conversationUrl ? (0, import_react.createElement)(
|
|
1365
|
+
import_react_native.View,
|
|
1224
1366
|
{ style: styles.webOverlay },
|
|
1225
|
-
createElement(
|
|
1226
|
-
View,
|
|
1367
|
+
(0, import_react.createElement)(
|
|
1368
|
+
import_react_native.View,
|
|
1227
1369
|
{ style: styles.webPanel },
|
|
1228
|
-
showCloseButton ? createElement(
|
|
1229
|
-
Pressable,
|
|
1370
|
+
showCloseButton ? (0, import_react.createElement)(
|
|
1371
|
+
import_react_native.Pressable,
|
|
1230
1372
|
{
|
|
1231
1373
|
accessibilityRole: "button",
|
|
1232
1374
|
accessibilityLabel: closeLabel,
|
|
1233
1375
|
onPress: () => internalSagepilotChat.dismiss(),
|
|
1234
1376
|
style: styles.webCloseButton
|
|
1235
1377
|
},
|
|
1236
|
-
createElement(Text, { style: styles.closeText }, closeLabel)
|
|
1378
|
+
(0, import_react.createElement)(import_react_native.Text, { style: styles.closeText }, closeLabel)
|
|
1237
1379
|
) : null,
|
|
1238
|
-
createElement("iframe", {
|
|
1380
|
+
(0, import_react.createElement)("iframe", {
|
|
1381
|
+
ref: webFrameRef,
|
|
1239
1382
|
src: state.conversationUrl,
|
|
1240
1383
|
style: styles.webFrame,
|
|
1241
|
-
title: "Sagepilot chat"
|
|
1384
|
+
title: "Sagepilot chat",
|
|
1385
|
+
onLoad: postIdentityToWebFrame
|
|
1242
1386
|
})
|
|
1243
1387
|
)
|
|
1244
1388
|
) : null
|
|
1245
1389
|
);
|
|
1246
1390
|
}
|
|
1247
|
-
return createElement(
|
|
1248
|
-
View,
|
|
1391
|
+
return (0, import_react.createElement)(
|
|
1392
|
+
import_react_native.View,
|
|
1249
1393
|
{ style: styles.root },
|
|
1250
1394
|
children,
|
|
1251
|
-
state.configured && !state.isPresented && state.shouldPreload && state.preloadUrl ? createElement(WebView, {
|
|
1395
|
+
state.configured && !state.isPresented && state.shouldPreload && state.preloadUrl ? (0, import_react.createElement)(import_react_native_webview.WebView, {
|
|
1252
1396
|
...hostedChatWebViewProps,
|
|
1253
1397
|
source: { uri: state.preloadUrl },
|
|
1254
1398
|
style: styles.preloadWebview,
|
|
1255
1399
|
injectedJavaScriptBeforeContentLoaded: getInjectedWebViewScript(),
|
|
1256
1400
|
onMessage: handleWebViewMessage
|
|
1257
1401
|
}) : null,
|
|
1258
|
-
createElement(
|
|
1259
|
-
Modal,
|
|
1402
|
+
(0, import_react.createElement)(
|
|
1403
|
+
import_react_native.Modal,
|
|
1260
1404
|
{
|
|
1261
1405
|
visible: state.configured && state.isPresented,
|
|
1262
1406
|
animationType,
|
|
1263
1407
|
presentationStyle: isFullScreenModal ? "fullScreen" : "pageSheet",
|
|
1408
|
+
statusBarTranslucent: import_react_native.Platform.OS === "android",
|
|
1409
|
+
navigationBarTranslucent: import_react_native.Platform.OS === "android",
|
|
1264
1410
|
onRequestClose: () => internalSagepilotChat.dismiss()
|
|
1265
1411
|
},
|
|
1266
|
-
createElement(
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
createElement(
|
|
1273
|
-
|
|
1274
|
-
{
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1412
|
+
(0, import_react.createElement)(
|
|
1413
|
+
NativeModalContainer,
|
|
1414
|
+
nativeModalContainerProps,
|
|
1415
|
+
(0, import_react.createElement)(
|
|
1416
|
+
ChatContentContainer,
|
|
1417
|
+
chatContentContainerProps,
|
|
1418
|
+
showCloseButton ? (0, import_react.createElement)(
|
|
1419
|
+
import_react_native.View,
|
|
1420
|
+
{ style: styles.header },
|
|
1421
|
+
(0, import_react.createElement)(
|
|
1422
|
+
import_react_native.Pressable,
|
|
1423
|
+
{
|
|
1424
|
+
accessibilityRole: "button",
|
|
1425
|
+
accessibilityLabel: closeLabel,
|
|
1426
|
+
onPress: () => internalSagepilotChat.dismiss(),
|
|
1427
|
+
style: styles.closeButton
|
|
1428
|
+
},
|
|
1429
|
+
(0, import_react.createElement)(import_react_native.Text, { style: styles.closeText }, closeLabel)
|
|
1430
|
+
)
|
|
1431
|
+
) : null,
|
|
1432
|
+
state.conversationUrl ? (0, import_react.createElement)(import_react_native_webview.WebView, {
|
|
1433
|
+
...hostedChatWebViewProps,
|
|
1434
|
+
ref: nativeWebViewRef,
|
|
1435
|
+
source: { uri: state.conversationUrl },
|
|
1436
|
+
style: styles.webview,
|
|
1437
|
+
startInLoadingState: true,
|
|
1438
|
+
injectedJavaScriptBeforeContentLoaded: getInjectedWebViewScript(),
|
|
1439
|
+
onMessage: handleWebViewMessage,
|
|
1440
|
+
onLoadEnd: postIdentityToNativeWebView,
|
|
1441
|
+
renderLoading: () => (0, import_react.createElement)(
|
|
1442
|
+
import_react_native.View,
|
|
1443
|
+
{ style: styles.loading },
|
|
1444
|
+
(0, import_react.createElement)(import_react_native.ActivityIndicator, null),
|
|
1445
|
+
(0, import_react.createElement)(import_react_native.Text, { style: styles.loadingText }, loadingLabel)
|
|
1446
|
+
)
|
|
1447
|
+
}) : null
|
|
1448
|
+
)
|
|
1297
1449
|
)
|
|
1298
1450
|
)
|
|
1299
1451
|
);
|
|
1300
1452
|
}
|
|
1301
|
-
var styles = StyleSheet.create({
|
|
1453
|
+
var styles = import_react_native.StyleSheet.create({
|
|
1302
1454
|
root: {
|
|
1303
1455
|
flex: 1
|
|
1304
1456
|
},
|
|
@@ -1306,6 +1458,11 @@ var styles = StyleSheet.create({
|
|
|
1306
1458
|
flex: 1,
|
|
1307
1459
|
backgroundColor: "#ffffff"
|
|
1308
1460
|
},
|
|
1461
|
+
modalContent: {
|
|
1462
|
+
flex: 1,
|
|
1463
|
+
width: "100%",
|
|
1464
|
+
backgroundColor: "#ffffff"
|
|
1465
|
+
},
|
|
1309
1466
|
header: {
|
|
1310
1467
|
minHeight: 48,
|
|
1311
1468
|
alignItems: "flex-end",
|
|
@@ -1379,7 +1536,7 @@ var styles = StyleSheet.create({
|
|
|
1379
1536
|
borderStyle: "none"
|
|
1380
1537
|
},
|
|
1381
1538
|
loading: {
|
|
1382
|
-
...StyleSheet.absoluteFillObject,
|
|
1539
|
+
...import_react_native.StyleSheet.absoluteFillObject,
|
|
1383
1540
|
alignItems: "center",
|
|
1384
1541
|
justifyContent: "center",
|
|
1385
1542
|
backgroundColor: "#ffffff"
|
|
@@ -1392,7 +1549,7 @@ var styles = StyleSheet.create({
|
|
|
1392
1549
|
});
|
|
1393
1550
|
|
|
1394
1551
|
// src/hooks/useSagepilotChat.ts
|
|
1395
|
-
|
|
1552
|
+
var import_react2 = require("react");
|
|
1396
1553
|
function readState() {
|
|
1397
1554
|
const state = SagepilotChat.getState();
|
|
1398
1555
|
return {
|
|
@@ -1404,23 +1561,25 @@ function readState() {
|
|
|
1404
1561
|
};
|
|
1405
1562
|
}
|
|
1406
1563
|
function useSagepilotChat() {
|
|
1407
|
-
const [state, setState] =
|
|
1408
|
-
|
|
1564
|
+
const [state, setState] = (0, import_react2.useState)(readState);
|
|
1565
|
+
(0, import_react2.useEffect)(() => {
|
|
1409
1566
|
return SagepilotChat.onStateChange(() => {
|
|
1410
1567
|
setState(readState());
|
|
1411
1568
|
});
|
|
1412
1569
|
}, []);
|
|
1413
|
-
const present = useCallback(() => SagepilotChat.present(), []);
|
|
1414
|
-
const presentMessages = useCallback(() => SagepilotChat.presentMessages(), []);
|
|
1415
|
-
const presentMessageComposer = useCallback((message) =>
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
const
|
|
1419
|
-
const
|
|
1570
|
+
const present = (0, import_react2.useCallback)(() => SagepilotChat.present(), []);
|
|
1571
|
+
const presentMessages = (0, import_react2.useCallback)(() => SagepilotChat.presentMessages(), []);
|
|
1572
|
+
const presentMessageComposer = (0, import_react2.useCallback)((message, options) => {
|
|
1573
|
+
return SagepilotChat.presentMessageComposer(message, options);
|
|
1574
|
+
}, []);
|
|
1575
|
+
const dismiss = (0, import_react2.useCallback)(() => SagepilotChat.dismiss(), []);
|
|
1576
|
+
const hide = (0, import_react2.useCallback)(() => SagepilotChat.hide(), []);
|
|
1577
|
+
const toggle = (0, import_react2.useCallback)(() => SagepilotChat.toggle(), []);
|
|
1578
|
+
const identify = (0, import_react2.useCallback)((identity) => {
|
|
1420
1579
|
return SagepilotChat.identify(identity);
|
|
1421
1580
|
}, []);
|
|
1422
|
-
const logout = useCallback(() => SagepilotChat.logout(), []);
|
|
1423
|
-
const getUnreadCount = useCallback(() => SagepilotChat.getUnreadCount(), []);
|
|
1581
|
+
const logout = (0, import_react2.useCallback)(() => SagepilotChat.logout(), []);
|
|
1582
|
+
const getUnreadCount = (0, import_react2.useCallback)(() => SagepilotChat.getUnreadCount(), []);
|
|
1424
1583
|
return {
|
|
1425
1584
|
...state,
|
|
1426
1585
|
present,
|
|
@@ -1434,11 +1593,12 @@ function useSagepilotChat() {
|
|
|
1434
1593
|
getUnreadCount
|
|
1435
1594
|
};
|
|
1436
1595
|
}
|
|
1437
|
-
export
|
|
1596
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1597
|
+
0 && (module.exports = {
|
|
1438
1598
|
SagepilotChat,
|
|
1439
1599
|
SagepilotChatError,
|
|
1440
1600
|
SagepilotChatProvider,
|
|
1441
1601
|
createAsyncStorageCacheStorage,
|
|
1442
1602
|
createKeychainTokenStorage,
|
|
1443
1603
|
useSagepilotChat
|
|
1444
|
-
};
|
|
1604
|
+
});
|