@dialtribe/chat-client 0.1.0 → 0.2.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/README.md +28 -2
- package/dist/index.d.mts +40 -5
- package/dist/index.d.ts +40 -5
- package/dist/index.js +35 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -5
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ export function App({ user }: { user: { id: string } | null }) {
|
|
|
58
58
|
return (
|
|
59
59
|
<DialtribeChatProvider
|
|
60
60
|
key={user.id}
|
|
61
|
-
serverUrl="https://
|
|
61
|
+
serverUrl="https://chatws.dialtribe.com"
|
|
62
62
|
getSessionToken={() => fetch("/api/chat-token").then((r) => r.text())}
|
|
63
63
|
>
|
|
64
64
|
<YourApp />
|
|
@@ -98,6 +98,8 @@ function MessageButton({ user }: { user: { id: string; name: string } }) {
|
|
|
98
98
|
| Prop | Default | |
|
|
99
99
|
|------|---------|--|
|
|
100
100
|
| `placement` | `"push"` | `"push"` or `"overlay"` (desktop) |
|
|
101
|
+
| `openPlacement` | `"push"` | With `placement="push"`: whether the open panel also pushes (`"push"`) or overlays (`"overlay"`). The collapsed rail always pushes |
|
|
102
|
+
| `items` | `[]` | Your own rail entries with your own panels (`RailItem[]`, see below) |
|
|
101
103
|
| `contexts` | `[]` | Extra rail entries, e.g. live shows: `{ roomId, label, avatarUrl?, badge? }` |
|
|
102
104
|
| `theme` | | `{ accent, background, surface, text, textMuted, border }` |
|
|
103
105
|
| `labels` | English | Override any string (`MessagesLabels`) to localize |
|
|
@@ -105,6 +107,30 @@ function MessageButton({ user }: { user: { id: string; name: string } }) {
|
|
|
105
107
|
| `railDmLimit` | `5` | Recent DMs shown as rail icons |
|
|
106
108
|
| `mobileBreakpoint` | `768` | Below this width the rail becomes the floating button |
|
|
107
109
|
|
|
110
|
+
### Your own rail items
|
|
111
|
+
|
|
112
|
+
Use the rail as your app's general-purpose rail: each item is your trigger
|
|
113
|
+
(shown with the rail-button chrome, active ring and badge) plus your panel
|
|
114
|
+
(any React, no header imposed).
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
<DialtribeMessages
|
|
118
|
+
items={[{
|
|
119
|
+
id: "account",
|
|
120
|
+
placement: "top", // "top" (default) above the inbox, "bottom" below the DMs
|
|
121
|
+
label: "Account",
|
|
122
|
+
trigger: ({ active }) => <ProfileAvatar active={active} />,
|
|
123
|
+
panel: ({ close }) => <AccountMenu onDone={close} />,
|
|
124
|
+
badge: 0,
|
|
125
|
+
}]}
|
|
126
|
+
/>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Don't put a `<button>` inside `trigger`: the rail wraps it in one. Clicking an
|
|
130
|
+
active trigger closes the panel, and `useDialtribeMessages().openItem("account")`
|
|
131
|
+
opens it from anywhere. On mobile the item lives in the drawer like everything
|
|
132
|
+
else.
|
|
133
|
+
|
|
108
134
|
## Hooks
|
|
109
135
|
|
|
110
136
|
All hooks must be under `<DialtribeChatProvider>`, which owns one connection
|
|
@@ -137,7 +163,7 @@ one subscription.
|
|
|
137
163
|
|
|
138
164
|
### `useDialtribeMessages()`
|
|
139
165
|
|
|
140
|
-
Drive the rail: `open`, `close`, `toggle`, `openInbox`, `openRoom(roomId)`,
|
|
166
|
+
Drive the rail: `open`, `close`, `toggle`, `openInbox`, `openRoom(roomId)`, `openItem(itemId)`,
|
|
141
167
|
`messageUser(userId, hint?)`, `isOpen`, `view`.
|
|
142
168
|
|
|
143
169
|
### `useChatConnection()`
|
package/dist/index.d.mts
CHANGED
|
@@ -311,7 +311,7 @@ declare class InboxStore extends Store<InboxSnapshot> {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
interface ChatClientOptions {
|
|
314
|
-
/** chat-ws base URL, e.g. "https://
|
|
314
|
+
/** chat-ws base URL, e.g. "https://chatws.dialtribe.com". */
|
|
315
315
|
serverUrl: string;
|
|
316
316
|
/**
|
|
317
317
|
* Returns a current `sess_` token minted by the host backend for the signed-in
|
|
@@ -419,6 +419,11 @@ type MessagesView = {
|
|
|
419
419
|
} | {
|
|
420
420
|
kind: "room";
|
|
421
421
|
roomId: string;
|
|
422
|
+
}
|
|
423
|
+
/** A host-defined rail item (DialtribeMessages `items`). */
|
|
424
|
+
| {
|
|
425
|
+
kind: "item";
|
|
426
|
+
itemId: string;
|
|
422
427
|
};
|
|
423
428
|
interface MessagesUiSnapshot {
|
|
424
429
|
open: boolean;
|
|
@@ -447,7 +452,7 @@ interface DialtribeChatProviderProps extends Omit<ChatClientOptions, "getSession
|
|
|
447
452
|
* {user && (
|
|
448
453
|
* <DialtribeChatProvider
|
|
449
454
|
* key={user.id}
|
|
450
|
-
* serverUrl="https://
|
|
455
|
+
* serverUrl="https://chatws.dialtribe.com"
|
|
451
456
|
* getSessionToken={() => fetch("/api/chat-token").then((r) => r.text())}
|
|
452
457
|
* >
|
|
453
458
|
* <App />
|
|
@@ -534,6 +539,8 @@ interface UseDialtribeMessagesReturn {
|
|
|
534
539
|
openInbox: () => void;
|
|
535
540
|
/** Show a room (a DM or a host context) in the rail. */
|
|
536
541
|
openRoom: (roomId: string) => void;
|
|
542
|
+
/** Show one of the host's own rail items (DialtribeMessages `items`) by id. */
|
|
543
|
+
openItem: (itemId: string) => void;
|
|
537
544
|
/**
|
|
538
545
|
* Start (or reopen) a DM with one of your users and show it. `hint` is only a
|
|
539
546
|
* display name for someone Dialtribe hasn't seen yet. Rejects with
|
|
@@ -586,6 +593,27 @@ interface MessagesContext {
|
|
|
586
593
|
/** Optional host-computed badge (e.g. new messages in that show's chat). */
|
|
587
594
|
badge?: number;
|
|
588
595
|
}
|
|
596
|
+
/**
|
|
597
|
+
* A host-defined rail entry: your own trigger (rendered inside the rail-button
|
|
598
|
+
* chrome, so don't put a <button> in it) and your own panel (any React).
|
|
599
|
+
*/
|
|
600
|
+
interface RailItem {
|
|
601
|
+
/** Stable unique id (also what useDialtribeMessages().openItem takes). */
|
|
602
|
+
id: string;
|
|
603
|
+
trigger: React.ReactNode | ((state: {
|
|
604
|
+
active: boolean;
|
|
605
|
+
}) => React.ReactNode);
|
|
606
|
+
/** Rendered in the panel area with no imposed header; `close` closes the rail. */
|
|
607
|
+
panel: React.ReactNode | ((state: {
|
|
608
|
+
close: () => void;
|
|
609
|
+
}) => React.ReactNode);
|
|
610
|
+
/** "top" (default) sits above the inbox button; "bottom" below the DMs. */
|
|
611
|
+
placement?: "top" | "bottom";
|
|
612
|
+
/** Count bubble on the trigger. */
|
|
613
|
+
badge?: number;
|
|
614
|
+
/** aria-label and tooltip. */
|
|
615
|
+
label?: string;
|
|
616
|
+
}
|
|
589
617
|
interface MessagesTheme {
|
|
590
618
|
accent?: string;
|
|
591
619
|
background?: string;
|
|
@@ -595,8 +623,15 @@ interface MessagesTheme {
|
|
|
595
623
|
border?: string;
|
|
596
624
|
}
|
|
597
625
|
interface DialtribeMessagesProps {
|
|
598
|
-
/** Desktop: "push"
|
|
626
|
+
/** Desktop: "push" reserves room for the rail on the page; "overlay" floats over it. */
|
|
599
627
|
placement?: "push" | "overlay";
|
|
628
|
+
/**
|
|
629
|
+
* With placement="push": whether the open panel also pushes the page ("push",
|
|
630
|
+
* default) or overlays it ("overlay"). The collapsed rail always pushes.
|
|
631
|
+
*/
|
|
632
|
+
openPlacement?: "push" | "overlay";
|
|
633
|
+
/** Your own rail entries (e.g. an account menu), above or below the DMs. */
|
|
634
|
+
items?: RailItem[];
|
|
600
635
|
/** Extra rail entries above the DMs, e.g. live shows (room chats). */
|
|
601
636
|
contexts?: MessagesContext[];
|
|
602
637
|
theme?: MessagesTheme;
|
|
@@ -623,7 +658,7 @@ interface DialtribeMessagesProps {
|
|
|
623
658
|
* </DialtribeChatProvider>
|
|
624
659
|
* ```
|
|
625
660
|
*/
|
|
626
|
-
declare function DialtribeMessages({ placement, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
|
|
661
|
+
declare function DialtribeMessages({ placement, openPlacement, items, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
|
|
627
662
|
|
|
628
663
|
interface AvatarProps {
|
|
629
664
|
name: string;
|
|
@@ -702,4 +737,4 @@ interface ChatInputProps {
|
|
|
702
737
|
*/
|
|
703
738
|
declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
|
|
704
739
|
|
|
705
|
-
export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type ParsedReactions, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
|
|
740
|
+
export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type ParsedReactions, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
|
package/dist/index.d.ts
CHANGED
|
@@ -311,7 +311,7 @@ declare class InboxStore extends Store<InboxSnapshot> {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
interface ChatClientOptions {
|
|
314
|
-
/** chat-ws base URL, e.g. "https://
|
|
314
|
+
/** chat-ws base URL, e.g. "https://chatws.dialtribe.com". */
|
|
315
315
|
serverUrl: string;
|
|
316
316
|
/**
|
|
317
317
|
* Returns a current `sess_` token minted by the host backend for the signed-in
|
|
@@ -419,6 +419,11 @@ type MessagesView = {
|
|
|
419
419
|
} | {
|
|
420
420
|
kind: "room";
|
|
421
421
|
roomId: string;
|
|
422
|
+
}
|
|
423
|
+
/** A host-defined rail item (DialtribeMessages `items`). */
|
|
424
|
+
| {
|
|
425
|
+
kind: "item";
|
|
426
|
+
itemId: string;
|
|
422
427
|
};
|
|
423
428
|
interface MessagesUiSnapshot {
|
|
424
429
|
open: boolean;
|
|
@@ -447,7 +452,7 @@ interface DialtribeChatProviderProps extends Omit<ChatClientOptions, "getSession
|
|
|
447
452
|
* {user && (
|
|
448
453
|
* <DialtribeChatProvider
|
|
449
454
|
* key={user.id}
|
|
450
|
-
* serverUrl="https://
|
|
455
|
+
* serverUrl="https://chatws.dialtribe.com"
|
|
451
456
|
* getSessionToken={() => fetch("/api/chat-token").then((r) => r.text())}
|
|
452
457
|
* >
|
|
453
458
|
* <App />
|
|
@@ -534,6 +539,8 @@ interface UseDialtribeMessagesReturn {
|
|
|
534
539
|
openInbox: () => void;
|
|
535
540
|
/** Show a room (a DM or a host context) in the rail. */
|
|
536
541
|
openRoom: (roomId: string) => void;
|
|
542
|
+
/** Show one of the host's own rail items (DialtribeMessages `items`) by id. */
|
|
543
|
+
openItem: (itemId: string) => void;
|
|
537
544
|
/**
|
|
538
545
|
* Start (or reopen) a DM with one of your users and show it. `hint` is only a
|
|
539
546
|
* display name for someone Dialtribe hasn't seen yet. Rejects with
|
|
@@ -586,6 +593,27 @@ interface MessagesContext {
|
|
|
586
593
|
/** Optional host-computed badge (e.g. new messages in that show's chat). */
|
|
587
594
|
badge?: number;
|
|
588
595
|
}
|
|
596
|
+
/**
|
|
597
|
+
* A host-defined rail entry: your own trigger (rendered inside the rail-button
|
|
598
|
+
* chrome, so don't put a <button> in it) and your own panel (any React).
|
|
599
|
+
*/
|
|
600
|
+
interface RailItem {
|
|
601
|
+
/** Stable unique id (also what useDialtribeMessages().openItem takes). */
|
|
602
|
+
id: string;
|
|
603
|
+
trigger: React.ReactNode | ((state: {
|
|
604
|
+
active: boolean;
|
|
605
|
+
}) => React.ReactNode);
|
|
606
|
+
/** Rendered in the panel area with no imposed header; `close` closes the rail. */
|
|
607
|
+
panel: React.ReactNode | ((state: {
|
|
608
|
+
close: () => void;
|
|
609
|
+
}) => React.ReactNode);
|
|
610
|
+
/** "top" (default) sits above the inbox button; "bottom" below the DMs. */
|
|
611
|
+
placement?: "top" | "bottom";
|
|
612
|
+
/** Count bubble on the trigger. */
|
|
613
|
+
badge?: number;
|
|
614
|
+
/** aria-label and tooltip. */
|
|
615
|
+
label?: string;
|
|
616
|
+
}
|
|
589
617
|
interface MessagesTheme {
|
|
590
618
|
accent?: string;
|
|
591
619
|
background?: string;
|
|
@@ -595,8 +623,15 @@ interface MessagesTheme {
|
|
|
595
623
|
border?: string;
|
|
596
624
|
}
|
|
597
625
|
interface DialtribeMessagesProps {
|
|
598
|
-
/** Desktop: "push"
|
|
626
|
+
/** Desktop: "push" reserves room for the rail on the page; "overlay" floats over it. */
|
|
599
627
|
placement?: "push" | "overlay";
|
|
628
|
+
/**
|
|
629
|
+
* With placement="push": whether the open panel also pushes the page ("push",
|
|
630
|
+
* default) or overlays it ("overlay"). The collapsed rail always pushes.
|
|
631
|
+
*/
|
|
632
|
+
openPlacement?: "push" | "overlay";
|
|
633
|
+
/** Your own rail entries (e.g. an account menu), above or below the DMs. */
|
|
634
|
+
items?: RailItem[];
|
|
600
635
|
/** Extra rail entries above the DMs, e.g. live shows (room chats). */
|
|
601
636
|
contexts?: MessagesContext[];
|
|
602
637
|
theme?: MessagesTheme;
|
|
@@ -623,7 +658,7 @@ interface DialtribeMessagesProps {
|
|
|
623
658
|
* </DialtribeChatProvider>
|
|
624
659
|
* ```
|
|
625
660
|
*/
|
|
626
|
-
declare function DialtribeMessages({ placement, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
|
|
661
|
+
declare function DialtribeMessages({ placement, openPlacement, items, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
|
|
627
662
|
|
|
628
663
|
interface AvatarProps {
|
|
629
664
|
name: string;
|
|
@@ -702,4 +737,4 @@ interface ChatInputProps {
|
|
|
702
737
|
*/
|
|
703
738
|
declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
|
|
704
739
|
|
|
705
|
-
export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type ParsedReactions, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
|
|
740
|
+
export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type ParsedReactions, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages };
|
package/dist/index.js
CHANGED
|
@@ -676,6 +676,9 @@ var MessagesUiStore = class extends Store {
|
|
|
676
676
|
openRoom(roomId) {
|
|
677
677
|
this.update({ open: true, view: { kind: "room", roomId } });
|
|
678
678
|
}
|
|
679
|
+
openItem(itemId) {
|
|
680
|
+
this.update({ open: true, view: { kind: "item", itemId } });
|
|
681
|
+
}
|
|
679
682
|
};
|
|
680
683
|
var ClientContext = react.createContext(null);
|
|
681
684
|
var MessagesUiContext = react.createContext(null);
|
|
@@ -786,6 +789,7 @@ function useDialtribeMessages() {
|
|
|
786
789
|
toggle: () => ui.toggle(),
|
|
787
790
|
openInbox: () => ui.openInbox(),
|
|
788
791
|
openRoom: (roomId) => ui.openRoom(roomId),
|
|
792
|
+
openItem: (itemId) => ui.openItem(itemId),
|
|
789
793
|
messageUser: async (userId, hint) => {
|
|
790
794
|
const result = await client.inbox.requestDM(userId, hint);
|
|
791
795
|
ui.openRoom(result.roomId);
|
|
@@ -1191,6 +1195,8 @@ var EDGE_SWIPE_ZONE = 24;
|
|
|
1191
1195
|
var SWIPE_DISTANCE = 60;
|
|
1192
1196
|
function DialtribeMessages({
|
|
1193
1197
|
placement = "push",
|
|
1198
|
+
openPlacement = "push",
|
|
1199
|
+
items = [],
|
|
1194
1200
|
contexts = [],
|
|
1195
1201
|
theme,
|
|
1196
1202
|
labels: labelOverrides,
|
|
@@ -1208,7 +1214,12 @@ function DialtribeMessages({
|
|
|
1208
1214
|
const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted").slice(0, railDmLimit);
|
|
1209
1215
|
const activeRoomId = isOpen && view.kind === "room" ? view.roomId : null;
|
|
1210
1216
|
const activeContext = contexts.find((c) => c.roomId === activeRoomId);
|
|
1211
|
-
|
|
1217
|
+
const activeItemId = isOpen && view.kind === "item" ? view.itemId : null;
|
|
1218
|
+
const activeItem = items.find((i) => i.id === activeItemId);
|
|
1219
|
+
const topItems = items.filter((i) => (i.placement ?? "top") === "top");
|
|
1220
|
+
const bottomItems = items.filter((i) => i.placement === "bottom");
|
|
1221
|
+
const panelInset = isOpen && openPlacement === "push" ? panelWidth : 0;
|
|
1222
|
+
usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + panelInset);
|
|
1212
1223
|
useScrollLock(isMobile && isOpen);
|
|
1213
1224
|
useEdgeSwipe(isMobile, isOpen, ui.open, ui.close);
|
|
1214
1225
|
react.useEffect(() => {
|
|
@@ -1218,10 +1229,25 @@ function DialtribeMessages({
|
|
|
1218
1229
|
return () => window.removeEventListener("keydown", onKey);
|
|
1219
1230
|
}, [isOpen, ui]);
|
|
1220
1231
|
const select = (target) => {
|
|
1221
|
-
const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : activeRoomId === target.roomId);
|
|
1232
|
+
const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : activeItemId === target.itemId);
|
|
1222
1233
|
if (showing) ui.close();
|
|
1223
1234
|
else if (target.kind === "inbox") ui.openInbox();
|
|
1224
|
-
else ui.openRoom(target.roomId);
|
|
1235
|
+
else if (target.kind === "room") ui.openRoom(target.roomId);
|
|
1236
|
+
else ui.openItem(target.itemId);
|
|
1237
|
+
};
|
|
1238
|
+
const renderItemButton = (item) => {
|
|
1239
|
+
const active = activeItemId === item.id;
|
|
1240
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1241
|
+
RailButton,
|
|
1242
|
+
{
|
|
1243
|
+
label: item.label ?? item.id,
|
|
1244
|
+
active,
|
|
1245
|
+
badge: item.badge ?? 0,
|
|
1246
|
+
onClick: () => select({ kind: "item", itemId: item.id }),
|
|
1247
|
+
children: typeof item.trigger === "function" ? item.trigger({ active }) : item.trigger
|
|
1248
|
+
},
|
|
1249
|
+
item.id
|
|
1250
|
+
);
|
|
1225
1251
|
};
|
|
1226
1252
|
const style = { ...themeVars(theme), "--dtc-panel-width": `${panelWidth}px`, "--dtc-rail-width": `${RAIL_WIDTH}px` };
|
|
1227
1253
|
const showRail = !isMobile || isOpen;
|
|
@@ -1235,7 +1261,7 @@ function DialtribeMessages({
|
|
|
1235
1261
|
/* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {}),
|
|
1236
1262
|
rollup > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
|
|
1237
1263
|
] }),
|
|
1238
|
-
isOpen && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": labels.messages, children: view.kind
|
|
1264
|
+
isOpen && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: activeItem ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-item-panel", children: typeof activeItem.panel === "function" ? activeItem.panel({ close: ui.close }) : activeItem.panel }) : view.kind !== "room" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1239
1265
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
|
|
1240
1266
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
|
|
1241
1267
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
|
|
@@ -1250,6 +1276,8 @@ function DialtribeMessages({
|
|
|
1250
1276
|
/* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
|
|
1251
1277
|
] }) : /* @__PURE__ */ jsxRuntime.jsx(ConversationView, { roomId: view.roomId, labels, onBack: ui.openInbox }, view.roomId) }),
|
|
1252
1278
|
showRail && /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "dtc-rail", "aria-label": labels.messages, children: [
|
|
1279
|
+
topItems.map(renderItemButton),
|
|
1280
|
+
topItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
|
|
1253
1281
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1254
1282
|
RailButton,
|
|
1255
1283
|
{
|
|
@@ -1283,7 +1311,9 @@ function DialtribeMessages({
|
|
|
1283
1311
|
children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 36 })
|
|
1284
1312
|
},
|
|
1285
1313
|
room.roomId
|
|
1286
|
-
))
|
|
1314
|
+
)),
|
|
1315
|
+
bottomItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
|
|
1316
|
+
bottomItems.map(renderItemButton)
|
|
1287
1317
|
] })
|
|
1288
1318
|
]
|
|
1289
1319
|
}
|