@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.mjs
CHANGED
|
@@ -239,6 +239,12 @@ var InboxStore = class extends Store {
|
|
|
239
239
|
this.readTimers = /* @__PURE__ */ new Map();
|
|
240
240
|
/** Rooms currently on screen: activity there is read, not unread. */
|
|
241
241
|
this.visible = /* @__PURE__ */ new Map();
|
|
242
|
+
/**
|
|
243
|
+
* Rooms the user removed (hide/ignore) and when. Filtered out of every list,
|
|
244
|
+
* so a refresh already in flight can't put them back, until a newer message
|
|
245
|
+
* arrives or the user messages/reopens/accepts them.
|
|
246
|
+
*/
|
|
247
|
+
this.removed = /* @__PURE__ */ new Map();
|
|
242
248
|
}
|
|
243
249
|
acquire() {
|
|
244
250
|
this.refs += 1;
|
|
@@ -269,11 +275,13 @@ var InboxStore = class extends Store {
|
|
|
269
275
|
targetAvatarUrl: hint?.avatarUrl,
|
|
270
276
|
showRequestId: hint?.showRequestId
|
|
271
277
|
});
|
|
278
|
+
this.removed.delete(result.roomId);
|
|
272
279
|
await this.refresh();
|
|
273
280
|
return { status: result.status, roomId: result.roomId };
|
|
274
281
|
}
|
|
275
282
|
async acceptDM(requestId) {
|
|
276
283
|
const { roomId } = await this.client.dm("chat-dm-accept", { requestId });
|
|
284
|
+
this.removed.delete(roomId);
|
|
277
285
|
await this.refresh();
|
|
278
286
|
return roomId;
|
|
279
287
|
}
|
|
@@ -287,6 +295,7 @@ var InboxStore = class extends Store {
|
|
|
287
295
|
}
|
|
288
296
|
async reopenDM(roomId) {
|
|
289
297
|
await this.client.dm("chat-dm-reopen", { roomId });
|
|
298
|
+
this.removed.delete(roomId);
|
|
290
299
|
await this.refresh();
|
|
291
300
|
}
|
|
292
301
|
/** Add someone. Returns the room to show (a new group when added to a 1:1). */
|
|
@@ -300,6 +309,21 @@ var InboxStore = class extends Store {
|
|
|
300
309
|
await this.refresh();
|
|
301
310
|
return result.roomId;
|
|
302
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Remove a conversation from the user's own inbox (optimistic). Not deleted
|
|
314
|
+
* and nobody else is affected: it comes back when a newer message arrives or
|
|
315
|
+
* when the user messages/reopens it.
|
|
316
|
+
*/
|
|
317
|
+
async hideDM(roomId) {
|
|
318
|
+
this.removeLocally(roomId);
|
|
319
|
+
try {
|
|
320
|
+
await this.client.dm("chat-dm-hide", { roomId });
|
|
321
|
+
} catch (err) {
|
|
322
|
+
this.removed.delete(roomId);
|
|
323
|
+
await this.refresh();
|
|
324
|
+
throw err;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
303
327
|
async setMuted(roomId, muted) {
|
|
304
328
|
this.patchRoom(roomId, (room) => ({ ...room, isMuted: muted }));
|
|
305
329
|
await this.client.dm("chat-dm-mute", { roomId, muted });
|
|
@@ -352,6 +376,7 @@ var InboxStore = class extends Store {
|
|
|
352
376
|
}
|
|
353
377
|
}
|
|
354
378
|
onActivity(roomId, message) {
|
|
379
|
+
this.removed.delete(roomId);
|
|
355
380
|
const known = this.getSnapshot().rooms.some((r) => r.roomId === roomId);
|
|
356
381
|
if (!known) {
|
|
357
382
|
this.scheduleRefresh(REFRESH_DEBOUNCE_MS);
|
|
@@ -409,9 +434,14 @@ var InboxStore = class extends Store {
|
|
|
409
434
|
this.setRooms(moveToTop ? [next, ...rest] : rooms.map((r, i) => i === index ? next : r));
|
|
410
435
|
}
|
|
411
436
|
removeLocally(roomId) {
|
|
412
|
-
this.
|
|
437
|
+
this.removed.set(roomId, Date.now());
|
|
438
|
+
this.setRooms(this.getSnapshot().rooms);
|
|
413
439
|
}
|
|
414
|
-
setRooms(
|
|
440
|
+
setRooms(all) {
|
|
441
|
+
const rooms = all.filter((r) => {
|
|
442
|
+
const removedAt = this.removed.get(r.roomId);
|
|
443
|
+
return removedAt === void 0 || r.lastMessageAt !== null && Date.parse(r.lastMessageAt) > removedAt;
|
|
444
|
+
});
|
|
415
445
|
this.update({
|
|
416
446
|
rooms,
|
|
417
447
|
requests: rooms.filter((r) => r.myStatus === "pending"),
|
|
@@ -674,6 +704,9 @@ var MessagesUiStore = class extends Store {
|
|
|
674
704
|
openRoom(roomId) {
|
|
675
705
|
this.update({ open: true, view: { kind: "room", roomId } });
|
|
676
706
|
}
|
|
707
|
+
openItem(itemId) {
|
|
708
|
+
this.update({ open: true, view: { kind: "item", itemId } });
|
|
709
|
+
}
|
|
677
710
|
};
|
|
678
711
|
var ClientContext = createContext(null);
|
|
679
712
|
var MessagesUiContext = createContext(null);
|
|
@@ -759,6 +792,7 @@ function useChatRooms() {
|
|
|
759
792
|
ignoreDM: inbox.ignoreDM.bind(inbox),
|
|
760
793
|
closeDM: inbox.closeDM.bind(inbox),
|
|
761
794
|
reopenDM: inbox.reopenDM.bind(inbox),
|
|
795
|
+
hideDM: inbox.hideDM.bind(inbox),
|
|
762
796
|
addParticipant: inbox.addParticipant.bind(inbox),
|
|
763
797
|
setMuted: inbox.setMuted.bind(inbox),
|
|
764
798
|
markRead: inbox.markRead.bind(inbox),
|
|
@@ -784,6 +818,7 @@ function useDialtribeMessages() {
|
|
|
784
818
|
toggle: () => ui.toggle(),
|
|
785
819
|
openInbox: () => ui.openInbox(),
|
|
786
820
|
openRoom: (roomId) => ui.openRoom(roomId),
|
|
821
|
+
openItem: (itemId) => ui.openItem(itemId),
|
|
787
822
|
messageUser: async (userId, hint) => {
|
|
788
823
|
const result = await client.inbox.requestDM(userId, hint);
|
|
789
824
|
ui.openRoom(result.roomId);
|
|
@@ -1094,6 +1129,7 @@ var DEFAULT_LABELS = {
|
|
|
1094
1129
|
conversationClosed: "This conversation is closed",
|
|
1095
1130
|
reopen: "Reopen",
|
|
1096
1131
|
closeConversation: "Close conversation",
|
|
1132
|
+
removeConversation: "Remove from inbox",
|
|
1097
1133
|
mute: "Mute",
|
|
1098
1134
|
unmute: "Unmute",
|
|
1099
1135
|
messagePlaceholder: "Message...",
|
|
@@ -1102,7 +1138,7 @@ var DEFAULT_LABELS = {
|
|
|
1102
1138
|
function badgeText(count) {
|
|
1103
1139
|
return count > 99 ? "99+" : String(count);
|
|
1104
1140
|
}
|
|
1105
|
-
function MessagesInbox({ rooms, requests, labels, onOpenRoom }) {
|
|
1141
|
+
function MessagesInbox({ rooms, requests, labels, onOpenRoom, onRemoveRoom }) {
|
|
1106
1142
|
const conversations = rooms.filter((r) => r.myStatus === "accepted");
|
|
1107
1143
|
if (rooms.length === 0) return /* @__PURE__ */ jsx("div", { className: "dtc-empty", children: labels.noMessages });
|
|
1108
1144
|
return /* @__PURE__ */ jsxs("div", { className: "dtc-inbox", children: [
|
|
@@ -1110,19 +1146,46 @@ function MessagesInbox({ rooms, requests, labels, onOpenRoom }) {
|
|
|
1110
1146
|
/* @__PURE__ */ jsx("h3", { className: "dtc-inbox-heading", children: labels.requests }),
|
|
1111
1147
|
requests.map((room) => /* @__PURE__ */ jsx(InboxRow, { room, onOpen: onOpenRoom }, room.roomId))
|
|
1112
1148
|
] }),
|
|
1113
|
-
conversations.length > 0 && /* @__PURE__ */ jsx("section", { className: "dtc-inbox-section", children: conversations.map((room) => /* @__PURE__ */ jsx(
|
|
1149
|
+
conversations.length > 0 && /* @__PURE__ */ jsx("section", { className: "dtc-inbox-section", children: conversations.map((room) => /* @__PURE__ */ jsx(
|
|
1150
|
+
InboxRow,
|
|
1151
|
+
{
|
|
1152
|
+
room,
|
|
1153
|
+
onOpen: onOpenRoom,
|
|
1154
|
+
onRemove: onRemoveRoom,
|
|
1155
|
+
removeLabel: labels.removeConversation
|
|
1156
|
+
},
|
|
1157
|
+
room.roomId
|
|
1158
|
+
)) })
|
|
1114
1159
|
] });
|
|
1115
1160
|
}
|
|
1116
|
-
function InboxRow({
|
|
1161
|
+
function InboxRow({
|
|
1162
|
+
room,
|
|
1163
|
+
onOpen,
|
|
1164
|
+
onRemove,
|
|
1165
|
+
removeLabel
|
|
1166
|
+
}) {
|
|
1117
1167
|
const unread = room.unreadCount > 0 && !room.isMuted;
|
|
1118
1168
|
const lead = room.participants[0];
|
|
1119
|
-
return /* @__PURE__ */ jsxs("
|
|
1120
|
-
/* @__PURE__ */
|
|
1121
|
-
|
|
1122
|
-
/* @__PURE__ */
|
|
1123
|
-
|
|
1169
|
+
return /* @__PURE__ */ jsxs("div", { className: `dtc-inbox-item ${unread ? "dtc-inbox-row-unread" : ""}`, children: [
|
|
1170
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "dtc-inbox-row", onClick: () => onOpen(room.roomId), children: [
|
|
1171
|
+
/* @__PURE__ */ jsx(Avatar, { name: room.name, url: room.kind === "dm" ? lead?.avatarUrl : null, size: 40 }),
|
|
1172
|
+
/* @__PURE__ */ jsxs("span", { className: "dtc-inbox-text", children: [
|
|
1173
|
+
/* @__PURE__ */ jsx("span", { className: "dtc-inbox-name", children: room.name }),
|
|
1174
|
+
room.lastMessage && /* @__PURE__ */ jsx("span", { className: "dtc-inbox-preview", children: room.lastMessage.text })
|
|
1175
|
+
] }),
|
|
1176
|
+
unread && /* @__PURE__ */ jsx("span", { className: "dtc-badge-count", children: badgeText(room.unreadCount) })
|
|
1124
1177
|
] }),
|
|
1125
|
-
|
|
1178
|
+
onRemove && /* @__PURE__ */ jsx(
|
|
1179
|
+
"button",
|
|
1180
|
+
{
|
|
1181
|
+
type: "button",
|
|
1182
|
+
className: "dtc-inbox-remove",
|
|
1183
|
+
onClick: () => onRemove(room.roomId),
|
|
1184
|
+
"aria-label": `${removeLabel ?? "Remove"}: ${room.name}`,
|
|
1185
|
+
title: removeLabel,
|
|
1186
|
+
children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" }) })
|
|
1187
|
+
}
|
|
1188
|
+
)
|
|
1126
1189
|
] });
|
|
1127
1190
|
}
|
|
1128
1191
|
function ConversationView({ roomId, labels, onBack }) {
|
|
@@ -1188,7 +1251,11 @@ var RAIL_WIDTH = 64;
|
|
|
1188
1251
|
var EDGE_SWIPE_ZONE = 24;
|
|
1189
1252
|
var SWIPE_DISTANCE = 60;
|
|
1190
1253
|
function DialtribeMessages({
|
|
1254
|
+
side = "right",
|
|
1191
1255
|
placement = "push",
|
|
1256
|
+
openPlacement = "push",
|
|
1257
|
+
items = [],
|
|
1258
|
+
inboxRowClose = true,
|
|
1192
1259
|
contexts = [],
|
|
1193
1260
|
theme,
|
|
1194
1261
|
labels: labelOverrides,
|
|
@@ -1206,9 +1273,15 @@ function DialtribeMessages({
|
|
|
1206
1273
|
const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted").slice(0, railDmLimit);
|
|
1207
1274
|
const activeRoomId = isOpen && view.kind === "room" ? view.roomId : null;
|
|
1208
1275
|
const activeContext = contexts.find((c) => c.roomId === activeRoomId);
|
|
1209
|
-
|
|
1276
|
+
const activeItemId = isOpen && view.kind === "item" ? view.itemId : null;
|
|
1277
|
+
const activeItem = items.find((i) => i.id === activeItemId);
|
|
1278
|
+
const topItems = items.filter((i) => (i.placement ?? "top") === "top");
|
|
1279
|
+
const bottomItems = items.filter((i) => i.placement === "bottom");
|
|
1280
|
+
const footerItems = items.filter((i) => i.placement === "footer");
|
|
1281
|
+
const panelInset = isOpen && openPlacement === "push" ? panelWidth : 0;
|
|
1282
|
+
usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + panelInset, side);
|
|
1210
1283
|
useScrollLock(isMobile && isOpen);
|
|
1211
|
-
useEdgeSwipe(isMobile, isOpen, ui.open, ui.close);
|
|
1284
|
+
useEdgeSwipe(isMobile, isOpen, ui.open, ui.close, side);
|
|
1212
1285
|
useEffect(() => {
|
|
1213
1286
|
if (!isOpen) return;
|
|
1214
1287
|
const onKey = (e) => e.key === "Escape" && ui.close();
|
|
@@ -1216,10 +1289,25 @@ function DialtribeMessages({
|
|
|
1216
1289
|
return () => window.removeEventListener("keydown", onKey);
|
|
1217
1290
|
}, [isOpen, ui]);
|
|
1218
1291
|
const select = (target) => {
|
|
1219
|
-
const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : activeRoomId === target.roomId);
|
|
1292
|
+
const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : activeItemId === target.itemId);
|
|
1220
1293
|
if (showing) ui.close();
|
|
1221
1294
|
else if (target.kind === "inbox") ui.openInbox();
|
|
1222
|
-
else ui.openRoom(target.roomId);
|
|
1295
|
+
else if (target.kind === "room") ui.openRoom(target.roomId);
|
|
1296
|
+
else ui.openItem(target.itemId);
|
|
1297
|
+
};
|
|
1298
|
+
const renderItemButton = (item) => {
|
|
1299
|
+
const active = activeItemId === item.id;
|
|
1300
|
+
return /* @__PURE__ */ jsx(
|
|
1301
|
+
RailButton,
|
|
1302
|
+
{
|
|
1303
|
+
label: item.label ?? item.id,
|
|
1304
|
+
active,
|
|
1305
|
+
badge: item.badge ?? 0,
|
|
1306
|
+
onClick: () => select({ kind: "item", itemId: item.id }),
|
|
1307
|
+
children: typeof item.trigger === "function" ? item.trigger({ active }) : item.trigger
|
|
1308
|
+
},
|
|
1309
|
+
item.id
|
|
1310
|
+
);
|
|
1223
1311
|
};
|
|
1224
1312
|
const style = { ...themeVars(theme), "--dtc-panel-width": `${panelWidth}px`, "--dtc-rail-width": `${RAIL_WIDTH}px` };
|
|
1225
1313
|
const showRail = !isMobile || isOpen;
|
|
@@ -1227,18 +1315,29 @@ function DialtribeMessages({
|
|
|
1227
1315
|
"div",
|
|
1228
1316
|
{
|
|
1229
1317
|
className: `dtc-rail-root ${isMobile ? "dtc-rail-root-mobile" : ""} ${isOpen ? "dtc-rail-root-open" : ""}`,
|
|
1318
|
+
"data-side": side,
|
|
1230
1319
|
style,
|
|
1231
1320
|
children: [
|
|
1232
1321
|
isMobile && !isOpen && /* @__PURE__ */ jsxs("button", { type: "button", className: "dtc-messages-fab", onClick: ui.openInbox, "aria-label": labels.openMessages, children: [
|
|
1233
1322
|
/* @__PURE__ */ jsx(ChatIcon, {}),
|
|
1234
1323
|
rollup > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
|
|
1235
1324
|
] }),
|
|
1236
|
-
isOpen && /* @__PURE__ */ jsx("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": labels.messages, children: view.kind
|
|
1325
|
+
isOpen && /* @__PURE__ */ jsx("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: activeItem ? /* @__PURE__ */ jsx("div", { className: "dtc-item-panel", children: typeof activeItem.panel === "function" ? activeItem.panel({ close: ui.close }) : activeItem.panel }) : view.kind !== "room" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1237
1326
|
/* @__PURE__ */ jsxs("div", { className: "dtc-panel-header", children: [
|
|
1238
1327
|
/* @__PURE__ */ jsx("span", { className: "dtc-panel-title", children: labels.messages }),
|
|
1239
1328
|
/* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
|
|
1240
1329
|
] }),
|
|
1241
|
-
/* @__PURE__ */ jsx(
|
|
1330
|
+
/* @__PURE__ */ jsx(
|
|
1331
|
+
MessagesInbox,
|
|
1332
|
+
{
|
|
1333
|
+
rooms: inbox.rooms,
|
|
1334
|
+
requests: inbox.requests,
|
|
1335
|
+
labels,
|
|
1336
|
+
onOpenRoom: ui.openRoom,
|
|
1337
|
+
onRemoveRoom: inboxRowClose ? (roomId) => void inbox.hideDM(roomId).catch(() => {
|
|
1338
|
+
}) : void 0
|
|
1339
|
+
}
|
|
1340
|
+
)
|
|
1242
1341
|
] }) : activeContext ? /* @__PURE__ */ jsxs("div", { className: "dtc-conversation", children: [
|
|
1243
1342
|
/* @__PURE__ */ jsxs("div", { className: "dtc-conversation-header", children: [
|
|
1244
1343
|
/* @__PURE__ */ jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
|
|
@@ -1248,40 +1347,47 @@ function DialtribeMessages({
|
|
|
1248
1347
|
/* @__PURE__ */ jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
|
|
1249
1348
|
] }) : /* @__PURE__ */ jsx(ConversationView, { roomId: view.roomId, labels, onBack: ui.openInbox }, view.roomId) }),
|
|
1250
1349
|
showRail && /* @__PURE__ */ jsxs("nav", { className: "dtc-rail", "aria-label": labels.messages, children: [
|
|
1251
|
-
/* @__PURE__ */
|
|
1252
|
-
|
|
1253
|
-
{
|
|
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
|
-
|
|
1350
|
+
/* @__PURE__ */ jsxs("div", { className: "dtc-rail-scroll", children: [
|
|
1351
|
+
topItems.map(renderItemButton),
|
|
1352
|
+
topItems.length > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-rail-divider" }),
|
|
1353
|
+
/* @__PURE__ */ jsx(
|
|
1354
|
+
RailButton,
|
|
1355
|
+
{
|
|
1356
|
+
label: labels.messages,
|
|
1357
|
+
active: isOpen && view.kind === "inbox",
|
|
1358
|
+
badge: rollup,
|
|
1359
|
+
onClick: () => select({ kind: "inbox" }),
|
|
1360
|
+
children: /* @__PURE__ */ jsx(ChatIcon, {})
|
|
1361
|
+
}
|
|
1362
|
+
),
|
|
1363
|
+
contexts.length > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-rail-divider" }),
|
|
1364
|
+
contexts.map((c) => /* @__PURE__ */ jsx(
|
|
1365
|
+
RailButton,
|
|
1366
|
+
{
|
|
1367
|
+
label: c.label,
|
|
1368
|
+
active: activeRoomId === c.roomId,
|
|
1369
|
+
badge: c.badge ?? 0,
|
|
1370
|
+
onClick: () => select({ kind: "room", roomId: c.roomId }),
|
|
1371
|
+
children: /* @__PURE__ */ jsx(Avatar, { name: c.label, url: c.avatarUrl, size: 36 })
|
|
1372
|
+
},
|
|
1373
|
+
c.roomId
|
|
1374
|
+
)),
|
|
1375
|
+
recentDms.length > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-rail-divider" }),
|
|
1376
|
+
recentDms.map((room) => /* @__PURE__ */ jsx(
|
|
1377
|
+
RailButton,
|
|
1378
|
+
{
|
|
1379
|
+
label: room.name,
|
|
1380
|
+
active: activeRoomId === room.roomId,
|
|
1381
|
+
badge: room.isMuted ? 0 : room.unreadCount,
|
|
1382
|
+
onClick: () => select({ kind: "room", roomId: room.roomId }),
|
|
1383
|
+
children: /* @__PURE__ */ jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 36 })
|
|
1384
|
+
},
|
|
1385
|
+
room.roomId
|
|
1386
|
+
)),
|
|
1387
|
+
bottomItems.length > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-rail-divider" }),
|
|
1388
|
+
bottomItems.map(renderItemButton)
|
|
1389
|
+
] }),
|
|
1390
|
+
footerItems.length > 0 && /* @__PURE__ */ jsx("div", { className: "dtc-rail-footer", children: footerItems.map(renderItemButton) })
|
|
1285
1391
|
] })
|
|
1286
1392
|
]
|
|
1287
1393
|
}
|
|
@@ -1321,37 +1427,25 @@ function useMediaQuery(query) {
|
|
|
1321
1427
|
}, [query]);
|
|
1322
1428
|
return matches;
|
|
1323
1429
|
}
|
|
1324
|
-
function usePushLayout(enabled, inset) {
|
|
1325
|
-
const original = useRef(null);
|
|
1430
|
+
function usePushLayout(enabled, inset, side) {
|
|
1326
1431
|
useEffect(() => {
|
|
1327
|
-
const root = document.documentElement;
|
|
1328
1432
|
if (!enabled) return;
|
|
1329
|
-
original.current ?? (original.current = { padding: root.style.paddingRight, transition: root.style.transition });
|
|
1330
|
-
root.style.transition = "padding-right 250ms ease-out";
|
|
1331
|
-
root.style.paddingRight = `${inset}px`;
|
|
1332
|
-
root.style.setProperty("--dtc-messages-inset", `${inset}px`);
|
|
1333
|
-
}, [enabled, inset]);
|
|
1334
|
-
useEffect(() => {
|
|
1335
|
-
if (enabled) return;
|
|
1336
1433
|
const root = document.documentElement;
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
}
|
|
1342
|
-
root.style.
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
if (original.current) {
|
|
1348
|
-
root.style.paddingRight = original.current.padding;
|
|
1349
|
-
root.style.transition = original.current.transition;
|
|
1350
|
-
}
|
|
1434
|
+
const prop = side === "left" ? "paddingLeft" : "paddingRight";
|
|
1435
|
+
const original = { padding: root.style[prop], transition: root.style.transition };
|
|
1436
|
+
root.style.transition = `${side === "left" ? "padding-left" : "padding-right"} 250ms ease-out`;
|
|
1437
|
+
root.style[prop] = `${inset}px`;
|
|
1438
|
+
root.style.setProperty("--dtc-messages-inset", `${inset}px`);
|
|
1439
|
+
root.style.setProperty("--dtc-messages-side", side);
|
|
1440
|
+
root.dataset.dtcMessagesSide = side;
|
|
1441
|
+
return () => {
|
|
1442
|
+
root.style[prop] = original.padding;
|
|
1443
|
+
root.style.transition = original.transition;
|
|
1351
1444
|
root.style.removeProperty("--dtc-messages-inset");
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1445
|
+
root.style.removeProperty("--dtc-messages-side");
|
|
1446
|
+
delete root.dataset.dtcMessagesSide;
|
|
1447
|
+
};
|
|
1448
|
+
}, [enabled, inset, side]);
|
|
1355
1449
|
}
|
|
1356
1450
|
function useScrollLock(locked) {
|
|
1357
1451
|
useEffect(() => {
|
|
@@ -1363,14 +1457,15 @@ function useScrollLock(locked) {
|
|
|
1363
1457
|
};
|
|
1364
1458
|
}, [locked]);
|
|
1365
1459
|
}
|
|
1366
|
-
function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
1460
|
+
function useEdgeSwipe(enabled, isOpen, open, close, side) {
|
|
1367
1461
|
useEffect(() => {
|
|
1368
1462
|
if (!enabled) return;
|
|
1369
1463
|
let start = null;
|
|
1370
1464
|
const onStart = (e) => {
|
|
1371
1465
|
const t = e.touches[0];
|
|
1372
1466
|
if (!t) return;
|
|
1373
|
-
|
|
1467
|
+
const atEdge = side === "left" ? t.clientX <= EDGE_SWIPE_ZONE : t.clientX >= window.innerWidth - EDGE_SWIPE_ZONE;
|
|
1468
|
+
if (isOpen || atEdge) start = { x: t.clientX, y: t.clientY };
|
|
1374
1469
|
};
|
|
1375
1470
|
const onEnd = (e) => {
|
|
1376
1471
|
const t = e.changedTouches[0];
|
|
@@ -1379,8 +1474,9 @@ function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
|
1379
1474
|
const dy = Math.abs(t.clientY - start.y);
|
|
1380
1475
|
start = null;
|
|
1381
1476
|
if (Math.abs(dx) < SWIPE_DISTANCE || dy > Math.abs(dx)) return;
|
|
1382
|
-
|
|
1383
|
-
|
|
1477
|
+
const inward = side === "left" ? dx > 0 : dx < 0;
|
|
1478
|
+
if (!isOpen && inward) open();
|
|
1479
|
+
else if (isOpen && !inward) close();
|
|
1384
1480
|
};
|
|
1385
1481
|
window.addEventListener("touchstart", onStart, { passive: true });
|
|
1386
1482
|
window.addEventListener("touchend", onEnd, { passive: true });
|
|
@@ -1388,7 +1484,7 @@ function useEdgeSwipe(enabled, isOpen, open, close) {
|
|
|
1388
1484
|
window.removeEventListener("touchstart", onStart);
|
|
1389
1485
|
window.removeEventListener("touchend", onEnd);
|
|
1390
1486
|
};
|
|
1391
|
-
}, [enabled, isOpen, open, close]);
|
|
1487
|
+
}, [enabled, isOpen, open, close, side]);
|
|
1392
1488
|
}
|
|
1393
1489
|
function themeVars(theme) {
|
|
1394
1490
|
if (!theme) return {};
|