@mordn/chat-widget 0.3.0 → 0.4.1

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/dist/index.d.mts CHANGED
@@ -57,6 +57,23 @@ interface ChatWidgetConfig {
57
57
  * Users can click these to quickly start a conversation
58
58
  */
59
59
  starterPrompts?: StarterPrompt[];
60
+ /**
61
+ * Called when the user dismisses the widget. The widget renders its own
62
+ * close X inside the header (correctly stacked) when this is provided —
63
+ * works in all layouts (popup, inline, page).
64
+ *
65
+ * In `popup` layout the widget also auto-closes its own panel; in
66
+ * `inline` and `page` layouts the consumer owns the close behaviour
67
+ * (e.g. setting their open state, navigating away).
68
+ */
69
+ onClose?: () => void;
70
+ /**
71
+ * Custom buttons rendered in the widget header next to the close X.
72
+ * Use this for "expand to full page", "settings", or any consumer-defined
73
+ * action that belongs in the widget's chrome — avoids absolute-positioning
74
+ * overlays from the outside that fight the widget's own z-index.
75
+ */
76
+ headerActions?: ReactNode;
60
77
  }
61
78
  interface StarterPrompt {
62
79
  /**
@@ -120,6 +137,7 @@ interface FeatureConfig {
120
137
  * - full: 100% - fills entire screen
121
138
  */
122
139
  type ChatWidgetSize = 'compact' | 'default' | 'large' | 'full';
140
+
123
141
  /**
124
142
  * Layout shape the widget renders in.
125
143
  *
@@ -193,7 +211,7 @@ interface ChatWidgetProps extends ChatWidgetConfig {
193
211
  */
194
212
  widgetId?: string;
195
213
  }
196
- declare function ChatWidget({ userId, conversationId, initialMessages, className, model, systemPrompt, temperature, theme, features, display, starterPrompts, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
214
+ declare function ChatWidget({ userId, conversationId, initialMessages, className, model, systemPrompt, temperature, theme, features, display, starterPrompts, onClose, headerActions, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
197
215
 
198
216
  interface ChatTheme {
199
217
  lightPrimary: string;
package/dist/index.d.ts CHANGED
@@ -57,6 +57,23 @@ interface ChatWidgetConfig {
57
57
  * Users can click these to quickly start a conversation
58
58
  */
59
59
  starterPrompts?: StarterPrompt[];
60
+ /**
61
+ * Called when the user dismisses the widget. The widget renders its own
62
+ * close X inside the header (correctly stacked) when this is provided —
63
+ * works in all layouts (popup, inline, page).
64
+ *
65
+ * In `popup` layout the widget also auto-closes its own panel; in
66
+ * `inline` and `page` layouts the consumer owns the close behaviour
67
+ * (e.g. setting their open state, navigating away).
68
+ */
69
+ onClose?: () => void;
70
+ /**
71
+ * Custom buttons rendered in the widget header next to the close X.
72
+ * Use this for "expand to full page", "settings", or any consumer-defined
73
+ * action that belongs in the widget's chrome — avoids absolute-positioning
74
+ * overlays from the outside that fight the widget's own z-index.
75
+ */
76
+ headerActions?: ReactNode;
60
77
  }
61
78
  interface StarterPrompt {
62
79
  /**
@@ -120,6 +137,7 @@ interface FeatureConfig {
120
137
  * - full: 100% - fills entire screen
121
138
  */
122
139
  type ChatWidgetSize = 'compact' | 'default' | 'large' | 'full';
140
+
123
141
  /**
124
142
  * Layout shape the widget renders in.
125
143
  *
@@ -193,7 +211,7 @@ interface ChatWidgetProps extends ChatWidgetConfig {
193
211
  */
194
212
  widgetId?: string;
195
213
  }
196
- declare function ChatWidget({ userId, conversationId, initialMessages, className, model, systemPrompt, temperature, theme, features, display, starterPrompts, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
214
+ declare function ChatWidget({ userId, conversationId, initialMessages, className, model, systemPrompt, temperature, theme, features, display, starterPrompts, onClose, headerActions, }: ChatWidgetProps): react_jsx_runtime.JSX.Element;
197
215
 
198
216
  interface ChatTheme {
199
217
  lightPrimary: string;
package/dist/index.js CHANGED
@@ -1431,7 +1431,7 @@ function useChatStorageKey() {
1431
1431
 
1432
1432
  // src/components/interface.tsx
1433
1433
  var import_jsx_runtime20 = require("react/jsx-runtime");
1434
- function ChatInterface({ id, initialMessages, config, onClose } = {}) {
1434
+ function ChatInterface({ id, initialMessages, config, onClose, headerActions } = {}) {
1435
1435
  const { storageKeyPrefix } = useChatStorageKey();
1436
1436
  const storageKey = (key) => storageKeyPrefix ? `chat-${storageKeyPrefix}-${key}` : `chat-${key}`;
1437
1437
  const themeMode = config?.theme?.mode || "light";
@@ -2102,6 +2102,7 @@ function ChatInterface({ id, initialMessages, config, onClose } = {}) {
2102
2102
  ] }, groupName)) }) })
2103
2103
  ] })
2104
2104
  ] }),
2105
+ headerActions,
2105
2106
  onClose && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2106
2107
  "button",
2107
2108
  {
@@ -2133,7 +2134,7 @@ function ChatInterface({ id, initialMessages, config, onClose } = {}) {
2133
2134
  ] }),
2134
2135
  /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "px-5 pb-5", children: [
2135
2136
  uploadError && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "mb-3 px-4 py-3 bg-red-50 dark:bg-red-900/20 border border-red-200/60 dark:border-red-800/60 rounded-2xl text-sm text-red-700 dark:text-red-400 shadow-sm", children: uploadError }),
2136
- messages.length === 0 && status !== "submitted" && config?.starterPrompts && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2137
+ isInitializing ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "flex items-center justify-center py-8", role: "status", "aria-label": "Loading conversation", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "h-4 w-4 rounded-full border-2 border-current border-t-transparent animate-spin", style: { color: "hsl(var(--chat-text-muted))" } }) }) : messages.length === 0 && status !== "submitted" && config?.starterPrompts && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2137
2138
  StarterMessages,
2138
2139
  {
2139
2140
  prompts: config.starterPrompts,
@@ -2215,7 +2216,9 @@ function ChatWidget({
2215
2216
  theme,
2216
2217
  features,
2217
2218
  display,
2218
- starterPrompts
2219
+ starterPrompts,
2220
+ onClose,
2221
+ headerActions
2219
2222
  }) {
2220
2223
  const layout = display?.layout || "popup";
2221
2224
  const showToggleButton = display?.showToggleButton !== false;
@@ -2297,7 +2300,9 @@ function ChatWidget({
2297
2300
  {
2298
2301
  id: conversationId,
2299
2302
  initialMessages,
2300
- config
2303
+ config,
2304
+ onClose,
2305
+ headerActions
2301
2306
  }
2302
2307
  )
2303
2308
  }
@@ -2315,7 +2320,9 @@ function ChatWidget({
2315
2320
  {
2316
2321
  id: conversationId,
2317
2322
  initialMessages,
2318
- config
2323
+ config,
2324
+ onClose,
2325
+ headerActions
2319
2326
  }
2320
2327
  )
2321
2328
  }
@@ -2355,7 +2362,11 @@ function ChatWidget({
2355
2362
  id: conversationId,
2356
2363
  initialMessages,
2357
2364
  config,
2358
- onClose: () => setIsOpen(false)
2365
+ onClose: () => {
2366
+ setIsOpen(false);
2367
+ onClose?.();
2368
+ },
2369
+ headerActions
2359
2370
  }
2360
2371
  ) })
2361
2372
  ]