@dialtribe/chat-client 0.2.0 → 0.3.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 +16 -6
- package/dist/index.d.mts +26 -4
- package/dist/index.d.ts +26 -4
- package/dist/index.js +150 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -84
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,10 +72,12 @@ Mount the provider only while someone is signed in, keyed by their user id.
|
|
|
72
72
|
Signing out or switching accounts then drops the old connection, inbox and
|
|
73
73
|
token rather than showing one user's messages to the next.
|
|
74
74
|
|
|
75
|
-
- **Desktop:** a rail pinned to the right edge (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
- **Desktop:** a rail pinned to the right edge (or the left, with `side="left"`)
|
|
76
|
+
holding the inbox, your contexts, recent DMs and unread badges, with a panel
|
|
77
|
+
that opens beside it. `placement="push"` pads the page so nothing is covered;
|
|
78
|
+
`"overlay"` floats over it. For your own fixed-position elements the root
|
|
79
|
+
element exposes `--dtc-messages-inset` (the width), plus
|
|
80
|
+
`--dtc-messages-side` and `data-dtc-messages-side` (`left` or `right`).
|
|
79
81
|
- **Mobile:** a floating button with a total badge. Tap it, or swipe in from the
|
|
80
82
|
right edge, to open; swipe right or press Escape to close.
|
|
81
83
|
|
|
@@ -97,9 +99,11 @@ function MessageButton({ user }: { user: { id: string; name: string } }) {
|
|
|
97
99
|
|
|
98
100
|
| Prop | Default | |
|
|
99
101
|
|------|---------|--|
|
|
102
|
+
| `side` | `"right"` | Which screen edge the rail docks to: `"left"` or `"right"` |
|
|
100
103
|
| `placement` | `"push"` | `"push"` or `"overlay"` (desktop) |
|
|
101
104
|
| `openPlacement` | `"push"` | With `placement="push"`: whether the open panel also pushes (`"push"`) or overlays (`"overlay"`). The collapsed rail always pushes |
|
|
102
105
|
| `items` | `[]` | Your own rail entries with your own panels (`RailItem[]`, see below) |
|
|
106
|
+
| `inboxRowClose` | `true` | An X on inbox conversations that removes them from the user's inbox (see `hideDM`) |
|
|
103
107
|
| `contexts` | `[]` | Extra rail entries, e.g. live shows: `{ roomId, label, avatarUrl?, badge? }` |
|
|
104
108
|
| `theme` | | `{ accent, background, surface, text, textMuted, border }` |
|
|
105
109
|
| `labels` | English | Override any string (`MessagesLabels`) to localize |
|
|
@@ -117,7 +121,8 @@ Use the rail as your app's general-purpose rail: each item is your trigger
|
|
|
117
121
|
<DialtribeMessages
|
|
118
122
|
items={[{
|
|
119
123
|
id: "account",
|
|
120
|
-
placement: "
|
|
124
|
+
placement: "footer", // "top" (default) above the inbox, "bottom" below the DMs,
|
|
125
|
+
// "footer" pinned to the bottom edge (doesn't scroll)
|
|
121
126
|
label: "Account",
|
|
122
127
|
trigger: ({ active }) => <ProfileAvatar active={active} />,
|
|
123
128
|
panel: ({ close }) => <AccountMenu onDone={close} />,
|
|
@@ -145,7 +150,7 @@ const {
|
|
|
145
150
|
rooms, // every DM, newest first (DmRoomSummary[])
|
|
146
151
|
requests, // incoming requests not yet answered
|
|
147
152
|
totalUnread, // across unmuted, accepted DMs
|
|
148
|
-
requestDM, acceptDM, ignoreDM, closeDM, reopenDM,
|
|
153
|
+
requestDM, acceptDM, ignoreDM, closeDM, reopenDM, hideDM,
|
|
149
154
|
addParticipant, setMuted, markRead, setVisible, refresh,
|
|
150
155
|
} = useChatRooms();
|
|
151
156
|
```
|
|
@@ -153,6 +158,11 @@ const {
|
|
|
153
158
|
A request id is the DM's room id. Ignoring is silent: the requester keeps
|
|
154
159
|
seeing "Request sent". Adding someone to a 1:1 starts a new group conversation.
|
|
155
160
|
|
|
161
|
+
`hideDM(roomId)` removes a conversation from this user's inbox only. Nothing is
|
|
162
|
+
deleted and the other person sees no change; it comes back when a newer message
|
|
163
|
+
arrives or when the user messages or reopens it. `closeDM` is different: it
|
|
164
|
+
closes the conversation for everyone and makes it read-only.
|
|
165
|
+
|
|
156
166
|
### `useDialtribeChat({ roomId })`
|
|
157
167
|
|
|
158
168
|
One room (a DM or a show room): `messages`, `config`, `typingUsers`, `status`,
|
package/dist/index.d.mts
CHANGED
|
@@ -275,6 +275,12 @@ declare class InboxStore extends Store<InboxSnapshot> {
|
|
|
275
275
|
private readTimers;
|
|
276
276
|
/** Rooms currently on screen: activity there is read, not unread. */
|
|
277
277
|
private visible;
|
|
278
|
+
/**
|
|
279
|
+
* Rooms the user removed (hide/ignore) and when. Filtered out of every list,
|
|
280
|
+
* so a refresh already in flight can't put them back, until a newer message
|
|
281
|
+
* arrives or the user messages/reopens/accepts them.
|
|
282
|
+
*/
|
|
283
|
+
private removed;
|
|
278
284
|
constructor(client: ChatClient);
|
|
279
285
|
acquire(): void;
|
|
280
286
|
release(): void;
|
|
@@ -292,6 +298,12 @@ declare class InboxStore extends Store<InboxSnapshot> {
|
|
|
292
298
|
name?: string;
|
|
293
299
|
avatarUrl?: string;
|
|
294
300
|
}): Promise<string>;
|
|
301
|
+
/**
|
|
302
|
+
* Remove a conversation from the user's own inbox (optimistic). Not deleted
|
|
303
|
+
* and nobody else is affected: it comes back when a newer message arrives or
|
|
304
|
+
* when the user messages/reopens it.
|
|
305
|
+
*/
|
|
306
|
+
hideDM(roomId: string): Promise<void>;
|
|
295
307
|
setMuted(roomId: string, muted: boolean): Promise<void>;
|
|
296
308
|
/** Mark a room read now (optimistic). */
|
|
297
309
|
markRead(roomId: string): Promise<void>;
|
|
@@ -513,7 +525,7 @@ declare function ChatRoomProvider({ roomId, children }: ChatRoomProviderProps):
|
|
|
513
525
|
/** The room from the nearest <ChatRoomProvider>. */
|
|
514
526
|
declare function useChatRoomContext(): UseDialtribeChatReturn;
|
|
515
527
|
|
|
516
|
-
type UseChatRoomsReturn = InboxSnapshot & Pick<InboxStore, "requestDM" | "acceptDM" | "ignoreDM" | "closeDM" | "reopenDM" | "addParticipant" | "setMuted" | "markRead" | "setVisible" | "refresh">;
|
|
528
|
+
type UseChatRoomsReturn = InboxSnapshot & Pick<InboxStore, "requestDM" | "acceptDM" | "ignoreDM" | "closeDM" | "reopenDM" | "hideDM" | "addParticipant" | "setMuted" | "markRead" | "setVisible" | "refresh">;
|
|
517
529
|
/**
|
|
518
530
|
* The signed-in user's DMs: inbox (newest first), incoming requests, unread
|
|
519
531
|
* totals, and every DM action. Live via the personal channel; reconciled with
|
|
@@ -578,6 +590,8 @@ interface MessagesLabels {
|
|
|
578
590
|
conversationClosed: string;
|
|
579
591
|
reopen: string;
|
|
580
592
|
closeConversation: string;
|
|
593
|
+
/** Inbox row X: remove from the inbox (comes back on a new message). */
|
|
594
|
+
removeConversation: string;
|
|
581
595
|
mute: string;
|
|
582
596
|
unmute: string;
|
|
583
597
|
messagePlaceholder: string;
|
|
@@ -607,8 +621,12 @@ interface RailItem {
|
|
|
607
621
|
panel: React.ReactNode | ((state: {
|
|
608
622
|
close: () => void;
|
|
609
623
|
}) => React.ReactNode);
|
|
610
|
-
/**
|
|
611
|
-
|
|
624
|
+
/**
|
|
625
|
+
* "top" (default) sits above the inbox button; "bottom" below the DMs (both
|
|
626
|
+
* scroll with the rail); "footer" is pinned to the bottom edge and never
|
|
627
|
+
* scrolls, e.g. the signed-in user's avatar opening a profile menu.
|
|
628
|
+
*/
|
|
629
|
+
placement?: "top" | "bottom" | "footer";
|
|
612
630
|
/** Count bubble on the trigger. */
|
|
613
631
|
badge?: number;
|
|
614
632
|
/** aria-label and tooltip. */
|
|
@@ -623,6 +641,8 @@ interface MessagesTheme {
|
|
|
623
641
|
border?: string;
|
|
624
642
|
}
|
|
625
643
|
interface DialtribeMessagesProps {
|
|
644
|
+
/** Which screen edge the rail docks to. */
|
|
645
|
+
side?: "left" | "right";
|
|
626
646
|
/** Desktop: "push" reserves room for the rail on the page; "overlay" floats over it. */
|
|
627
647
|
placement?: "push" | "overlay";
|
|
628
648
|
/**
|
|
@@ -632,6 +652,8 @@ interface DialtribeMessagesProps {
|
|
|
632
652
|
openPlacement?: "push" | "overlay";
|
|
633
653
|
/** Your own rail entries (e.g. an account menu), above or below the DMs. */
|
|
634
654
|
items?: RailItem[];
|
|
655
|
+
/** Show a close (X) on inbox conversations that removes them from the inbox. */
|
|
656
|
+
inboxRowClose?: boolean;
|
|
635
657
|
/** Extra rail entries above the DMs, e.g. live shows (room chats). */
|
|
636
658
|
contexts?: MessagesContext[];
|
|
637
659
|
theme?: MessagesTheme;
|
|
@@ -658,7 +680,7 @@ interface DialtribeMessagesProps {
|
|
|
658
680
|
* </DialtribeChatProvider>
|
|
659
681
|
* ```
|
|
660
682
|
*/
|
|
661
|
-
declare function DialtribeMessages({ placement, openPlacement, items, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
|
|
683
|
+
declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
|
|
662
684
|
|
|
663
685
|
interface AvatarProps {
|
|
664
686
|
name: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -275,6 +275,12 @@ declare class InboxStore extends Store<InboxSnapshot> {
|
|
|
275
275
|
private readTimers;
|
|
276
276
|
/** Rooms currently on screen: activity there is read, not unread. */
|
|
277
277
|
private visible;
|
|
278
|
+
/**
|
|
279
|
+
* Rooms the user removed (hide/ignore) and when. Filtered out of every list,
|
|
280
|
+
* so a refresh already in flight can't put them back, until a newer message
|
|
281
|
+
* arrives or the user messages/reopens/accepts them.
|
|
282
|
+
*/
|
|
283
|
+
private removed;
|
|
278
284
|
constructor(client: ChatClient);
|
|
279
285
|
acquire(): void;
|
|
280
286
|
release(): void;
|
|
@@ -292,6 +298,12 @@ declare class InboxStore extends Store<InboxSnapshot> {
|
|
|
292
298
|
name?: string;
|
|
293
299
|
avatarUrl?: string;
|
|
294
300
|
}): Promise<string>;
|
|
301
|
+
/**
|
|
302
|
+
* Remove a conversation from the user's own inbox (optimistic). Not deleted
|
|
303
|
+
* and nobody else is affected: it comes back when a newer message arrives or
|
|
304
|
+
* when the user messages/reopens it.
|
|
305
|
+
*/
|
|
306
|
+
hideDM(roomId: string): Promise<void>;
|
|
295
307
|
setMuted(roomId: string, muted: boolean): Promise<void>;
|
|
296
308
|
/** Mark a room read now (optimistic). */
|
|
297
309
|
markRead(roomId: string): Promise<void>;
|
|
@@ -513,7 +525,7 @@ declare function ChatRoomProvider({ roomId, children }: ChatRoomProviderProps):
|
|
|
513
525
|
/** The room from the nearest <ChatRoomProvider>. */
|
|
514
526
|
declare function useChatRoomContext(): UseDialtribeChatReturn;
|
|
515
527
|
|
|
516
|
-
type UseChatRoomsReturn = InboxSnapshot & Pick<InboxStore, "requestDM" | "acceptDM" | "ignoreDM" | "closeDM" | "reopenDM" | "addParticipant" | "setMuted" | "markRead" | "setVisible" | "refresh">;
|
|
528
|
+
type UseChatRoomsReturn = InboxSnapshot & Pick<InboxStore, "requestDM" | "acceptDM" | "ignoreDM" | "closeDM" | "reopenDM" | "hideDM" | "addParticipant" | "setMuted" | "markRead" | "setVisible" | "refresh">;
|
|
517
529
|
/**
|
|
518
530
|
* The signed-in user's DMs: inbox (newest first), incoming requests, unread
|
|
519
531
|
* totals, and every DM action. Live via the personal channel; reconciled with
|
|
@@ -578,6 +590,8 @@ interface MessagesLabels {
|
|
|
578
590
|
conversationClosed: string;
|
|
579
591
|
reopen: string;
|
|
580
592
|
closeConversation: string;
|
|
593
|
+
/** Inbox row X: remove from the inbox (comes back on a new message). */
|
|
594
|
+
removeConversation: string;
|
|
581
595
|
mute: string;
|
|
582
596
|
unmute: string;
|
|
583
597
|
messagePlaceholder: string;
|
|
@@ -607,8 +621,12 @@ interface RailItem {
|
|
|
607
621
|
panel: React.ReactNode | ((state: {
|
|
608
622
|
close: () => void;
|
|
609
623
|
}) => React.ReactNode);
|
|
610
|
-
/**
|
|
611
|
-
|
|
624
|
+
/**
|
|
625
|
+
* "top" (default) sits above the inbox button; "bottom" below the DMs (both
|
|
626
|
+
* scroll with the rail); "footer" is pinned to the bottom edge and never
|
|
627
|
+
* scrolls, e.g. the signed-in user's avatar opening a profile menu.
|
|
628
|
+
*/
|
|
629
|
+
placement?: "top" | "bottom" | "footer";
|
|
612
630
|
/** Count bubble on the trigger. */
|
|
613
631
|
badge?: number;
|
|
614
632
|
/** aria-label and tooltip. */
|
|
@@ -623,6 +641,8 @@ interface MessagesTheme {
|
|
|
623
641
|
border?: string;
|
|
624
642
|
}
|
|
625
643
|
interface DialtribeMessagesProps {
|
|
644
|
+
/** Which screen edge the rail docks to. */
|
|
645
|
+
side?: "left" | "right";
|
|
626
646
|
/** Desktop: "push" reserves room for the rail on the page; "overlay" floats over it. */
|
|
627
647
|
placement?: "push" | "overlay";
|
|
628
648
|
/**
|
|
@@ -632,6 +652,8 @@ interface DialtribeMessagesProps {
|
|
|
632
652
|
openPlacement?: "push" | "overlay";
|
|
633
653
|
/** Your own rail entries (e.g. an account menu), above or below the DMs. */
|
|
634
654
|
items?: RailItem[];
|
|
655
|
+
/** Show a close (X) on inbox conversations that removes them from the inbox. */
|
|
656
|
+
inboxRowClose?: boolean;
|
|
635
657
|
/** Extra rail entries above the DMs, e.g. live shows (room chats). */
|
|
636
658
|
contexts?: MessagesContext[];
|
|
637
659
|
theme?: MessagesTheme;
|
|
@@ -658,7 +680,7 @@ interface DialtribeMessagesProps {
|
|
|
658
680
|
* </DialtribeChatProvider>
|
|
659
681
|
* ```
|
|
660
682
|
*/
|
|
661
|
-
declare function DialtribeMessages({ placement, openPlacement, items, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
|
|
683
|
+
declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, }: DialtribeMessagesProps): react.JSX.Element;
|
|
662
684
|
|
|
663
685
|
interface AvatarProps {
|
|
664
686
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -241,6 +241,12 @@ var InboxStore = class extends Store {
|
|
|
241
241
|
this.readTimers = /* @__PURE__ */ new Map();
|
|
242
242
|
/** Rooms currently on screen: activity there is read, not unread. */
|
|
243
243
|
this.visible = /* @__PURE__ */ new Map();
|
|
244
|
+
/**
|
|
245
|
+
* Rooms the user removed (hide/ignore) and when. Filtered out of every list,
|
|
246
|
+
* so a refresh already in flight can't put them back, until a newer message
|
|
247
|
+
* arrives or the user messages/reopens/accepts them.
|
|
248
|
+
*/
|
|
249
|
+
this.removed = /* @__PURE__ */ new Map();
|
|
244
250
|
}
|
|
245
251
|
acquire() {
|
|
246
252
|
this.refs += 1;
|
|
@@ -271,11 +277,13 @@ var InboxStore = class extends Store {
|
|
|
271
277
|
targetAvatarUrl: hint?.avatarUrl,
|
|
272
278
|
showRequestId: hint?.showRequestId
|
|
273
279
|
});
|
|
280
|
+
this.removed.delete(result.roomId);
|
|
274
281
|
await this.refresh();
|
|
275
282
|
return { status: result.status, roomId: result.roomId };
|
|
276
283
|
}
|
|
277
284
|
async acceptDM(requestId) {
|
|
278
285
|
const { roomId } = await this.client.dm("chat-dm-accept", { requestId });
|
|
286
|
+
this.removed.delete(roomId);
|
|
279
287
|
await this.refresh();
|
|
280
288
|
return roomId;
|
|
281
289
|
}
|
|
@@ -289,6 +297,7 @@ var InboxStore = class extends Store {
|
|
|
289
297
|
}
|
|
290
298
|
async reopenDM(roomId) {
|
|
291
299
|
await this.client.dm("chat-dm-reopen", { roomId });
|
|
300
|
+
this.removed.delete(roomId);
|
|
292
301
|
await this.refresh();
|
|
293
302
|
}
|
|
294
303
|
/** Add someone. Returns the room to show (a new group when added to a 1:1). */
|
|
@@ -302,6 +311,21 @@ var InboxStore = class extends Store {
|
|
|
302
311
|
await this.refresh();
|
|
303
312
|
return result.roomId;
|
|
304
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Remove a conversation from the user's own inbox (optimistic). Not deleted
|
|
316
|
+
* and nobody else is affected: it comes back when a newer message arrives or
|
|
317
|
+
* when the user messages/reopens it.
|
|
318
|
+
*/
|
|
319
|
+
async hideDM(roomId) {
|
|
320
|
+
this.removeLocally(roomId);
|
|
321
|
+
try {
|
|
322
|
+
await this.client.dm("chat-dm-hide", { roomId });
|
|
323
|
+
} catch (err) {
|
|
324
|
+
this.removed.delete(roomId);
|
|
325
|
+
await this.refresh();
|
|
326
|
+
throw err;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
305
329
|
async setMuted(roomId, muted) {
|
|
306
330
|
this.patchRoom(roomId, (room) => ({ ...room, isMuted: muted }));
|
|
307
331
|
await this.client.dm("chat-dm-mute", { roomId, muted });
|
|
@@ -354,6 +378,7 @@ var InboxStore = class extends Store {
|
|
|
354
378
|
}
|
|
355
379
|
}
|
|
356
380
|
onActivity(roomId, message) {
|
|
381
|
+
this.removed.delete(roomId);
|
|
357
382
|
const known = this.getSnapshot().rooms.some((r) => r.roomId === roomId);
|
|
358
383
|
if (!known) {
|
|
359
384
|
this.scheduleRefresh(REFRESH_DEBOUNCE_MS);
|
|
@@ -411,9 +436,14 @@ var InboxStore = class extends Store {
|
|
|
411
436
|
this.setRooms(moveToTop ? [next, ...rest] : rooms.map((r, i) => i === index ? next : r));
|
|
412
437
|
}
|
|
413
438
|
removeLocally(roomId) {
|
|
414
|
-
this.
|
|
439
|
+
this.removed.set(roomId, Date.now());
|
|
440
|
+
this.setRooms(this.getSnapshot().rooms);
|
|
415
441
|
}
|
|
416
|
-
setRooms(
|
|
442
|
+
setRooms(all) {
|
|
443
|
+
const rooms = all.filter((r) => {
|
|
444
|
+
const removedAt = this.removed.get(r.roomId);
|
|
445
|
+
return removedAt === void 0 || r.lastMessageAt !== null && Date.parse(r.lastMessageAt) > removedAt;
|
|
446
|
+
});
|
|
417
447
|
this.update({
|
|
418
448
|
rooms,
|
|
419
449
|
requests: rooms.filter((r) => r.myStatus === "pending"),
|
|
@@ -764,6 +794,7 @@ function useChatRooms() {
|
|
|
764
794
|
ignoreDM: inbox.ignoreDM.bind(inbox),
|
|
765
795
|
closeDM: inbox.closeDM.bind(inbox),
|
|
766
796
|
reopenDM: inbox.reopenDM.bind(inbox),
|
|
797
|
+
hideDM: inbox.hideDM.bind(inbox),
|
|
767
798
|
addParticipant: inbox.addParticipant.bind(inbox),
|
|
768
799
|
setMuted: inbox.setMuted.bind(inbox),
|
|
769
800
|
markRead: inbox.markRead.bind(inbox),
|
|
@@ -1100,6 +1131,7 @@ var DEFAULT_LABELS = {
|
|
|
1100
1131
|
conversationClosed: "This conversation is closed",
|
|
1101
1132
|
reopen: "Reopen",
|
|
1102
1133
|
closeConversation: "Close conversation",
|
|
1134
|
+
removeConversation: "Remove from inbox",
|
|
1103
1135
|
mute: "Mute",
|
|
1104
1136
|
unmute: "Unmute",
|
|
1105
1137
|
messagePlaceholder: "Message...",
|
|
@@ -1108,7 +1140,7 @@ var DEFAULT_LABELS = {
|
|
|
1108
1140
|
function badgeText(count) {
|
|
1109
1141
|
return count > 99 ? "99+" : String(count);
|
|
1110
1142
|
}
|
|
1111
|
-
function MessagesInbox({ rooms, requests, labels, onOpenRoom }) {
|
|
1143
|
+
function MessagesInbox({ rooms, requests, labels, onOpenRoom, onRemoveRoom }) {
|
|
1112
1144
|
const conversations = rooms.filter((r) => r.myStatus === "accepted");
|
|
1113
1145
|
if (rooms.length === 0) return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: labels.noMessages });
|
|
1114
1146
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-inbox", children: [
|
|
@@ -1116,19 +1148,46 @@ function MessagesInbox({ rooms, requests, labels, onOpenRoom }) {
|
|
|
1116
1148
|
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "dtc-inbox-heading", children: labels.requests }),
|
|
1117
1149
|
requests.map((room) => /* @__PURE__ */ jsxRuntime.jsx(InboxRow, { room, onOpen: onOpenRoom }, room.roomId))
|
|
1118
1150
|
] }),
|
|
1119
|
-
conversations.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("section", { className: "dtc-inbox-section", children: conversations.map((room) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1151
|
+
conversations.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("section", { className: "dtc-inbox-section", children: conversations.map((room) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1152
|
+
InboxRow,
|
|
1153
|
+
{
|
|
1154
|
+
room,
|
|
1155
|
+
onOpen: onOpenRoom,
|
|
1156
|
+
onRemove: onRemoveRoom,
|
|
1157
|
+
removeLabel: labels.removeConversation
|
|
1158
|
+
},
|
|
1159
|
+
room.roomId
|
|
1160
|
+
)) })
|
|
1120
1161
|
] });
|
|
1121
1162
|
}
|
|
1122
|
-
function InboxRow({
|
|
1163
|
+
function InboxRow({
|
|
1164
|
+
room,
|
|
1165
|
+
onOpen,
|
|
1166
|
+
onRemove,
|
|
1167
|
+
removeLabel
|
|
1168
|
+
}) {
|
|
1123
1169
|
const unread = room.unreadCount > 0 && !room.isMuted;
|
|
1124
1170
|
const lead = room.participants[0];
|
|
1125
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("
|
|
1126
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1127
|
-
|
|
1128
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1129
|
-
|
|
1171
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `dtc-inbox-item ${unread ? "dtc-inbox-row-unread" : ""}`, children: [
|
|
1172
|
+
/* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "dtc-inbox-row", onClick: () => onOpen(room.roomId), children: [
|
|
1173
|
+
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? lead?.avatarUrl : null, size: 40 }),
|
|
1174
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-inbox-text", children: [
|
|
1175
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-inbox-name", children: room.name }),
|
|
1176
|
+
room.lastMessage && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-inbox-preview", children: room.lastMessage.text })
|
|
1177
|
+
] }),
|
|
1178
|
+
unread && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count", children: badgeText(room.unreadCount) })
|
|
1130
1179
|
] }),
|
|
1131
|
-
|
|
1180
|
+
onRemove && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1181
|
+
"button",
|
|
1182
|
+
{
|
|
1183
|
+
type: "button",
|
|
1184
|
+
className: "dtc-inbox-remove",
|
|
1185
|
+
onClick: () => onRemove(room.roomId),
|
|
1186
|
+
"aria-label": `${removeLabel ?? "Remove"}: ${room.name}`,
|
|
1187
|
+
title: removeLabel,
|
|
1188
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6l12 12" }) })
|
|
1189
|
+
}
|
|
1190
|
+
)
|
|
1132
1191
|
] });
|
|
1133
1192
|
}
|
|
1134
1193
|
function ConversationView({ roomId, labels, onBack }) {
|
|
@@ -1194,9 +1253,11 @@ var RAIL_WIDTH = 64;
|
|
|
1194
1253
|
var EDGE_SWIPE_ZONE = 24;
|
|
1195
1254
|
var SWIPE_DISTANCE = 60;
|
|
1196
1255
|
function DialtribeMessages({
|
|
1256
|
+
side = "right",
|
|
1197
1257
|
placement = "push",
|
|
1198
1258
|
openPlacement = "push",
|
|
1199
1259
|
items = [],
|
|
1260
|
+
inboxRowClose = true,
|
|
1200
1261
|
contexts = [],
|
|
1201
1262
|
theme,
|
|
1202
1263
|
labels: labelOverrides,
|
|
@@ -1218,10 +1279,11 @@ function DialtribeMessages({
|
|
|
1218
1279
|
const activeItem = items.find((i) => i.id === activeItemId);
|
|
1219
1280
|
const topItems = items.filter((i) => (i.placement ?? "top") === "top");
|
|
1220
1281
|
const bottomItems = items.filter((i) => i.placement === "bottom");
|
|
1282
|
+
const footerItems = items.filter((i) => i.placement === "footer");
|
|
1221
1283
|
const panelInset = isOpen && openPlacement === "push" ? panelWidth : 0;
|
|
1222
|
-
usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + panelInset);
|
|
1284
|
+
usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + panelInset, side);
|
|
1223
1285
|
useScrollLock(isMobile && isOpen);
|
|
1224
|
-
useEdgeSwipe(isMobile, isOpen, ui.open, ui.close);
|
|
1286
|
+
useEdgeSwipe(isMobile, isOpen, ui.open, ui.close, side);
|
|
1225
1287
|
react.useEffect(() => {
|
|
1226
1288
|
if (!isOpen) return;
|
|
1227
1289
|
const onKey = (e) => e.key === "Escape" && ui.close();
|
|
@@ -1255,6 +1317,7 @@ function DialtribeMessages({
|
|
|
1255
1317
|
"div",
|
|
1256
1318
|
{
|
|
1257
1319
|
className: `dtc-rail-root ${isMobile ? "dtc-rail-root-mobile" : ""} ${isOpen ? "dtc-rail-root-open" : ""}`,
|
|
1320
|
+
"data-side": side,
|
|
1258
1321
|
style,
|
|
1259
1322
|
children: [
|
|
1260
1323
|
isMobile && !isOpen && /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "dtc-messages-fab", onClick: ui.openInbox, "aria-label": labels.openMessages, children: [
|
|
@@ -1266,7 +1329,17 @@ function DialtribeMessages({
|
|
|
1266
1329
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
|
|
1267
1330
|
/* @__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, {}) })
|
|
1268
1331
|
] }),
|
|
1269
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1332
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1333
|
+
MessagesInbox,
|
|
1334
|
+
{
|
|
1335
|
+
rooms: inbox.rooms,
|
|
1336
|
+
requests: inbox.requests,
|
|
1337
|
+
labels,
|
|
1338
|
+
onOpenRoom: ui.openRoom,
|
|
1339
|
+
onRemoveRoom: inboxRowClose ? (roomId) => void inbox.hideDM(roomId).catch(() => {
|
|
1340
|
+
}) : void 0
|
|
1341
|
+
}
|
|
1342
|
+
)
|
|
1270
1343
|
] }) : activeContext ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
|
|
1271
1344
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1272
1345
|
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
|
|
@@ -1276,44 +1349,47 @@ function DialtribeMessages({
|
|
|
1276
1349
|
/* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
|
|
1277
1350
|
] }) : /* @__PURE__ */ jsxRuntime.jsx(ConversationView, { roomId: view.roomId, labels, onBack: ui.openInbox }, view.roomId) }),
|
|
1278
1351
|
showRail && /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "dtc-rail", "aria-label": labels.messages, children: [
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1352
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-rail-scroll", children: [
|
|
1353
|
+
topItems.map(renderItemButton),
|
|
1354
|
+
topItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
|
|
1355
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1356
|
+
RailButton,
|
|
1357
|
+
{
|
|
1358
|
+
label: labels.messages,
|
|
1359
|
+
active: isOpen && view.kind === "inbox",
|
|
1360
|
+
badge: rollup,
|
|
1361
|
+
onClick: () => select({ kind: "inbox" }),
|
|
1362
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {})
|
|
1363
|
+
}
|
|
1364
|
+
),
|
|
1365
|
+
contexts.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
|
|
1366
|
+
contexts.map((c) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1367
|
+
RailButton,
|
|
1368
|
+
{
|
|
1369
|
+
label: c.label,
|
|
1370
|
+
active: activeRoomId === c.roomId,
|
|
1371
|
+
badge: c.badge ?? 0,
|
|
1372
|
+
onClick: () => select({ kind: "room", roomId: c.roomId }),
|
|
1373
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: c.label, url: c.avatarUrl, size: 36 })
|
|
1374
|
+
},
|
|
1375
|
+
c.roomId
|
|
1376
|
+
)),
|
|
1377
|
+
recentDms.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
|
|
1378
|
+
recentDms.map((room) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1379
|
+
RailButton,
|
|
1380
|
+
{
|
|
1381
|
+
label: room.name,
|
|
1382
|
+
active: activeRoomId === room.roomId,
|
|
1383
|
+
badge: room.isMuted ? 0 : room.unreadCount,
|
|
1384
|
+
onClick: () => select({ kind: "room", roomId: room.roomId }),
|
|
1385
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 36 })
|
|
1386
|
+
},
|
|
1387
|
+
room.roomId
|
|
1388
|
+
)),
|
|
1389
|
+
bottomItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
|
|
1390
|
+
bottomItems.map(renderItemButton)
|
|
1391
|
+
] }),
|
|
1392
|
+
footerItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-rail-footer", children: footerItems.map(renderItemButton) })
|
|
1317
1393
|
] })
|
|
1318
1394
|
]
|
|
1319
1395
|
}
|
|
@@ -1353,37 +1429,25 @@ function useMediaQuery(query) {
|
|
|
1353
1429
|
}, [query]);
|
|
1354
1430
|
return matches;
|
|
1355
1431
|
}
|
|
1356
|
-
function usePushLayout(enabled, inset) {
|
|
1357
|
-
const original = react.useRef(null);
|
|
1432
|
+
function usePushLayout(enabled, inset, side) {
|
|
1358
1433
|
react.useEffect(() => {
|
|
1359
|
-
const root = document.documentElement;
|
|
1360
1434
|
if (!enabled) return;
|
|
1361
|
-
original.current ?? (original.current = { padding: root.style.paddingRight, transition: root.style.transition });
|
|
1362
|
-
root.style.transition = "padding-right 250ms ease-out";
|
|
1363
|
-
root.style.paddingRight = `${inset}px`;
|
|
1364
|
-
root.style.setProperty("--dtc-messages-inset", `${inset}px`);
|
|
1365
|
-
}, [enabled, inset]);
|
|
1366
|
-
react.useEffect(() => {
|
|
1367
|
-
if (enabled) return;
|
|
1368
1435
|
const root = document.documentElement;
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
}
|
|
1374
|
-
root.style.
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
if (original.current) {
|
|
1380
|
-
root.style.paddingRight = original.current.padding;
|
|
1381
|
-
root.style.transition = original.current.transition;
|
|
1382
|
-
}
|
|
1436
|
+
const prop = side === "left" ? "paddingLeft" : "paddingRight";
|
|
1437
|
+
const original = { padding: root.style[prop], transition: root.style.transition };
|
|
1438
|
+
root.style.transition = `${side === "left" ? "padding-left" : "padding-right"} 250ms ease-out`;
|
|
1439
|
+
root.style[prop] = `${inset}px`;
|
|
1440
|
+
root.style.setProperty("--dtc-messages-inset", `${inset}px`);
|
|
1441
|
+
root.style.setProperty("--dtc-messages-side", side);
|
|
1442
|
+
root.dataset.dtcMessagesSide = side;
|
|
1443
|
+
return () => {
|
|
1444
|
+
root.style[prop] = original.padding;
|
|
1445
|
+
root.style.transition = original.transition;
|
|
1383
1446
|
root.style.removeProperty("--dtc-messages-inset");
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1447
|
+
root.style.removeProperty("--dtc-messages-side");
|
|
1448
|
+
delete root.dataset.dtcMessagesSide;
|
|
1449
|
+
};
|
|
1450
|
+
}, [enabled, inset, side]);
|
|
1387
1451
|
}
|
|
1388
1452
|
function useScrollLock(locked) {
|
|
1389
1453
|
react.useEffect(() => {
|
|
@@ -1395,14 +1459,15 @@ function useScrollLock(locked) {
|
|
|
1395
1459
|
};
|
|
1396
1460
|
}, [locked]);
|
|
1397
1461
|
}
|
|
1398
|
-
function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
1462
|
+
function useEdgeSwipe(enabled, isOpen, open, close, side) {
|
|
1399
1463
|
react.useEffect(() => {
|
|
1400
1464
|
if (!enabled) return;
|
|
1401
1465
|
let start = null;
|
|
1402
1466
|
const onStart = (e) => {
|
|
1403
1467
|
const t = e.touches[0];
|
|
1404
1468
|
if (!t) return;
|
|
1405
|
-
|
|
1469
|
+
const atEdge = side === "left" ? t.clientX <= EDGE_SWIPE_ZONE : t.clientX >= window.innerWidth - EDGE_SWIPE_ZONE;
|
|
1470
|
+
if (isOpen || atEdge) start = { x: t.clientX, y: t.clientY };
|
|
1406
1471
|
};
|
|
1407
1472
|
const onEnd = (e) => {
|
|
1408
1473
|
const t = e.changedTouches[0];
|
|
@@ -1411,8 +1476,9 @@ function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
|
1411
1476
|
const dy = Math.abs(t.clientY - start.y);
|
|
1412
1477
|
start = null;
|
|
1413
1478
|
if (Math.abs(dx) < SWIPE_DISTANCE || dy > Math.abs(dx)) return;
|
|
1414
|
-
|
|
1415
|
-
|
|
1479
|
+
const inward = side === "left" ? dx > 0 : dx < 0;
|
|
1480
|
+
if (!isOpen && inward) open();
|
|
1481
|
+
else if (isOpen && !inward) close();
|
|
1416
1482
|
};
|
|
1417
1483
|
window.addEventListener("touchstart", onStart, { passive: true });
|
|
1418
1484
|
window.addEventListener("touchend", onEnd, { passive: true });
|
|
@@ -1420,7 +1486,7 @@ function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
|
1420
1486
|
window.removeEventListener("touchstart", onStart);
|
|
1421
1487
|
window.removeEventListener("touchend", onEnd);
|
|
1422
1488
|
};
|
|
1423
|
-
}, [enabled, isOpen, open, close]);
|
|
1489
|
+
}, [enabled, isOpen, open, close, side]);
|
|
1424
1490
|
}
|
|
1425
1491
|
function themeVars(theme) {
|
|
1426
1492
|
if (!theme) return {};
|