droplinked-chatbot-next 1.0.7 → 1.0.9

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 CHANGED
@@ -1,25 +1,80 @@
1
1
  # Droplinked Chatbot
2
2
 
3
- A React-based chatbot component with AI capabilities.
3
+ A React-based chatbot component with AI capabilities, now supporting both SSR and browser environments with dual builds.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install droplinked-chatbot
8
+ npm install droplinked-chatbot-next
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
+ ### For SSR Frameworks (Next.js, etc.)
14
+
15
+ For SSR frameworks like Next.js, use the client export with dynamic imports:
16
+
17
+ ```jsx
18
+ 'use client'
19
+
20
+ import dynamic from 'next/dynamic'
21
+
22
+ const Chatbot = dynamic(
23
+ () => import('droplinked-chatbot-next/client'),
24
+ { ssr: false }
25
+ )
26
+
27
+ function App() {
28
+ return (
29
+ <Chatbot
30
+ apiBaseUrl="https://your-api-base-url.com"
31
+ drawerTrigger={(onClick) => (
32
+ <button onClick={onClick}>Open Chat</button>
33
+ )}
34
+ />
35
+ )
36
+ }
37
+ ```
38
+
39
+ ### For Browser-Only Applications (Vite, Create React App, etc.)
40
+
41
+ For browser-only applications, you can import directly:
42
+
13
43
  ```jsx
14
- import { Chatbot } from 'droplinked-chatbot';
44
+ import { Chatbot } from 'droplinked-chatbot-next'
15
45
 
16
46
  function App() {
17
47
  return (
18
48
  <Chatbot
19
- apiBaseUrl="https://your-api-base-url.com"
20
- buttonType="floating"
49
+ apiBaseUrl="https://your-api-base-url.com"
50
+ drawerTrigger={(onClick) => (
51
+ <button onClick={onClick}>Open Chat</button>
52
+ )}
21
53
  />
22
- );
54
+ )
55
+ }
56
+ ```
57
+
58
+ ## Dual Builds
59
+
60
+ This package now provides dual builds for maximum compatibility:
61
+
62
+ - **CommonJS**: `dist/index.cjs` - For Node.js/SSR environments
63
+ - **ES Module**: `dist/index.mjs` - For modern browser bundlers
64
+ - **Client Export**: `dist/index.client.js` - For client-side only imports
65
+
66
+ The package.json uses modern `"exports"` field for proper resolution:
67
+
68
+ ```json
69
+ {
70
+ "exports": {
71
+ ".": {
72
+ "import": "./dist/index.mjs",
73
+ "require": "./dist/index.cjs",
74
+ "types": "./dist/index.d.ts"
75
+ },
76
+ "./client": "./dist/index.client.js"
77
+ }
23
78
  }
24
79
  ```
25
80
 
@@ -90,10 +145,10 @@ This indicates a mismatch between ES modules and CommonJS modules. To fix this:
90
145
  2. Use import syntax instead of require:
91
146
  ```js
92
147
  // Good
93
- import { Chatbot } from 'droplinked-chatbot';
148
+ import { Chatbot } from 'droplinked-chatbot-next';
94
149
 
95
150
  // Avoid
96
- const { Chatbot } = require('droplinked-chatbot');
151
+ const { Chatbot } = require('droplinked-chatbot-next');
97
152
  ```
98
153
 
99
154
  3. If you must use CommonJS, rename your files to use the `.cjs` extension.
@@ -130,9 +185,8 @@ The chatbot requires an `apiBaseUrl` prop to connect to your backend services:
130
185
  |------|------|----------|-------------|
131
186
  | apiBaseUrl | string | Yes | Base URL for API endpoints |
132
187
  | apiKey | string | No | API key for authentication |
133
- | buttonType | "floating" \| "solid" | No | Chat button style (default: "floating") |
134
- | buttonText | string | No | Custom text for solid button |
135
188
  | user | object | No | Initial user information |
189
+ | drawerTrigger | function | Yes | Function that returns a React element to trigger the chat drawer |
136
190
 
137
191
  ## Development
138
192
 
@@ -147,6 +201,13 @@ npm run dev
147
201
  npm run build
148
202
  ```
149
203
 
204
+ ## Examples
205
+
206
+ See the [examples](./examples) directory for detailed usage in different frameworks:
207
+
208
+ - [Next.js Example](./examples/nextjs/README.md)
209
+ - [React + Vite Example](./examples/react-vite/README.md)
210
+
150
211
  ## Troubleshooting
151
212
 
152
213
  ### Node.js Version Warning
@@ -187,7 +248,7 @@ To test the chatbot in another project:
187
248
 
188
249
  2. In your test project:
189
250
  ```bash
190
- npm link droplinked-chatbot
251
+ npm link droplinked-chatbot-next
191
252
  ```
192
253
 
193
254
  3. Make sure your test project has all peer dependencies installed:
@@ -199,7 +260,8 @@ To test the chatbot in another project:
199
260
 
200
261
  When publishing to npm, the package is built with both CommonJS and ES module formats for maximum compatibility:
201
262
 
202
- - `dist/index.js` - CommonJS format
203
- - `dist/index.esm.js` - ES module format
263
+ - `dist/index.cjs` - CommonJS format
264
+ - `dist/index.mjs` - ES module format
265
+ - `dist/index.client.js` - Client-only format
204
266
 
205
267
  The package.json includes proper export maps to ensure the correct format is used based on the importing environment.
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ interface ChatbotProps {
3
+ apiBaseUrl?: string;
4
+ apiKey?: string;
5
+ user?: {
6
+ id?: string;
7
+ name?: string;
8
+ email?: string;
9
+ };
10
+ }
11
+ declare const Chatbot: React.FC<ChatbotProps>;
12
+ export default Chatbot;
@@ -2,8 +2,8 @@ import { ChatbotUser } from "../types";
2
2
  interface ChatbotProps {
3
3
  apiBaseUrl: string;
4
4
  apiKey?: string;
5
- buttonType?: "floating" | "solid";
6
5
  user?: Partial<ChatbotUser> | null;
6
+ drawerTrigger: (onClick: () => void) => React.ReactNode;
7
7
  }
8
- declare function Chatbot({ apiBaseUrl, apiKey, buttonType, user: initialUser, }: ChatbotProps): import("react/jsx-runtime").JSX.Element;
8
+ declare function Chatbot({ apiBaseUrl, apiKey, user: initialUser, drawerTrigger, }: ChatbotProps): import("react/jsx-runtime").JSX.Element;
9
9
  export default Chatbot;