@dialtribe/chat-client 0.1.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 +43 -7
- package/dist/index.d.mts +63 -6
- package/dist/index.d.ts +63 -6
- package/dist/index.js +179 -83
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +179 -83
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
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"),
|
|
@@ -676,6 +706,9 @@ var MessagesUiStore = class extends Store {
|
|
|
676
706
|
openRoom(roomId) {
|
|
677
707
|
this.update({ open: true, view: { kind: "room", roomId } });
|
|
678
708
|
}
|
|
709
|
+
openItem(itemId) {
|
|
710
|
+
this.update({ open: true, view: { kind: "item", itemId } });
|
|
711
|
+
}
|
|
679
712
|
};
|
|
680
713
|
var ClientContext = react.createContext(null);
|
|
681
714
|
var MessagesUiContext = react.createContext(null);
|
|
@@ -761,6 +794,7 @@ function useChatRooms() {
|
|
|
761
794
|
ignoreDM: inbox.ignoreDM.bind(inbox),
|
|
762
795
|
closeDM: inbox.closeDM.bind(inbox),
|
|
763
796
|
reopenDM: inbox.reopenDM.bind(inbox),
|
|
797
|
+
hideDM: inbox.hideDM.bind(inbox),
|
|
764
798
|
addParticipant: inbox.addParticipant.bind(inbox),
|
|
765
799
|
setMuted: inbox.setMuted.bind(inbox),
|
|
766
800
|
markRead: inbox.markRead.bind(inbox),
|
|
@@ -786,6 +820,7 @@ function useDialtribeMessages() {
|
|
|
786
820
|
toggle: () => ui.toggle(),
|
|
787
821
|
openInbox: () => ui.openInbox(),
|
|
788
822
|
openRoom: (roomId) => ui.openRoom(roomId),
|
|
823
|
+
openItem: (itemId) => ui.openItem(itemId),
|
|
789
824
|
messageUser: async (userId, hint) => {
|
|
790
825
|
const result = await client.inbox.requestDM(userId, hint);
|
|
791
826
|
ui.openRoom(result.roomId);
|
|
@@ -1096,6 +1131,7 @@ var DEFAULT_LABELS = {
|
|
|
1096
1131
|
conversationClosed: "This conversation is closed",
|
|
1097
1132
|
reopen: "Reopen",
|
|
1098
1133
|
closeConversation: "Close conversation",
|
|
1134
|
+
removeConversation: "Remove from inbox",
|
|
1099
1135
|
mute: "Mute",
|
|
1100
1136
|
unmute: "Unmute",
|
|
1101
1137
|
messagePlaceholder: "Message...",
|
|
@@ -1104,7 +1140,7 @@ var DEFAULT_LABELS = {
|
|
|
1104
1140
|
function badgeText(count) {
|
|
1105
1141
|
return count > 99 ? "99+" : String(count);
|
|
1106
1142
|
}
|
|
1107
|
-
function MessagesInbox({ rooms, requests, labels, onOpenRoom }) {
|
|
1143
|
+
function MessagesInbox({ rooms, requests, labels, onOpenRoom, onRemoveRoom }) {
|
|
1108
1144
|
const conversations = rooms.filter((r) => r.myStatus === "accepted");
|
|
1109
1145
|
if (rooms.length === 0) return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: labels.noMessages });
|
|
1110
1146
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-inbox", children: [
|
|
@@ -1112,19 +1148,46 @@ function MessagesInbox({ rooms, requests, labels, onOpenRoom }) {
|
|
|
1112
1148
|
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "dtc-inbox-heading", children: labels.requests }),
|
|
1113
1149
|
requests.map((room) => /* @__PURE__ */ jsxRuntime.jsx(InboxRow, { room, onOpen: onOpenRoom }, room.roomId))
|
|
1114
1150
|
] }),
|
|
1115
|
-
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
|
+
)) })
|
|
1116
1161
|
] });
|
|
1117
1162
|
}
|
|
1118
|
-
function InboxRow({
|
|
1163
|
+
function InboxRow({
|
|
1164
|
+
room,
|
|
1165
|
+
onOpen,
|
|
1166
|
+
onRemove,
|
|
1167
|
+
removeLabel
|
|
1168
|
+
}) {
|
|
1119
1169
|
const unread = room.unreadCount > 0 && !room.isMuted;
|
|
1120
1170
|
const lead = room.participants[0];
|
|
1121
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("
|
|
1122
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1123
|
-
|
|
1124
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1125
|
-
|
|
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) })
|
|
1126
1179
|
] }),
|
|
1127
|
-
|
|
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
|
+
)
|
|
1128
1191
|
] });
|
|
1129
1192
|
}
|
|
1130
1193
|
function ConversationView({ roomId, labels, onBack }) {
|
|
@@ -1190,7 +1253,11 @@ var RAIL_WIDTH = 64;
|
|
|
1190
1253
|
var EDGE_SWIPE_ZONE = 24;
|
|
1191
1254
|
var SWIPE_DISTANCE = 60;
|
|
1192
1255
|
function DialtribeMessages({
|
|
1256
|
+
side = "right",
|
|
1193
1257
|
placement = "push",
|
|
1258
|
+
openPlacement = "push",
|
|
1259
|
+
items = [],
|
|
1260
|
+
inboxRowClose = true,
|
|
1194
1261
|
contexts = [],
|
|
1195
1262
|
theme,
|
|
1196
1263
|
labels: labelOverrides,
|
|
@@ -1208,9 +1275,15 @@ function DialtribeMessages({
|
|
|
1208
1275
|
const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted").slice(0, railDmLimit);
|
|
1209
1276
|
const activeRoomId = isOpen && view.kind === "room" ? view.roomId : null;
|
|
1210
1277
|
const activeContext = contexts.find((c) => c.roomId === activeRoomId);
|
|
1211
|
-
|
|
1278
|
+
const activeItemId = isOpen && view.kind === "item" ? view.itemId : null;
|
|
1279
|
+
const activeItem = items.find((i) => i.id === activeItemId);
|
|
1280
|
+
const topItems = items.filter((i) => (i.placement ?? "top") === "top");
|
|
1281
|
+
const bottomItems = items.filter((i) => i.placement === "bottom");
|
|
1282
|
+
const footerItems = items.filter((i) => i.placement === "footer");
|
|
1283
|
+
const panelInset = isOpen && openPlacement === "push" ? panelWidth : 0;
|
|
1284
|
+
usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + panelInset, side);
|
|
1212
1285
|
useScrollLock(isMobile && isOpen);
|
|
1213
|
-
useEdgeSwipe(isMobile, isOpen, ui.open, ui.close);
|
|
1286
|
+
useEdgeSwipe(isMobile, isOpen, ui.open, ui.close, side);
|
|
1214
1287
|
react.useEffect(() => {
|
|
1215
1288
|
if (!isOpen) return;
|
|
1216
1289
|
const onKey = (e) => e.key === "Escape" && ui.close();
|
|
@@ -1218,10 +1291,25 @@ function DialtribeMessages({
|
|
|
1218
1291
|
return () => window.removeEventListener("keydown", onKey);
|
|
1219
1292
|
}, [isOpen, ui]);
|
|
1220
1293
|
const select = (target) => {
|
|
1221
|
-
const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : activeRoomId === target.roomId);
|
|
1294
|
+
const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : activeItemId === target.itemId);
|
|
1222
1295
|
if (showing) ui.close();
|
|
1223
1296
|
else if (target.kind === "inbox") ui.openInbox();
|
|
1224
|
-
else ui.openRoom(target.roomId);
|
|
1297
|
+
else if (target.kind === "room") ui.openRoom(target.roomId);
|
|
1298
|
+
else ui.openItem(target.itemId);
|
|
1299
|
+
};
|
|
1300
|
+
const renderItemButton = (item) => {
|
|
1301
|
+
const active = activeItemId === item.id;
|
|
1302
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1303
|
+
RailButton,
|
|
1304
|
+
{
|
|
1305
|
+
label: item.label ?? item.id,
|
|
1306
|
+
active,
|
|
1307
|
+
badge: item.badge ?? 0,
|
|
1308
|
+
onClick: () => select({ kind: "item", itemId: item.id }),
|
|
1309
|
+
children: typeof item.trigger === "function" ? item.trigger({ active }) : item.trigger
|
|
1310
|
+
},
|
|
1311
|
+
item.id
|
|
1312
|
+
);
|
|
1225
1313
|
};
|
|
1226
1314
|
const style = { ...themeVars(theme), "--dtc-panel-width": `${panelWidth}px`, "--dtc-rail-width": `${RAIL_WIDTH}px` };
|
|
1227
1315
|
const showRail = !isMobile || isOpen;
|
|
@@ -1229,18 +1317,29 @@ function DialtribeMessages({
|
|
|
1229
1317
|
"div",
|
|
1230
1318
|
{
|
|
1231
1319
|
className: `dtc-rail-root ${isMobile ? "dtc-rail-root-mobile" : ""} ${isOpen ? "dtc-rail-root-open" : ""}`,
|
|
1320
|
+
"data-side": side,
|
|
1232
1321
|
style,
|
|
1233
1322
|
children: [
|
|
1234
1323
|
isMobile && !isOpen && /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "dtc-messages-fab", onClick: ui.openInbox, "aria-label": labels.openMessages, children: [
|
|
1235
1324
|
/* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {}),
|
|
1236
1325
|
rollup > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
|
|
1237
1326
|
] }),
|
|
1238
|
-
isOpen && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": labels.messages, children: view.kind
|
|
1327
|
+
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
1328
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
|
|
1240
1329
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
|
|
1241
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, {}) })
|
|
1242
1331
|
] }),
|
|
1243
|
-
/* @__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
|
+
)
|
|
1244
1343
|
] }) : activeContext ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
|
|
1245
1344
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1246
1345
|
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
|
|
@@ -1250,40 +1349,47 @@ function DialtribeMessages({
|
|
|
1250
1349
|
/* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
|
|
1251
1350
|
] }) : /* @__PURE__ */ jsxRuntime.jsx(ConversationView, { roomId: view.roomId, labels, onBack: ui.openInbox }, view.roomId) }),
|
|
1252
1351
|
showRail && /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "dtc-rail", "aria-label": labels.messages, children: [
|
|
1253
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1254
|
-
|
|
1255
|
-
{
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
{
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
{
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
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) })
|
|
1287
1393
|
] })
|
|
1288
1394
|
]
|
|
1289
1395
|
}
|
|
@@ -1323,37 +1429,25 @@ function useMediaQuery(query) {
|
|
|
1323
1429
|
}, [query]);
|
|
1324
1430
|
return matches;
|
|
1325
1431
|
}
|
|
1326
|
-
function usePushLayout(enabled, inset) {
|
|
1327
|
-
const original = react.useRef(null);
|
|
1432
|
+
function usePushLayout(enabled, inset, side) {
|
|
1328
1433
|
react.useEffect(() => {
|
|
1329
|
-
const root = document.documentElement;
|
|
1330
1434
|
if (!enabled) return;
|
|
1331
|
-
original.current ?? (original.current = { padding: root.style.paddingRight, transition: root.style.transition });
|
|
1332
|
-
root.style.transition = "padding-right 250ms ease-out";
|
|
1333
|
-
root.style.paddingRight = `${inset}px`;
|
|
1334
|
-
root.style.setProperty("--dtc-messages-inset", `${inset}px`);
|
|
1335
|
-
}, [enabled, inset]);
|
|
1336
|
-
react.useEffect(() => {
|
|
1337
|
-
if (enabled) return;
|
|
1338
1435
|
const root = document.documentElement;
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
}
|
|
1344
|
-
root.style.
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
if (original.current) {
|
|
1350
|
-
root.style.paddingRight = original.current.padding;
|
|
1351
|
-
root.style.transition = original.current.transition;
|
|
1352
|
-
}
|
|
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;
|
|
1353
1446
|
root.style.removeProperty("--dtc-messages-inset");
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1447
|
+
root.style.removeProperty("--dtc-messages-side");
|
|
1448
|
+
delete root.dataset.dtcMessagesSide;
|
|
1449
|
+
};
|
|
1450
|
+
}, [enabled, inset, side]);
|
|
1357
1451
|
}
|
|
1358
1452
|
function useScrollLock(locked) {
|
|
1359
1453
|
react.useEffect(() => {
|
|
@@ -1365,14 +1459,15 @@ function useScrollLock(locked) {
|
|
|
1365
1459
|
};
|
|
1366
1460
|
}, [locked]);
|
|
1367
1461
|
}
|
|
1368
|
-
function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
1462
|
+
function useEdgeSwipe(enabled, isOpen, open, close, side) {
|
|
1369
1463
|
react.useEffect(() => {
|
|
1370
1464
|
if (!enabled) return;
|
|
1371
1465
|
let start = null;
|
|
1372
1466
|
const onStart = (e) => {
|
|
1373
1467
|
const t = e.touches[0];
|
|
1374
1468
|
if (!t) return;
|
|
1375
|
-
|
|
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 };
|
|
1376
1471
|
};
|
|
1377
1472
|
const onEnd = (e) => {
|
|
1378
1473
|
const t = e.changedTouches[0];
|
|
@@ -1381,8 +1476,9 @@ function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
|
1381
1476
|
const dy = Math.abs(t.clientY - start.y);
|
|
1382
1477
|
start = null;
|
|
1383
1478
|
if (Math.abs(dx) < SWIPE_DISTANCE || dy > Math.abs(dx)) return;
|
|
1384
|
-
|
|
1385
|
-
|
|
1479
|
+
const inward = side === "left" ? dx > 0 : dx < 0;
|
|
1480
|
+
if (!isOpen && inward) open();
|
|
1481
|
+
else if (isOpen && !inward) close();
|
|
1386
1482
|
};
|
|
1387
1483
|
window.addEventListener("touchstart", onStart, { passive: true });
|
|
1388
1484
|
window.addEventListener("touchend", onEnd, { passive: true });
|
|
@@ -1390,7 +1486,7 @@ function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
|
1390
1486
|
window.removeEventListener("touchstart", onStart);
|
|
1391
1487
|
window.removeEventListener("touchend", onEnd);
|
|
1392
1488
|
};
|
|
1393
|
-
}, [enabled, isOpen, open, close]);
|
|
1489
|
+
}, [enabled, isOpen, open, close, side]);
|
|
1394
1490
|
}
|
|
1395
1491
|
function themeVars(theme) {
|
|
1396
1492
|
if (!theme) return {};
|