UNPKG

react-native-langflow-chat

Version:

A native React Native component for integrating LangFlow chat with streaming support, citation bubbles, react-native-marked rendering, and customizable UI

131 lines (130 loc) 4.62 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.LoadingBubble = exports.LoadingDots = void 0; const react_1 = __importStar(require("react")); const react_native_1 = require("react-native"); // Componente per l'animazione loading dots const LoadingDots = ({ style, dotStyle, }) => { const [activeIndex, setActiveIndex] = (0, react_1.useState)(0); (0, react_1.useEffect)(() => { const interval = setInterval(() => { setActiveIndex((prev) => (prev + 1) % 3); }, 500); return () => clearInterval(interval); }, []); return (<react_native_1.View style={[styles.loadingDotsContainer, style]}> {[0, 1, 2].map((index) => (<react_native_1.Text key={index} style={[ styles.loadingDot, dotStyle, { opacity: index <= activeIndex ? 1 : 0.3, }, ]}></react_native_1.Text>))} </react_native_1.View>); }; exports.LoadingDots = LoadingDots; // Componente per la bubble di loading con three dots const LoadingBubble = ({ botMessageStyle }) => { return (<react_native_1.View style={styles.messageContainer}> <react_native_1.View style={styles.botMessageContainer}> <react_native_1.View style={[ styles.messageBubble, styles.botMessageBubble, styles.loadingBubble, botMessageStyle, // Usa lo stesso stile delle bubble bot ]}> <exports.LoadingDots style={styles.bubbleLoadingDots} dotStyle={[ styles.bubbleLoadingDot, { color: (botMessageStyle === null || botMessageStyle === void 0 ? void 0 : botMessageStyle.color) || "#666" }, // Usa il colore del testo bot ]}/> </react_native_1.View> </react_native_1.View> </react_native_1.View>); }; exports.LoadingBubble = LoadingBubble; const styles = react_native_1.StyleSheet.create({ messageContainer: { marginVertical: 4, // Ridotto da 6 a 4 }, botMessageContainer: { alignItems: "flex-start", }, messageBubble: { maxWidth: "80%", paddingHorizontal: 16, // Ridotto da 18 a 16 paddingVertical: 12, // Ridotto da 14 a 12 borderRadius: 20, // Ridotto da 24 a 20 marginVertical: 2, }, botMessageBubble: { backgroundColor: "#ffffff", borderBottomLeftRadius: 6, // Ridotto da 8 a 6 borderWidth: 1, borderColor: "rgba(0, 0, 0, 0.08)", }, loadingDotsContainer: { flexDirection: "row", justifyContent: "center", alignItems: "center", width: 20, height: 20, }, loadingDot: { fontSize: 16, color: "white", fontWeight: "bold", marginHorizontal: 1, lineHeight: 16, }, loadingBubble: { paddingHorizontal: 12, paddingVertical: 8, borderRadius: 15, // Rimuovo background e border fissi - userà quelli di botMessageBubble }, bubbleLoadingDots: { marginLeft: 4, }, bubbleLoadingDot: { fontSize: 16, color: "#666", fontWeight: "bold", marginHorizontal: 1, lineHeight: 16, }, });