@fluxy-chat/ui-kit 0.1.1 → 0.1.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 +2 -2
- package/dist/fluxy-chat-widget.d.ts +4 -1
- package/dist/fluxy-chat-widget.js +42 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ import { FluxyChatWidget } from "@fluxy-chat/ui-kit";
|
|
|
18
18
|
<FluxyChatWidget
|
|
19
19
|
roomId="general"
|
|
20
20
|
workerUrl={process.env.NEXT_PUBLIC_FLUXYCHAT_WORKER_URL!}
|
|
21
|
-
|
|
21
|
+
guest
|
|
22
22
|
theme="brand"
|
|
23
23
|
height={520}
|
|
24
24
|
/>
|
|
@@ -50,7 +50,7 @@ return <Thread runtime={runtime} />;
|
|
|
50
50
|
## CLI
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
|
-
npx create-fluxy-chat my-chat --minimal
|
|
53
|
+
npx @fluxy-chat/create-fluxy-chat@latest my-chat --minimal
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
Generates Vite + `FluxyChatWidget` only (no platform modules).
|
|
@@ -7,10 +7,13 @@ export interface FluxyChatWidgetProps {
|
|
|
7
7
|
workerUrl?: string;
|
|
8
8
|
token?: string;
|
|
9
9
|
userId?: string;
|
|
10
|
+
/** Join a public room with joinPublicRoomAsGuest (no member JWT). */
|
|
11
|
+
guest?: boolean;
|
|
12
|
+
displayName?: string;
|
|
10
13
|
theme?: FluxyThemeId;
|
|
11
14
|
className?: string;
|
|
12
15
|
height?: string | number;
|
|
13
16
|
title?: string;
|
|
14
17
|
}
|
|
15
18
|
/** Drop-in chat widget — polished UI out of the box. */
|
|
16
|
-
export declare function FluxyChatWidget({ roomId, client: clientProp, workerUrl, token, userId, theme, className, height, title, }: FluxyChatWidgetProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare function FluxyChatWidget({ roomId, client: clientProp, workerUrl, token, userId, guest, displayName, theme, className, height, title, }: FluxyChatWidgetProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useMemo } from "react";
|
|
3
|
+
import { useEffect, useMemo, useState } from "react";
|
|
4
4
|
import { FluxyChatClient } from "@fluxy-chat/sdk";
|
|
5
5
|
import { useChat } from "@fluxy-chat/react";
|
|
6
6
|
import { ChatWindow, applyFluxyTheme, fluxyThemeClassName, } from "@fluxy-chat/ui";
|
|
7
|
-
import { useEffect } from "react";
|
|
8
7
|
function WidgetInner({ roomId, title, client, }) {
|
|
9
8
|
const { messages, sendMessage, connectionState, typingUsers, online } = useChat({
|
|
10
9
|
roomId,
|
|
@@ -14,8 +13,8 @@ function WidgetInner({ roomId, title, client, }) {
|
|
|
14
13
|
return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [title && (_jsxs("header", { className: "border-b border-border px-4 py-2 text-sm font-semibold", children: [title, _jsx("span", { className: "ml-2 font-normal text-muted-foreground", children: connectionState.status })] })), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(ChatWindow, { messages: messages, online: online, typingUsers: typingUsers, onSend: (text) => sendMessage(text) }) })] }));
|
|
15
14
|
}
|
|
16
15
|
/** Drop-in chat widget — polished UI out of the box. */
|
|
17
|
-
export function FluxyChatWidget({ roomId, client: clientProp, workerUrl, token, userId = "user-1", theme = "default", className, height = 480, title, }) {
|
|
18
|
-
const
|
|
16
|
+
export function FluxyChatWidget({ roomId, client: clientProp, workerUrl, token, userId = "user-1", guest = false, displayName, theme = "default", className, height = 480, title, }) {
|
|
17
|
+
const tokenClient = useMemo(() => {
|
|
19
18
|
if (clientProp)
|
|
20
19
|
return clientProp;
|
|
21
20
|
if (!workerUrl?.trim() || !token?.trim())
|
|
@@ -26,12 +25,49 @@ export function FluxyChatWidget({ roomId, client: clientProp, workerUrl, token,
|
|
|
26
25
|
token: token.trim(),
|
|
27
26
|
});
|
|
28
27
|
}, [clientProp, workerUrl, token, userId]);
|
|
28
|
+
const [guestClient, setGuestClient] = useState(null);
|
|
29
|
+
const [guestError, setGuestError] = useState(null);
|
|
29
30
|
useEffect(() => {
|
|
30
31
|
applyFluxyTheme(theme);
|
|
31
32
|
}, [theme]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (clientProp || token?.trim() || !guest || !workerUrl?.trim()) {
|
|
35
|
+
setGuestClient(null);
|
|
36
|
+
setGuestError(null);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let cancelled = false;
|
|
40
|
+
void FluxyChatClient.joinPublicRoomAsGuest(workerUrl.trim(), roomId, { displayName })
|
|
41
|
+
.then((session) => {
|
|
42
|
+
if (cancelled)
|
|
43
|
+
return;
|
|
44
|
+
setGuestClient(new FluxyChatClient({
|
|
45
|
+
baseUrl: workerUrl.trim(),
|
|
46
|
+
userId: session.userId,
|
|
47
|
+
token: session.token,
|
|
48
|
+
}));
|
|
49
|
+
})
|
|
50
|
+
.catch((err) => {
|
|
51
|
+
if (cancelled)
|
|
52
|
+
return;
|
|
53
|
+
setGuestError(err instanceof Error ? err.message : "Guest join failed");
|
|
54
|
+
});
|
|
55
|
+
return () => {
|
|
56
|
+
cancelled = true;
|
|
57
|
+
};
|
|
58
|
+
}, [clientProp, token, guest, workerUrl, roomId, displayName]);
|
|
59
|
+
const client = tokenClient ?? guestClient;
|
|
32
60
|
if (!client) {
|
|
33
|
-
return (_jsx("div", { className: className, style: { height, padding: 16, border: "1px solid #e4e4e7", borderRadius: 12 }, children:
|
|
61
|
+
return (_jsx("div", { className: className, style: { height, padding: 16, border: "1px solid #e4e4e7", borderRadius: 12 }, children: _jsx("p", { style: { margin: 0, fontSize: 14 }, children: guestError ??
|
|
62
|
+
"Set workerUrl plus token, pass guest on a public room, or pass a client." }) }));
|
|
34
63
|
}
|
|
35
64
|
const h = typeof height === "number" ? `${height}px` : height;
|
|
36
|
-
return (_jsx("div", { className: [fluxyThemeClassName(theme), className].filter(Boolean).join(" "), style: {
|
|
65
|
+
return (_jsx("div", { className: [fluxyThemeClassName(theme), className].filter(Boolean).join(" "), style: {
|
|
66
|
+
height: h,
|
|
67
|
+
display: "flex",
|
|
68
|
+
flexDirection: "column",
|
|
69
|
+
overflow: "hidden",
|
|
70
|
+
borderRadius: 12,
|
|
71
|
+
border: "1px solid #e4e4e7",
|
|
72
|
+
}, children: _jsx(WidgetInner, { roomId: roomId, title: title ?? roomId, client: client }) }));
|
|
37
73
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluxy-chat/ui-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Polished drop-in FluxyChat widget and inbox — built on @fluxy-chat/ui with optional assistant-ui runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=18",
|
|
22
|
-
"@fluxy-chat/sdk": "^0.6.
|
|
23
|
-
"@fluxy-chat/react": "^0.1.
|
|
22
|
+
"@fluxy-chat/sdk": "^0.6.5",
|
|
23
|
+
"@fluxy-chat/react": "^0.1.4",
|
|
24
24
|
"@fluxy-chat/ui": "^0.1.4",
|
|
25
25
|
"@assistant-ui/react": ">=0.10.0"
|
|
26
26
|
},
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@fluxy-chat/sdk": "0.6.
|
|
34
|
-
"@fluxy-chat/
|
|
35
|
-
"@fluxy-chat/
|
|
33
|
+
"@fluxy-chat/sdk": "0.6.5",
|
|
34
|
+
"@fluxy-chat/react": "0.1.4",
|
|
35
|
+
"@fluxy-chat/ui": "0.1.4"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/react": "^19.2.14",
|