@mordn/chat-widget 0.2.1 → 0.4.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.
package/dist/index.mjs CHANGED
@@ -1411,7 +1411,7 @@ function useChatStorageKey() {
1411
1411
 
1412
1412
  // src/components/interface.tsx
1413
1413
  import { jsx as jsx20, jsxs as jsxs12 } from "react/jsx-runtime";
1414
- function ChatInterface({ id, initialMessages, config, onClose } = {}) {
1414
+ function ChatInterface({ id, initialMessages, config, onClose, headerActions } = {}) {
1415
1415
  const { storageKeyPrefix } = useChatStorageKey();
1416
1416
  const storageKey = (key) => storageKeyPrefix ? `chat-${storageKeyPrefix}-${key}` : `chat-${key}`;
1417
1417
  const themeMode = config?.theme?.mode || "light";
@@ -2082,6 +2082,7 @@ function ChatInterface({ id, initialMessages, config, onClose } = {}) {
2082
2082
  ] }, groupName)) }) })
2083
2083
  ] })
2084
2084
  ] }),
2085
+ headerActions,
2085
2086
  onClose && /* @__PURE__ */ jsx20(
2086
2087
  "button",
2087
2088
  {
@@ -2195,12 +2196,17 @@ function ChatWidget({
2195
2196
  theme,
2196
2197
  features,
2197
2198
  display,
2198
- starterPrompts
2199
+ starterPrompts,
2200
+ onClose,
2201
+ headerActions
2199
2202
  }) {
2203
+ const layout = display?.layout || "popup";
2200
2204
  const showToggleButton = display?.showToggleButton !== false;
2201
- const resizable = display?.resizable !== false;
2205
+ const resizable = layout === "popup" && display?.resizable !== false;
2202
2206
  const size = display?.size || "default";
2203
- const [isOpen, setIsOpen] = useState5(display?.defaultOpen || false);
2207
+ const [isOpen, setIsOpen] = useState5(
2208
+ layout !== "popup" ? true : display?.defaultOpen || false
2209
+ );
2204
2210
  const [isResizing, setIsResizing] = useState5(false);
2205
2211
  const containerRef = useRef4(null);
2206
2212
  const customStyles = useMemo3(() => {
@@ -2261,6 +2267,47 @@ function ChatWidget({
2261
2267
  starterPrompts
2262
2268
  }), [userId, model, systemPrompt, temperature, theme, features, starterPrompts]);
2263
2269
  const togglePosition = display?.toggleButtonPosition || { bottom: "24px", right: "24px" };
2270
+ const themeClass = theme?.mode === "dark" ? "dark" : "";
2271
+ if (layout === "inline") {
2272
+ return /* @__PURE__ */ jsx21(ChatStorageProvider, { userId, children: /* @__PURE__ */ jsx21(
2273
+ "div",
2274
+ {
2275
+ ref: containerRef,
2276
+ className: `chat-widget-container chat-widget-inline chat-widget-content ${themeClass} ${className || ""}`,
2277
+ style: customStyles,
2278
+ children: /* @__PURE__ */ jsx21(
2279
+ ChatInterface,
2280
+ {
2281
+ id: conversationId,
2282
+ initialMessages,
2283
+ config,
2284
+ onClose,
2285
+ headerActions
2286
+ }
2287
+ )
2288
+ }
2289
+ ) });
2290
+ }
2291
+ if (layout === "page") {
2292
+ return /* @__PURE__ */ jsx21(ChatStorageProvider, { userId, children: /* @__PURE__ */ jsx21(
2293
+ "div",
2294
+ {
2295
+ ref: containerRef,
2296
+ className: `chat-widget-container chat-widget-page chat-widget-content ${themeClass} ${className || ""}`,
2297
+ style: customStyles,
2298
+ children: /* @__PURE__ */ jsx21(
2299
+ ChatInterface,
2300
+ {
2301
+ id: conversationId,
2302
+ initialMessages,
2303
+ config,
2304
+ onClose,
2305
+ headerActions
2306
+ }
2307
+ )
2308
+ }
2309
+ ) });
2310
+ }
2264
2311
  return /* @__PURE__ */ jsxs13(ChatStorageProvider, { userId, children: [
2265
2312
  showToggleButton && !isOpen && /* @__PURE__ */ jsx21(
2266
2313
  "button",
@@ -2276,7 +2323,7 @@ function ChatWidget({
2276
2323
  "div",
2277
2324
  {
2278
2325
  ref: containerRef,
2279
- className: `chat-widget-container chat-widget-popup chat-widget-content ${theme?.mode === "dark" ? "dark" : ""} ${className || ""}`,
2326
+ className: `chat-widget-container chat-widget-popup chat-widget-content ${themeClass} ${className || ""}`,
2280
2327
  "data-size": size,
2281
2328
  "data-resizing": isResizing,
2282
2329
  style: customStyles,
@@ -2295,7 +2342,11 @@ function ChatWidget({
2295
2342
  id: conversationId,
2296
2343
  initialMessages,
2297
2344
  config,
2298
- onClose: () => setIsOpen(false)
2345
+ onClose: () => {
2346
+ setIsOpen(false);
2347
+ onClose?.();
2348
+ },
2349
+ headerActions
2299
2350
  }
2300
2351
  ) })
2301
2352
  ]