inboxer 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inboxer",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A self-hosted mail layer for agents: persists every inbound and outbound email, exposes an MCP server, and ships a minimal UI to review drafts.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/ui/routes.ts CHANGED
@@ -2,7 +2,7 @@ import type { Context, Hono } from "hono";
2
2
  import { deleteCookie, getCookie, getSignedCookie, setCookie, setSignedCookie } from "hono/cookie";
3
3
  import type { Access } from "../auth.ts";
4
4
  import { bareAddress, domainOf, splitAddresses } from "../core/address.ts";
5
- import { ConflictError, InvalidRequestError, type Mail, type MessageView } from "../core/mail.ts";
5
+ import { ConflictError, InvalidRequestError, type Mail, type MessageView, type ThreadStatus } from "../core/mail.ts";
6
6
  import { CATCHALL, type Actor, type InboxerConfig, type Message, type Session } from "../types.ts";
7
7
  import { S } from "./strings.ts";
8
8
  import * as V from "./views.ts";
@@ -47,23 +47,34 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
47
47
  cc: m.cc.filter(a => !own.has(bareAddress(a))),
48
48
  });
49
49
 
50
- const page = async (c: Context<UiEnv>, title: string, body: V.View, current: V.Page, status: 200 | 401 | 404 = 200) => {
50
+ /** Mailboxes a session can send from: every one in its scope but the catch-all. */
51
+ const senders = (session: Session): V.Mailbox[] => mail.listMailboxes(session.scope).filter(m => m.id !== CATCHALL);
52
+ const domainsOf = (session: Session): string[] => [...new Set(senders(session).map(m => domainOf(m.address)))];
53
+
54
+ const page = async (c: Context<UiEnv>, title: string, body: V.View, current: V.Page, status: 200 | 400 | 401 | 404 = 200, fullScreen = false) => {
51
55
  const session = c.get("session");
52
- const draftCount = session ? (await mail.listDrafts(undefined, session.scope)).length : 0;
53
- const domains = session
54
- ? [...new Set(mail.listMailboxes(session.scope).filter(m => m.id !== CATCHALL).map(m => domainOf(m.address)))]
55
- : [];
56
- return c.html(V.layout(title, body, { theme: theme(c), page: current, draftCount, signedIn: !!session, domains }), status);
56
+ const shell = session
57
+ ? { draftCount: (await mail.listDrafts(undefined, session.scope)).length, domains: domainsOf(session), senders: senders(session) }
58
+ : {};
59
+ return c.html(V.layout(title, body, { theme: theme(c), page: current, signedIn: !!session, fullScreen, ...shell }), status);
57
60
  };
58
61
 
59
62
  // Sign-in: GET only shows a button, so link previews and scanners do not burn the link.
63
+ // A used or expired link on a browser that is already signed in just opens the app.
64
+ const signedInSession = async (c: Context<UiEnv>): Promise<Session | null> => {
65
+ const value = await getSignedCookie(c, secret, SESSION_COOKIE);
66
+ return value ? access.authenticate(value) : null;
67
+ };
68
+
60
69
  app.get("/auth/:token", async c => {
61
70
  const valid = await access.isLinkValid(c.req.param("token"));
71
+ if (!valid && (await signedInSession(c))) return c.redirect("/", 303);
62
72
  return page(c, S.signInTitle, V.signIn(c.req.param("token"), valid), null, valid ? 200 : 404);
63
73
  });
64
74
 
65
75
  app.post("/auth/:token", async c => {
66
76
  const signedIn = await access.consumeLoginLink(c.req.param("token"), clientInfo(c));
77
+ if (!signedIn && (await signedInSession(c))) return c.redirect("/", 303);
67
78
  if (!signedIn) return page(c, S.signInTitle, V.signIn("", false), null, 404);
68
79
  await setSignedCookie(c, SESSION_COOKIE, signedIn.secret, secret, cookieOptions);
69
80
  return c.redirect(signedIn.next, 303);
@@ -78,7 +89,7 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
78
89
  return c.redirect(path, 303);
79
90
  });
80
91
 
81
- const ui = ["/", "/inbox", "/threads/*", "/drafts/*", "/attachments/*", "/devices", "/devices/*", "/logout"];
92
+ const ui = ["/", "/inbox", "/threads/*", "/drafts/*", "/attachments/*", "/compose", "/devices", "/devices/*", "/settings", "/logout"];
82
93
  for (const path of ui) {
83
94
  app.use(path, async (c, next) => {
84
95
  const value = await getSignedCookie(c, secret, SESSION_COOKIE);
@@ -188,29 +199,79 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
188
199
  });
189
200
  }
190
201
 
191
- app.get("/inbox", async c => {
192
- const mailbox = c.req.query("mailbox") ?? "";
202
+ /** The inbox filter from the query, carried along when a thread opens beside the list. */
203
+ const inboxFilter = (c: Context<UiEnv>): V.InboxFilter => {
193
204
  const requested = c.req.query("status");
194
205
  const status = requested === "all" || requested === "archived" ? requested : "unanswered";
195
- const scope = c.get("session").scope;
196
- const threads = await mail.listThreads({ mailbox: mailbox || undefined, status, limit: 200 }, scope);
197
- const mailboxes = mail.listMailboxes(scope);
198
- const own = new Set(mailboxes.map(m => bareAddress(m.address)));
199
- return page(c, S.navInbox, V.inboxPage(threads, mailboxes.map(m => m.id), { mailbox, status }, own), "inbox");
200
- });
206
+ return { mailbox: c.req.query("mailbox") ?? "", status };
207
+ };
208
+
209
+ const threadList = async (c: Context<UiEnv>, current: string | null): Promise<V.View> => {
210
+ const session = c.get("session");
211
+ const filter = inboxFilter(c);
212
+ const threads = await mail.listThreads({ mailbox: filter.mailbox || undefined, status: filter.status as ThreadStatus, limit: 200 }, session.scope);
213
+ const mailboxes = mail.listMailboxes(session.scope).map(m => m.id);
214
+ return V.threadList(threads, { mailboxes, domains: domainsOf(session), filter, own, current });
215
+ };
216
+
217
+ app.get("/inbox", async c => page(c, S.navInbox, V.inboxPage(await threadList(c, null), null), "inbox"));
201
218
 
202
219
  app.get("/threads/:id", async c => {
203
220
  const id = c.req.param("id");
204
- const scope = c.get("session").scope;
205
- let thread = await mail.requireThread(id, scope);
221
+ const session = c.get("session");
222
+ let thread = await mail.requireThread(id, session.scope);
206
223
  if (thread.unread) {
207
- await mail.mark([id], { read: true }, uiActor(c.get("session")));
208
- thread = await mail.requireThread(id, scope);
224
+ await mail.mark([id], { read: true }, uiActor(session));
225
+ thread = await mail.requireThread(id, session.scope);
226
+ }
227
+ const { messages, context, contacts } = await mail.getThread(id, session.scope);
228
+ const people = thread.participants.filter(p => !own.has(p));
229
+ const entries = await Promise.all(messages.map(async m => ({
230
+ at: m.date,
231
+ view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id), [], null) : V.messageBubble(shown(m), people.length > 1),
232
+ })));
233
+ const reply = { allowed: senders(session).some(m => m.id === thread.mailbox), replyAll: people.length > 1 };
234
+ const view = V.threadView(thread, entries, { context, contacts }, { filter: inboxFilter(c), own, reply });
235
+ return page(c, thread.subject || S.navInbox, V.inboxPage(await threadList(c, id), view), "inbox", 200, true);
236
+ });
237
+
238
+ /** Replies to the latest message; a reply sent from here gets the same undo window as a draft. */
239
+ app.post("/threads/:id/reply", async c => {
240
+ const id = c.req.param("id");
241
+ const actor = uiActor(c.get("session"));
242
+ const body = await c.req.parseBody();
243
+ const text = String(body.text ?? "");
244
+ const { messages } = await mail.getThread(id, actor.scope);
245
+ const latest = messages.filter(m => m.status !== "draft").at(-1);
246
+ const back = `/threads/${id}?${V.inboxQuery(inboxFilter(c))}`;
247
+ if (!latest || !text.trim()) return c.redirect(back, 303);
248
+ try {
249
+ const draft = await mail.createDraft({ replyToId: latest.id, replyAll: body.reply_all === "1", text }, actor);
250
+ if (body.action === "send") await mail.schedule(draft.id, "send", actor);
251
+ } catch (err) {
252
+ if (err instanceof InvalidRequestError) return page(c, S.reply, V.message([err.message]), "inbox", 400);
253
+ throw err;
254
+ }
255
+ return c.redirect(back, 303);
256
+ });
257
+
258
+ app.post("/compose", async c => {
259
+ const actor = uiActor(c.get("session"));
260
+ const body = await c.req.parseBody();
261
+ try {
262
+ const draft = await mail.createDraft({
263
+ mailbox: String(body.mailbox ?? ""),
264
+ to: splitAddresses(String(body.to ?? "")),
265
+ cc: splitAddresses(String(body.cc ?? "")),
266
+ subject: String(body.subject ?? ""),
267
+ text: String(body.text ?? ""),
268
+ }, actor);
269
+ if (body.action === "send") await mail.schedule(draft.id, "send", actor);
270
+ return c.redirect(`/threads/${draft.thread_id}?status=all`, 303);
271
+ } catch (err) {
272
+ if (err instanceof InvalidRequestError) return page(c, S.newMail, V.message([err.message]), null, 400);
273
+ throw err;
209
274
  }
210
- const { messages, context, contacts } = await mail.getThread(id, scope);
211
- const items = await Promise.all([...messages].reverse().map(async m =>
212
- m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id), [], null) : V.messageCard(shown(m))));
213
- return page(c, thread.subject || S.navInbox, V.threadPage(thread, items, { context, contacts }), "inbox");
214
275
  });
215
276
 
216
277
  app.post("/threads/:id/archive", async c => {
@@ -238,6 +299,8 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
238
299
  return page(c, S.navDevices, V.devicesPage(await access.listSessions(session.scope), session.id), "devices");
239
300
  });
240
301
 
302
+ app.get("/settings", async c => page(c, S.navSettings, V.settingsPage(theme(c)), "settings"));
303
+
241
304
  app.post("/devices/:id/revoke", async c => {
242
305
  await access.revokeSession(c.req.param("id"), uiActor(c.get("session")));
243
306
  return c.body(null, 200);
@@ -1,3 +1,30 @@
1
+ // New mail opens as a modal sheet; a click on its backdrop or a [data-close] button closes it.
2
+ document.addEventListener("click", event => {
3
+ const target = event.target instanceof Element ? event.target : null;
4
+ if (!target) return;
5
+ if (target.closest("[data-compose]")) {
6
+ const dialog = document.getElementById("compose");
7
+ dialog.showModal();
8
+ dialog.querySelector("#compose-to").focus();
9
+ } else if (target.closest("[data-close]")) {
10
+ target.closest("dialog").close();
11
+ } else if (target instanceof HTMLDialogElement && target.open) {
12
+ target.close();
13
+ } else if (target.closest("[data-context-toggle]")) {
14
+ document.body.classList.toggle("context-open");
15
+ }
16
+ });
17
+
18
+ document.addEventListener("keydown", event => {
19
+ if (event.key === "Escape") document.body.classList.remove("context-open");
20
+ });
21
+
22
+ // A thread opens at its latest message.
23
+ document.addEventListener("DOMContentLoaded", () => {
24
+ const messages = document.querySelector("[data-scroll-end]");
25
+ if (messages) messages.scrollTop = messages.scrollHeight;
26
+ });
27
+
1
28
  // Files dropped on a [data-drop] zone go to its file input, which uploads them through htmx.
2
29
  const zoneOf = event => event.target instanceof Element ? event.target.closest("[data-drop]") : null;
3
30
  const hasFiles = event => [...(event.dataTransfer?.types ?? [])].includes("Files");
@@ -1,17 +1,23 @@
1
1
  :root {
2
2
  color-scheme: light dark;
3
- --bg: light-dark(#fbfbfa, #0c0b0a);
4
- --fg: light-dark(#0a0a0a, #f2f2f0);
5
- --muted: light-dark(#8a8a86, #6e6e6a);
6
- --line: light-dark(#e6e6e3, #24201d);
7
- --soft: light-dark(#f1f1ef, #141414);
3
+ --bg: light-dark(#fbfbfa, #262624);
4
+ --fg: light-dark(#0a0a0a, #ececea);
5
+ --muted: light-dark(#6b6b67, #a3a39e);
6
+ --line: light-dark(#e6e6e3, #3a3a37);
7
+ --soft: light-dark(#f1f1ef, #1f1f1e);
8
+ --chip: light-dark(#e9e9e6, #333331);
9
+ --surface: light-dark(#ffffff, #2e2e2c);
10
+ --mine: light-dark(#ffe6d6, #4a2e20);
11
+ --mine-line: light-dark(#ffd2b8, #5e3a28);
8
12
  --accent: light-dark(#ff4d00, #ff7a3d);
9
- --focus: light-dark(#0a0a0a, #c2552a);
10
- --primary-bg: light-dark(#0a0a0a, #2e1a10);
11
- --primary-fg: light-dark(#fbfbfa, #ffd9c4);
12
- --primary-border: light-dark(#0a0a0a, #5a2e17);
13
+ --accent-text: light-dark(#c43d00, #ff8f5c);
14
+ --focus: light-dark(#0a0a0a, #a3a39e);
15
+ --primary-bg: light-dark(#0a0a0a, #ececea);
16
+ --primary-fg: light-dark(#fbfbfa, #1f1f1e);
13
17
  --danger: light-dark(#d92d20, #ff6b5e);
18
+ --backdrop: light-dark(rgb(10 10 10 / .42), rgb(0 0 0 / .5));
14
19
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
20
+ --tabbar: 64px;
15
21
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
16
22
  font-size: 15px;
17
23
  line-height: 1.5;
@@ -24,24 +30,242 @@
24
30
  [hidden] { display: none !important; }
25
31
  body { margin: 0; background: var(--bg); color: var(--fg); }
26
32
  a { color: inherit; text-decoration: none; }
27
- main { max-width: 720px; margin: 0 auto; padding: 32px 16px 96px; }
28
- h1 { font-size: 2.25rem; line-height: 1.1; letter-spacing: -0.04em; font-weight: 700; margin: 0 0 24px; }
33
+ h1 { font-size: 2rem; line-height: 1.1; letter-spacing: -0.04em; font-weight: 700; margin: 0 0 24px; }
29
34
  ::selection { background: var(--accent); color: #fff; }
35
+ .icon { flex: none; }
30
36
 
31
- /* Header */
32
- header {
33
- position: sticky; top: 0; z-index: 1;
34
- display: flex; align-items: center; gap: 12px;
35
- padding: 12px 16px;
36
- background: color-mix(in srgb, var(--bg) 85%, transparent);
37
- backdrop-filter: blur(12px);
38
- border-bottom: 1px solid var(--line);
39
- }
40
- header nav { display: flex; gap: 16px; flex: 1; min-width: 0; overflow-x: auto; }
41
- header nav a { color: var(--muted); font-weight: 500; white-space: nowrap; transition: color .15s; }
42
- header nav a:hover, header nav a[aria-current="page"] { color: var(--fg); }
43
- header form { margin: 0; }
44
- .count { color: var(--accent); font-family: var(--mono); font-size: .75rem; vertical-align: super; }
37
+ /* Shell: a tab bar on a phone, a sidebar on a wide screen */
38
+ .sidebar { display: none; }
39
+ body.app { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
40
+ body.app.full { padding-bottom: 0; }
41
+ .page { max-width: 760px; margin: 0 auto; padding: 24px 16px 32px; }
42
+
43
+ .tabbar {
44
+ position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
45
+ display: flex; align-items: center;
46
+ padding: 4px 8px env(safe-area-inset-bottom);
47
+ background: var(--bg); border-top: 1px solid var(--line);
48
+ }
49
+ body.full .tabbar { display: none; }
50
+ .tabbar a {
51
+ position: relative; flex: 1; height: 56px;
52
+ display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
53
+ font-size: 11px; font-weight: 500; color: var(--muted);
54
+ }
55
+ .tabbar a[aria-current="page"] { color: var(--fg); }
56
+ .tabbar .count {
57
+ position: absolute; top: 4px; left: 52%;
58
+ min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
59
+ display: flex; align-items: center; justify-content: center;
60
+ background: var(--accent); color: #1f1f1e; font-family: var(--mono); font-size: 10px;
61
+ }
62
+ .tab-compose { flex: 1; height: 56px; padding: 0; border: none; background: none; display: flex; align-items: center; justify-content: center; }
63
+ .tab-compose span {
64
+ width: 52px; height: 40px; border-radius: 14px;
65
+ display: flex; align-items: center; justify-content: center;
66
+ background: var(--primary-bg); color: var(--primary-fg);
67
+ }
68
+ .tab-compose:hover { border: none; }
69
+
70
+ @media (min-width: 900px) {
71
+ body.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); padding-bottom: 0; }
72
+ .tabbar { display: none; }
73
+ .sidebar {
74
+ position: sticky; top: 0; height: 100dvh;
75
+ display: flex; flex-direction: column; gap: 4px;
76
+ padding: 20px 14px; border-right: 1px solid var(--line);
77
+ }
78
+ .brand { font-size: 20px; font-weight: 700; letter-spacing: -0.03em; padding: 0 12px; }
79
+ .brand span { color: var(--accent); }
80
+ .sidebar .domain { font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 2px 12px 0; overflow-wrap: anywhere; }
81
+ .new-mail { display: flex; align-items: center; justify-content: center; gap: 8px; height: 44px; border-radius: 12px; margin: 16px 0 14px; }
82
+ .side-nav { display: flex; flex-direction: column; gap: 2px; }
83
+ .side-nav a {
84
+ display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 10px;
85
+ color: var(--muted); font-size: 14px; font-weight: 500;
86
+ }
87
+ .side-nav a:hover { color: var(--fg); }
88
+ .side-nav a[aria-current="page"] { background: var(--chip); color: var(--fg); }
89
+ .side-nav .count { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--accent-text); }
90
+ .side-end { margin-top: auto; }
91
+ .page { padding-top: 40px; }
92
+ }
93
+
94
+ /* Inbox: the list, and the open thread beside it on a wide screen */
95
+ .split .pane { display: none; }
96
+ .split.has-thread .list { display: none; }
97
+ .split.has-thread .pane { display: block; }
98
+ @media (min-width: 900px) {
99
+ .split { display: flex; height: 100dvh; }
100
+ .split .list { display: block; width: 380px; flex: none; overflow-y: auto; border-right: 1px solid var(--line); }
101
+ .split .pane { display: block; flex: 1; min-width: 0; background: var(--soft); }
102
+ body.context-open .split .list { display: none; }
103
+ }
104
+
105
+ .list-head { padding: 18px 16px 12px; }
106
+ .list-head h1 { font-size: 21px; line-height: 1.2; letter-spacing: -0.02em; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
107
+ .filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
108
+ .chips { display: flex; gap: 8px; }
109
+ .chip {
110
+ display: inline-flex; align-items: center; height: 36px; padding: 0 14px; border-radius: 999px;
111
+ border: 1px solid var(--line); font-size: 13px; font-weight: 500; white-space: nowrap;
112
+ }
113
+ .chip:hover { border-color: var(--focus); }
114
+ .chip[aria-current="page"] { background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-bg); }
115
+
116
+ .row { display: flex; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); }
117
+ .row:hover { background: var(--soft); }
118
+ .row[aria-current="page"] { background: var(--soft); box-shadow: inset 3px 0 0 var(--accent); }
119
+ .avatar {
120
+ width: 44px; height: 44px; border-radius: 999px; flex: none;
121
+ display: flex; align-items: center; justify-content: center;
122
+ background: var(--chip); font-size: 14px; font-weight: 600;
123
+ }
124
+ .row-main { flex: 1; min-width: 0; }
125
+ .row-top { display: flex; align-items: baseline; gap: 8px; }
126
+ .row .who { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
127
+ .row time { flex: none; font-family: var(--mono); font-size: 11px; color: var(--muted); }
128
+ .row-subject { display: block; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
129
+ .row.unread .who { font-weight: 600; }
130
+ .row.unread .row-subject { color: var(--fg); font-weight: 500; }
131
+ .row.unread time { color: var(--accent-text); }
132
+ .row-tags { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
133
+ .list .empty { border-top: 1px solid var(--line); }
134
+
135
+ /* Thread */
136
+ .thread {
137
+ position: relative; height: 100dvh;
138
+ display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto;
139
+ background: var(--soft);
140
+ }
141
+ .thread > :not(.context-panel, .context-backdrop) { grid-column: 1; }
142
+ .thread-head {
143
+ display: flex; align-items: center; gap: 4px; padding: 8px 6px;
144
+ background: var(--bg); border-bottom: 1px solid var(--line);
145
+ }
146
+ .icon-btn {
147
+ width: 44px; height: 44px; padding: 0; flex: none; border: none; border-radius: 999px;
148
+ display: inline-flex; align-items: center; justify-content: center; background: none; color: var(--fg);
149
+ }
150
+ .icon-btn:hover { background: var(--soft); border: none; }
151
+ .thread-head form { margin: 0; }
152
+ .thread-title {
153
+ flex: 1; min-width: 0; height: auto; padding: 4px 6px; border: none; border-radius: 12px;
154
+ display: flex; flex-direction: column; align-items: flex-start; text-align: left; background: none; font: inherit; color: inherit;
155
+ }
156
+ button.thread-title:hover { background: var(--soft); border: none; }
157
+ .thread-subject {
158
+ font-size: 15px; font-weight: 600; line-height: 1.25;
159
+ display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
160
+ }
161
+ .thread-meta { max-width: 100%; font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
162
+ .context-btn { display: none; }
163
+
164
+ .messages { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px 12px 20px; }
165
+ .day {
166
+ align-self: center; padding: 4px 10px; border-radius: 999px; background: var(--chip);
167
+ font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
168
+ }
169
+ .msg { max-width: 86%; padding: 12px 14px 8px; border-radius: 18px; font-size: 14.5px; }
170
+ .msg.theirs { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
171
+ .msg.mine { align-self: flex-end; background: var(--mine); border: 1px solid var(--mine-line); border-bottom-right-radius: 6px; }
172
+ .msg .body { margin: 0; }
173
+ .msg > .meta { margin-bottom: 6px; }
174
+ .msg-from { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
175
+ .msg-time { display: block; text-align: right; margin-top: 4px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
176
+
177
+ /* A draft in a thread sits on our side as a dashed bubble */
178
+ .messages .card {
179
+ align-self: flex-end; max-width: 86%; padding: 12px 14px;
180
+ background: var(--surface); border: 1.5px dashed var(--accent); border-radius: 18px; border-bottom-right-radius: 6px;
181
+ }
182
+ .messages .card.editing { width: 100%; max-width: 100%; }
183
+ .messages .card.pending, .messages .card.notice { border-style: solid; border-color: var(--line); }
184
+ .messages .card .mailbox, .messages .draft-head .subject { display: none; }
185
+ .messages .card .body { margin-top: 10px; }
186
+ .messages .card .actions { justify-content: flex-end; margin-top: 12px; }
187
+
188
+ .composer {
189
+ display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px;
190
+ padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
191
+ background: var(--bg); border-top: 1px solid var(--line);
192
+ }
193
+ .composer textarea {
194
+ flex: 1; min-width: 0; min-height: 44px; max-height: 40dvh; margin: 0; padding: 11px 16px;
195
+ field-sizing: content; resize: none; border: 1px solid var(--line); border-radius: 22px; background: var(--surface);
196
+ }
197
+ .composer textarea:focus { border-color: var(--focus); }
198
+ .composer .send { width: 44px; height: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
199
+ .reply-all { flex-basis: 100%; display: flex; align-items: center; gap: 8px; padding: 2px 8px; font-family: var(--mono); font-size: .72rem; color: var(--muted); cursor: pointer; }
200
+ .reply-all input { accent-color: var(--accent); }
201
+
202
+ /* Context: a side panel on a wide screen, a bottom sheet on a phone */
203
+ .context-panel { display: none; background: var(--bg); }
204
+ .context-head { display: flex; align-items: center; height: 60px; padding: 0 8px 0 16px; }
205
+ .context-head h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; }
206
+ .context-body { overflow-y: auto; padding: 0 16px 16px; }
207
+ .context-body section { padding: 14px 0; border-top: 1px solid var(--line); }
208
+ .context-backdrop { display: none; }
209
+ body.context-open .context-panel { display: flex; flex-direction: column; }
210
+ @media (max-width: 899px) {
211
+ body.context-open .context-backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: var(--backdrop); }
212
+ body.context-open .context-panel {
213
+ position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; height: 70dvh;
214
+ border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgb(0 0 0 / .25);
215
+ padding-bottom: env(safe-area-inset-bottom); animation: rise .2s ease-out;
216
+ }
217
+ .context-panel::before {
218
+ content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px;
219
+ border-radius: 999px; background: var(--line);
220
+ }
221
+ }
222
+ @media (min-width: 900px) {
223
+ .thread { height: 100dvh; }
224
+ .msg, .messages .card { max-width: 68%; }
225
+ .messages { padding: 20px 32px 28px; }
226
+ .thread-head { padding: 12px 20px 12px 12px; gap: 8px; }
227
+ .context-btn { display: inline-flex; align-items: center; }
228
+ body.context-open .context-btn { background: var(--chip); }
229
+ body.context-open .thread { grid-template-columns: minmax(0, 1fr) 360px; }
230
+ body.context-open .context-panel { grid-column: 2; grid-row: 1 / -1; border-left: 1px solid var(--line); min-height: 0; }
231
+ .composer { padding: 0 24px 20px; background: none; border: none; }
232
+ }
233
+ @keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
234
+
235
+ /* Context rows, shared by the panel and the folded block on a draft */
236
+ .context .who, .context-body .who { font-family: var(--mono); font-size: .75rem; color: var(--fg); overflow-wrap: anywhere; }
237
+ .context dl, .context-body dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 10px 0 0; font-family: var(--mono); font-size: .75rem; }
238
+ .context dt, .context-body dt { color: var(--muted); }
239
+ .context dd, .context-body dd { margin: 0; overflow-wrap: anywhere; }
240
+ .context p, .context-body p { margin: 10px 0 0; padding: 8px 10px; border-radius: 10px; background: var(--soft); white-space: pre-wrap; font-size: .8125rem; color: var(--muted); }
241
+ .context summary { margin-top: 14px; }
242
+ .context section { margin-top: 12px; padding-left: 14px; border-left: 1px solid var(--line); }
243
+
244
+ /* Sheets: New mail rises from the bottom on a phone and centers on a wide screen */
245
+ dialog.sheet {
246
+ margin: auto 0 0; width: 100%; max-width: 100%; height: 70dvh; max-height: 70dvh; padding: 0;
247
+ border: none; border-radius: 22px 22px 0 0; background: var(--bg); color: var(--fg);
248
+ box-shadow: 0 -8px 30px rgb(0 0 0 / .25);
249
+ }
250
+ dialog.sheet[open] { animation: rise .2s ease-out; }
251
+ dialog.sheet::backdrop { background: var(--backdrop); }
252
+ dialog.sheet form { position: relative; height: 100%; display: flex; flex-direction: column; }
253
+ .grabber { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 8px auto 9px; flex: none; }
254
+ .sheet-close { position: absolute; top: 8px; right: 8px; color: var(--muted); z-index: 1; }
255
+ dialog.sheet .field { padding: 0 16px; }
256
+ dialog.sheet .field.compact { padding-right: 60px; }
257
+ dialog.sheet .field output { font-family: var(--mono); font-size: .8rem; padding: 10px 0; }
258
+ dialog.sheet textarea { flex: 1; min-height: 0; margin: 0; padding: 12px 16px; resize: none; }
259
+ .sheet-actions {
260
+ display: flex; justify-content: flex-end; gap: 8px;
261
+ padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
262
+ }
263
+ .sheet-actions button { height: 44px; display: inline-flex; align-items: center; gap: 8px; }
264
+ @media (min-width: 900px) {
265
+ dialog.sheet { margin: auto; width: 640px; height: min(640px, 80dvh); border-radius: 18px; }
266
+ dialog.sheet[open] { animation: none; }
267
+ .grabber { visibility: hidden; }
268
+ }
45
269
 
46
270
  /* Meta and labels */
47
271
  .meta {
@@ -53,34 +277,28 @@ header form { margin: 0; }
53
277
  font-family: var(--mono); font-size: .66rem; font-weight: 500; text-transform: uppercase; letter-spacing: .08em;
54
278
  padding: 2px 7px; border: 1px solid var(--line); border-radius: 4px; color: var(--fg);
55
279
  }
56
- .badge.draft { border-color: var(--accent); color: var(--accent); }
57
- .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }
280
+ .badge.draft { border-color: var(--accent); color: var(--accent-text); }
281
+ .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; margin-left: auto; }
58
282
 
59
- /* Items */
283
+ /* Cards: drafts for review and devices */
60
284
  .card { border-top: 1px solid var(--line); padding: 24px 0; scroll-margin-top: 64px; }
61
- .card > .meta + .meta { margin-top: 6px; }
285
+ .card > .meta + .meta, .draft-head { margin-top: 8px; }
62
286
  .subject { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.02em; margin: 10px 0 4px; }
63
- .note { border-left: 2px solid var(--accent); padding: 2px 0 2px 14px; margin: 14px 0; white-space: pre-wrap; }
64
- .context summary { margin-top: 14px; }
65
- .context section { margin-top: 12px; padding-left: 14px; border-left: 1px solid var(--line); }
66
- .context .who { font-family: var(--mono); font-size: .75rem; color: var(--fg); overflow-wrap: anywhere; }
67
- .context dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 16px; margin: 8px 0 0; font-family: var(--mono); font-size: .75rem; }
68
- .context dt { color: var(--muted); }
69
- .context dd { margin: 0; overflow-wrap: anywhere; }
70
- .context p { margin: 8px 0 0; white-space: pre-wrap; font-size: .8125rem; color: var(--muted); }
287
+ .note { background: var(--soft); border-radius: 10px; padding: 6px 10px; margin: 12px 0; white-space: pre-wrap; font-size: .8125rem; color: var(--muted); }
288
+ .messages .note { background: var(--chip); }
71
289
  .body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 14px 0 0; font: inherit; }
72
- .images { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 16px; }
73
- .images a { display: block; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--soft); }
290
+ .images { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 12px; }
291
+ .images a { display: block; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--soft); }
74
292
  .images img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .15s; }
75
293
  .images a:hover img { opacity: .8; }
76
- .files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
294
+ .files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
77
295
  .file {
78
296
  display: inline-flex; align-items: center; gap: 10px; max-width: 100%;
79
297
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
80
- font-family: var(--mono); font-size: .72rem; transition: border-color .15s;
298
+ font-family: var(--mono); font-size: .72rem; white-space: nowrap; transition: border-color .15s;
81
299
  }
82
300
  .file:hover { border-color: var(--focus); }
83
- .file span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
301
+ .file span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
84
302
  .file .size { color: var(--muted); flex: none; }
85
303
  .draft-files { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
86
304
  .draft-files .warn { flex-basis: 100%; margin: 0; color: var(--danger); font-family: var(--mono); font-size: .72rem; }
@@ -93,25 +311,20 @@ header form { margin: 0; }
93
311
  align-items: center; justify-content: center;
94
312
  border: 1px dashed var(--accent); border-radius: 8px;
95
313
  background: color-mix(in srgb, var(--bg) 88%, transparent);
96
- font-family: var(--mono); font-size: .8rem; color: var(--accent); pointer-events: none;
314
+ font-family: var(--mono); font-size: .8rem; color: var(--accent-text); pointer-events: none;
97
315
  }
98
316
  [data-drop].dragging .drop-hint { display: flex; }
99
317
  .notice { color: var(--muted); font-family: var(--mono); font-size: .8rem; }
100
- .thread-head { margin-bottom: 28px; }
101
- .domain { font-family: var(--mono); font-size: .72rem; letter-spacing: .02em; color: var(--muted); margin-bottom: 10px; }
102
318
  .pending { position: relative; }
103
319
  .pending-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: .9rem; }
104
320
  .pending-row span { min-width: 0; overflow-wrap: anywhere; color: var(--muted); }
105
321
  .pending-row strong { color: var(--fg); font-weight: 500; }
106
322
  .countdown { position: absolute; left: 0; top: -1px; height: 1px; width: 100%; background: var(--accent); transform-origin: left; animation: countdown linear forwards; }
323
+ .messages .countdown { left: 14px; right: 14px; width: auto; top: auto; bottom: 6px; }
107
324
  @keyframes countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }
108
325
  .conflict { border-top: 2px solid var(--danger); }
109
326
  .conflict .warn { color: var(--danger); font-weight: 600; margin: 14px 0 4px; }
110
327
 
111
- .thread-row { display: block; transition: opacity .15s; }
112
- .thread-row:hover { opacity: .65; }
113
- .thread-row .subject { margin: 8px 0 2px; }
114
-
115
328
  details summary {
116
329
  cursor: pointer; list-style: none; margin-top: 18px;
117
330
  font-family: var(--mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
@@ -127,11 +340,11 @@ button {
127
340
  font: inherit; font-size: .875rem; font-weight: 500;
128
341
  height: 36px; padding: 0 16px; border-radius: 999px;
129
342
  border: 1px solid var(--line); background: transparent; color: var(--fg);
130
- cursor: pointer; transition: border-color .15s, opacity .15s;
343
+ cursor: pointer; transition: border-color .15s, opacity .15s, background-color .15s;
131
344
  }
132
345
  button:hover { border-color: var(--focus); }
133
- button.primary { background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-border); }
134
- button.primary:hover { border-color: var(--focus); opacity: .9; }
346
+ button.primary { background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-bg); }
347
+ button.primary:hover { opacity: .9; }
135
348
  button.danger { color: var(--danger); border-color: transparent; }
136
349
  button.danger:hover { border-color: var(--danger); }
137
350
  button.link { height: auto; padding: 0; border: none; color: var(--muted); }
@@ -141,9 +354,10 @@ button.link:hover { color: var(--fg); }
141
354
  select {
142
355
  appearance: none; -webkit-appearance: none;
143
356
  font: inherit; font-size: .8rem; color: var(--fg); cursor: pointer;
144
- height: 32px; padding: 0 30px 0 12px; border: 1px solid var(--line); border-radius: 999px;
357
+ height: 36px; padding: 0 30px 0 12px; border: 1px solid var(--line); border-radius: 999px;
145
358
  background: transparent;
146
359
  }
360
+ select option { background: var(--bg); color: var(--fg); }
147
361
  .select { position: relative; display: inline-flex; color: var(--fg); }
148
362
  .select::after {
149
363
  content: ""; position: absolute; right: 13px; top: 50%; pointer-events: none;
@@ -153,27 +367,26 @@ select {
153
367
  select:hover, select:focus { border-color: var(--focus); outline: none; }
154
368
 
155
369
  /* Editor */
156
- .field { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
370
+ .field { display: flex; align-items: center; gap: 12px; min-height: 44px; border-bottom: 1px solid var(--line); }
157
371
  .field label {
158
372
  flex: 0 0 64px;
159
373
  font-family: var(--mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
160
374
  }
161
- .field input { flex: 1; min-width: 0; border: none; background: none; padding: 12px 0; font: inherit; color: var(--fg); outline: none; }
375
+ .field input { flex: 1; min-width: 0; border: none; background: none; padding: 11px 0; font: inherit; color: var(--fg); outline: none; }
162
376
  .field:focus-within { border-bottom-color: var(--focus); }
163
377
  .field .link { font-family: var(--mono); font-size: .72rem; }
164
378
  textarea {
165
379
  display: block; width: 100%; min-height: 16rem; margin-top: 16px; padding: 0; resize: vertical;
166
380
  border: none; background: none; font: inherit; color: var(--fg); outline: none;
167
381
  }
382
+ .messages .editing textarea { min-height: 10rem; }
168
383
 
169
- /* Inbox filters */
170
- .filters { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-bottom: 8px; }
171
- .tabs { display: flex; gap: 16px; }
172
- .tabs a { color: var(--muted); font-weight: 500; padding: 4px 0; border-bottom: 1px solid transparent; }
173
- .tabs a:hover { color: var(--fg); }
174
- .tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--focus); }
384
+ /* Settings */
385
+ .setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 0; border-top: 1px solid var(--line); }
386
+ .setting label { font-weight: 500; }
387
+ .setting .danger { padding: 0; }
175
388
 
176
389
  /* States */
177
- .centered { max-width: 360px; margin: 20vh auto 0; text-align: center; }
390
+ .centered { max-width: 360px; margin: 20vh auto 0; padding: 0 16px; text-align: center; }
178
391
  .centered h1 { font-size: 1.75rem; }
179
- .empty { color: var(--muted); font-family: var(--mono); font-size: .8rem; border-top: 1px solid var(--line); padding: 48px 0; text-align: center; }
392
+ .empty { color: var(--muted); font-family: var(--mono); font-size: .8rem; border-top: 1px solid var(--line); padding: 48px 16px; text-align: center; }
package/src/ui/strings.ts CHANGED
@@ -4,6 +4,10 @@ export const S = {
4
4
  navDrafts: "Drafts",
5
5
  navInbox: "Inbox",
6
6
  navDevices: "Devices",
7
+ navSettings: "Settings",
8
+ mainNav: "Main",
9
+ back: "Back",
10
+ close: "Close",
7
11
  logout: "Log out",
8
12
  themeSystem: "System",
9
13
  themeLight: "Light",
@@ -33,6 +37,13 @@ export const S = {
33
37
  sentTo: "Sent to",
34
38
  discarded: "Draft discarded.",
35
39
  editedByHuman: "Edited by you",
40
+ byAgent: "By agent",
41
+ newMail: "New mail",
42
+ saveDraft: "Save draft",
43
+ reply: "Reply",
44
+ replyAll: "Reply all",
45
+ today: "Today",
46
+ yesterday: "Yesterday",
36
47
  thread: "Thread",
37
48
  thisThread: "This thread",
38
49
  context: "Context",
@@ -42,7 +53,7 @@ export const S = {
42
53
  yourVersion: "Your version",
43
54
  currentVersion: "Current version",
44
55
 
45
- filterUnanswered: "Unanswered",
56
+ filterPending: "Pending",
46
57
  filterAll: "All",
47
58
  filterArchived: "Archived",
48
59
  allMailboxes: "All mailboxes",
@@ -53,7 +64,6 @@ export const S = {
53
64
 
54
65
  archive: "Archive",
55
66
  unarchive: "Move to inbox",
56
- status: "Status",
57
67
 
58
68
  devicesEmpty: "No signed-in devices.",
59
69
  thisDevice: "This device",
package/src/ui/views.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { html, raw } from "hono/html";
2
2
  import type { HtmlEscapedString } from "hono/utils/html";
3
+ import { bareAddress } from "../core/address.ts";
3
4
  import type { MessageView } from "../core/mail.ts";
4
5
  import type { Contact, Context, Message, Session, Thread } from "../types.ts";
5
6
  import { ASSETS } from "./assets.ts";
@@ -7,7 +8,7 @@ import { S } from "./strings.ts";
7
8
 
8
9
  export type View = HtmlEscapedString;
9
10
  export type Theme = "system" | "light" | "dark";
10
- export type Page = "drafts" | "inbox" | "devices" | null;
11
+ export type Page = "drafts" | "inbox" | "devices" | "settings" | null;
11
12
 
12
13
  /** Views never await, so `html` returns a plain escaped string. */
13
14
  function h(strings: TemplateStringsArray, ...values: unknown[]): View {
@@ -22,47 +23,153 @@ function when(condition: unknown, view: () => View): View | "" {
22
23
  return condition ? view() : "";
23
24
  }
24
25
 
25
- function formatDate(iso: string): string {
26
+ const ICONS = {
27
+ back: '<path d="M15 18l-6-6 6-6"/>',
28
+ archive: '<rect x="3" y="4" width="18" height="5" rx="1"/><path d="M5 9v10a1 1 0 001 1h12a1 1 0 001-1V9"/><path d="M10 13h4"/>',
29
+ unarchive: '<rect x="3" y="4" width="18" height="5" rx="1"/><path d="M5 9v10a1 1 0 001 1h12a1 1 0 001-1V9"/><path d="M12 17v-5M9.5 14.5L12 12l2.5 2.5"/>',
30
+ drafts: '<path d="M4 20h4L19 9l-4-4L4 16z"/><path d="M13 7l4 4"/>',
31
+ inbox: '<path d="M3 13l3-8h12l3 8v6a1 1 0 01-1 1H4a1 1 0 01-1-1z"/><path d="M3 13h5l1 3h6l1-3h5"/>',
32
+ plus: '<path d="M12 5v14M5 12h14"/>',
33
+ devices: '<rect x="6" y="2" width="12" height="20" rx="2"/><path d="M11 18h2"/>',
34
+ settings: '<circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M2 12h3M19 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1"/>',
35
+ send: '<path d="M5 12h14"/><path d="M13 6l6 6-6 6"/>',
36
+ close: '<path d="M6 6l12 12M18 6L6 18"/>',
37
+ } as const;
38
+
39
+ function icon(name: keyof typeof ICONS): View {
40
+ return raw(`<svg class="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[name]}</svg>`) as View;
41
+ }
42
+
43
+ const sameDay = (a: Date, b: Date) => a.toDateString() === b.toDateString();
44
+
45
+ function formatTime(iso: string): string {
46
+ return new Date(iso).toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
47
+ }
48
+
49
+ function formatDay(iso: string): string {
26
50
  const date = new Date(iso);
27
- const sameDay = date.toDateString() === new Date().toDateString();
28
- return sameDay
29
- ? date.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit" })
51
+ const now = new Date();
52
+ return date.getFullYear() === now.getFullYear()
53
+ ? date.toLocaleDateString("en", { month: "short", day: "numeric" })
30
54
  : date.toLocaleDateString("en", { month: "short", day: "numeric", year: "numeric" });
31
55
  }
32
56
 
33
- export function layout(title: string, body: View, opts: { theme: Theme; page: Page; draftCount?: number; signedIn: boolean; domains?: string[] }): View {
34
- const nav = (page: Page, href: string, label: string, extra: View | "" = "") =>
35
- h`<a href="${href}" ${raw(opts.page === page ? 'aria-current="page"' : "")}>${label}${extra}</a>`;
57
+ /** A time today, a day otherwise. */
58
+ function formatDate(iso: string): string {
59
+ return sameDay(new Date(iso), new Date()) ? formatTime(iso) : formatDay(iso);
60
+ }
61
+
62
+ function dayLabel(iso: string): string {
63
+ const date = new Date(iso);
64
+ const yesterday = new Date(Date.now() - 86_400_000);
65
+ if (sameDay(date, new Date())) return S.today;
66
+ if (sameDay(date, yesterday)) return S.yesterday;
67
+ return formatDay(iso);
68
+ }
69
+
70
+ /** Display name from `Name <a@b.com>`, else the bare address. */
71
+ function displayName(address: string): string {
72
+ const match = /^\s*"?([^"<]+?)"?\s*</.exec(address);
73
+ return match ? match[1]! : bareAddress(address);
74
+ }
75
+
76
+ function initials(address: string): string {
77
+ const name = displayName(address);
78
+ const words = (name.includes("@") ? name.split("@")[0]! : name).split(/[\s._-]+/).filter(Boolean);
79
+ return (words.length > 1 ? words[0]![0]! + words[1]![0]! : (words[0] ?? "?").slice(0, 2)).toUpperCase();
80
+ }
81
+
82
+ export interface Mailbox {
83
+ id: string;
84
+ address: string;
85
+ }
86
+
87
+ export interface LayoutOptions {
88
+ theme: Theme;
89
+ page: Page;
90
+ signedIn: boolean;
91
+ draftCount?: number;
92
+ domains?: string[];
93
+ /** Mailboxes the session can send from; New mail shows only when there is one. */
94
+ senders?: Mailbox[];
95
+ /** Thread pages fill the screen on a phone, so the tab bar gives way to the reply box. */
96
+ fullScreen?: boolean;
97
+ }
98
+
99
+ export function layout(title: string, body: View, opts: LayoutOptions): View {
100
+ const link = (page: Page, href: string, label: string, name: keyof typeof ICONS, extra: View | "" = "") =>
101
+ h`<a href="${href}" ${raw(opts.page === page ? 'aria-current="page"' : "")}>${icon(name)}<span>${label}</span>${extra}</a>`;
102
+ const count = opts.draftCount ? h`<span class="count">${opts.draftCount}</span>` : "";
103
+ const canSend = !!opts.senders?.length;
36
104
  return h`<!doctype html>
37
105
  <html lang="en" ${raw(opts.theme === "system" ? "" : `data-theme="${opts.theme}"`)}>
38
106
  <head>
39
107
  <meta charset="utf-8">
40
- <meta name="viewport" content="width=device-width, initial-scale=1">
108
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
41
109
  <title>${title} · ${S.appName}</title>
42
110
  <link rel="stylesheet" href="${ASSETS["style.css"]!.url}">
43
111
  <script src="${ASSETS["htmx.min.js"]!.url}" defer></script>
44
112
  <script src="${ASSETS["app.js"]!.url}" defer></script>
45
113
  </head>
46
- <body>
47
- ${when(opts.signedIn, () => h`<header>
48
- <nav>
49
- ${nav("drafts", "/", S.navDrafts, opts.draftCount ? h` <span class="count">${opts.draftCount}</span>` : "")}
50
- ${nav("inbox", "/inbox", S.navInbox)}
51
- ${nav("devices", "/devices", S.navDevices)}
114
+ <body class="${opts.signedIn ? "app" : ""} ${opts.fullScreen ? "full" : ""}">
115
+ ${when(opts.signedIn, () => h`<aside class="sidebar">
116
+ <div class="brand">${S.appName}<span>.</span></div>
117
+ ${when(opts.domains?.length, () => h`<div class="domain">${opts.domains!.join(" · ")}</div>`)}
118
+ ${when(canSend, () => h`<button type="button" class="primary new-mail" data-compose>${icon("plus")}${S.newMail}</button>`)}
119
+ <nav class="side-nav" aria-label="${S.mainNav}">
120
+ ${link("drafts", "/", S.navDrafts, "drafts", count)}
121
+ ${link("inbox", "/inbox", S.navInbox, "inbox")}
122
+ ${link("devices", "/devices", S.navDevices, "devices")}
52
123
  </nav>
53
- <form method="post" action="/theme">
54
- <span class="select"><select name="theme" aria-label="${S.theme}" onchange="this.form.submit()">
55
- ${join((["system", "light", "dark"] as const).map(t =>
56
- h`<option value="${t}" ${raw(t === opts.theme ? "selected" : "")}>${{ system: S.themeSystem, light: S.themeLight, dark: S.themeDark }[t]}</option>`))}
57
- </select></span>
58
- </form>
59
- <form method="post" action="/logout"><button class="link">${S.logout}</button></form>
60
- </header>`)}
61
- <main>${when(opts.domains?.length, () => h`<div class="domain">${opts.domains!.join(" · ")}</div>`)}${body}</main>
124
+ <nav class="side-nav side-end" aria-label="${S.navSettings}">${link("settings", "/settings", S.navSettings, "settings")}</nav>
125
+ </aside>`)}
126
+ <main>${body}</main>
127
+ ${when(opts.signedIn, () => h`<nav class="tabbar" aria-label="${S.mainNav}">
128
+ ${link("drafts", "/", S.navDrafts, "drafts", count)}
129
+ ${link("inbox", "/inbox", S.navInbox, "inbox")}
130
+ ${when(canSend, () => h`<button type="button" class="tab-compose" data-compose aria-label="${S.newMail}"><span>${icon("plus")}</span></button>`)}
131
+ ${link("devices", "/devices", S.navDevices, "devices")}
132
+ ${link("settings", "/settings", S.navSettings, "settings")}
133
+ </nav>`)}
134
+ ${when(opts.signedIn && canSend, () => composeDialog(opts.senders!))}
62
135
  </body>
63
136
  </html>`;
64
137
  }
65
138
 
139
+ /** New mail, opened from the sidebar or the tab bar; a bottom sheet on a phone. */
140
+ function composeDialog(senders: Mailbox[]): View {
141
+ return h`<dialog class="sheet" id="compose" aria-label="${S.newMail}">
142
+ <form method="post" action="/compose">
143
+ <div class="grabber" aria-hidden="true"></div>
144
+ <button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
145
+ <div class="field compact">
146
+ <label for="compose-from">${S.from}</label>
147
+ ${senders.length > 1
148
+ ? h`<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h`<option value="${m.id}">${m.address}</option>`))}</select></span>`
149
+ : h`<input type="hidden" name="mailbox" value="${senders[0]!.id}"><output id="compose-from">${senders[0]!.address}</output>`}
150
+ </div>
151
+ <div class="field">
152
+ <label for="compose-to">${S.to}</label>
153
+ <input id="compose-to" name="to" autocomplete="off" required>
154
+ <button type="button" class="link" onclick="this.remove();var r=document.getElementById('compose-cc-row');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>
155
+ </div>
156
+ <div class="field" id="compose-cc-row" hidden>
157
+ <label for="compose-cc">${S.cc}</label>
158
+ <input id="compose-cc" name="cc" autocomplete="off">
159
+ </div>
160
+ <div class="field">
161
+ <label for="compose-subject">${S.subject}</label>
162
+ <input id="compose-subject" name="subject" required>
163
+ </div>
164
+ <textarea name="text" aria-label="${S.body}" required></textarea>
165
+ <div class="sheet-actions">
166
+ <button type="submit" name="action" value="save">${S.saveDraft}</button>
167
+ <button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
168
+ </div>
169
+ </form>
170
+ </dialog>`;
171
+ }
172
+
66
173
  export function message(lines: string[]): View {
67
174
  return h`<div class="centered">${join(lines.map(l => h`<p>${l}</p>`))}</div>`;
68
175
  }
@@ -76,7 +183,7 @@ export function signIn(token: string, valid: boolean): View {
76
183
  }
77
184
 
78
185
  function mailboxBadge(mailbox: string): View {
79
- return h`<span class="badge">${mailbox}</span>`;
186
+ return h`<span class="badge mailbox">${mailbox}</span>`;
80
187
  }
81
188
 
82
189
  const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
@@ -114,6 +221,12 @@ function withoutImagePlaceholders(m: MessageView): string {
114
221
  return text.replace(/\n{3,}/g, "\n\n").trim();
115
222
  }
116
223
 
224
+ function recipients(m: MessageView): View | "" {
225
+ if (!m.to.length && !m.cc.length) return "";
226
+ return h`<div class="meta">${when(m.to.length, () => h`<span>${S.to}: ${m.to.join(", ")}</span>`)}${when(m.cc.length, () => h`<span>${S.cc}: ${m.cc.join(", ")}</span>`)}</div>`;
227
+ }
228
+
229
+ /** A message in a draft's history on the Drafts page. */
117
230
  export function messageCard(m: MessageView): View {
118
231
  return h`<article class="card ${m.direction}">
119
232
  <div class="meta">
@@ -121,9 +234,22 @@ export function messageCard(m: MessageView): View {
121
234
  <span>${formatDate(m.date)}</span>
122
235
  ${when(m.direction === "out" && m.status !== "draft", () => h`<span>${m.status}</span>`)}
123
236
  </div>
124
- ${when(m.to.length || m.cc.length, () => h`<div class="meta">${when(m.to.length, () => h`<span>${S.to}: ${m.to.join(", ")}</span>`)}${when(m.cc.length, () => h`<span>${S.cc}: ${m.cc.join(", ")}</span>`)}</div>`)}
237
+ ${recipients(m)}
238
+ <pre class="body">${withoutImagePlaceholders(m)}</pre>
239
+ ${attachments(m)}
240
+ </article>`;
241
+ }
242
+
243
+ /** A message in a thread: received ones on the left, ours on the right. */
244
+ export function messageBubble(m: MessageView, showSender: boolean): View {
245
+ const mine = m.direction === "out";
246
+ const extra = m.cc.length || m.to.length > (mine ? 1 : 0);
247
+ return h`<article class="msg ${mine ? "mine" : "theirs"}" id="m-${m.id}">
248
+ ${when(showSender && !mine, () => h`<div class="msg-from">${displayName(m.from)}</div>`)}
249
+ ${extra ? recipients(m) : ""}
125
250
  <pre class="body">${withoutImagePlaceholders(m)}</pre>
126
251
  ${attachments(m)}
252
+ <span class="msg-time">${formatTime(m.date)}${mine ? ` · ${m.status}` : ""}</span>
127
253
  </article>`;
128
254
  }
129
255
 
@@ -132,19 +258,27 @@ export interface ContextView {
132
258
  contacts: Contact[];
133
259
  }
134
260
 
135
- /** Read-only context agents attached to the thread and its participants. */
136
- function contextBlock(ctx: ContextView | null): View | "" {
137
- if (!ctx) return "";
138
- const rows = [
139
- ...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
261
+ function contextRows(ctx: ContextView): { who: string; meta: Context["meta"]; note: string | null }[] {
262
+ return [
140
263
  ...(ctx.context ? [{ who: S.thisThread, meta: ctx.context.meta, note: ctx.context.note }] : []),
264
+ ...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
141
265
  ].filter(r => r.note || Object.keys(r.meta).length);
142
- if (!rows.length) return "";
143
- return h`<details class="context"><summary>${S.context}</summary>${join(rows.map(r => h`<section>
266
+ }
267
+
268
+ function contextSections(rows: ReturnType<typeof contextRows>): View {
269
+ return join(rows.map(r => h`<section>
144
270
  <div class="who">${r.who}</div>
145
271
  ${when(Object.keys(r.meta).length, () => h`<dl>${join(Object.entries(r.meta).map(([k, v]) => h`<dt>${k}</dt><dd>${String(v)}</dd>`))}</dl>`)}
146
272
  ${when(r.note, () => h`<p>${r.note}</p>`)}
147
- </section>`))}</details>`;
273
+ </section>`));
274
+ }
275
+
276
+ /** Read-only context agents attached to the thread and its participants, folded on a draft card. */
277
+ function contextBlock(ctx: ContextView | null): View | "" {
278
+ if (!ctx) return "";
279
+ const rows = contextRows(ctx);
280
+ if (!rows.length) return "";
281
+ return h`<details class="context"><summary>${S.context}</summary>${contextSections(rows)}</details>`;
148
282
  }
149
283
 
150
284
  /** A send or discard in its undo window; reloads itself when the window closes. */
@@ -159,25 +293,27 @@ function pendingCard(d: Message): View {
159
293
  </article>`;
160
294
  }
161
295
 
296
+ /** A draft for review: a card on the Drafts page, a bubble on our side of a thread. */
162
297
  export function draftCard(d: Message, history: MessageView[], ctx: ContextView | null): View {
163
298
  if (d.pending) return pendingCard(d);
164
- return h`<article class="card" id="draft-${d.id}">
299
+ return h`<article class="card draft" id="draft-${d.id}">
165
300
  <div class="meta">
166
- ${mailboxBadge(d.mailbox)}
167
301
  <span class="badge draft">${S.draft}</span>
168
- ${when(d.edited_by_human, () => h`<span>${S.editedByHuman}</span>`)}
169
- <span>${formatDate(d.created_at)}</span>
302
+ ${mailboxBadge(d.mailbox)}
303
+ <span>${d.edited_by_human ? S.editedByHuman : S.byAgent} · ${formatDate(d.created_at)}</span>
304
+ </div>
305
+ <div class="draft-head">
306
+ <div class="meta"><span>${S.to}: <strong>${d.to.join(", ")}</strong></span>${when(d.cc.length, () => h`<span>${S.cc}: ${d.cc.join(", ")}</span>`)}</div>
307
+ <div class="subject">${d.subject}</div>
170
308
  </div>
171
- <div class="meta"><span>${S.to}: <strong>${d.to.join(", ")}</strong></span>${when(d.cc.length, () => h`<span>${S.cc}: ${d.cc.join(", ")}</span>`)}</div>
172
- <div class="subject">${d.subject}</div>
173
309
  ${contextBlock(ctx)}
174
310
  ${when(d.note, () => h`<div class="note">${d.note}</div>`)}
175
311
  <pre class="body">${d.text}</pre>
176
312
  ${attachments(d)}
177
313
  <div class="actions">
314
+ <button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
178
315
  <button hx-get="/drafts/${d.id}/edit" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.edit}</button>
179
316
  <button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
180
- <button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
181
317
  </div>
182
318
  ${when(history.length, () => h`<details>
183
319
  <summary>${S.thread} (${history.length})</summary>
@@ -195,9 +331,9 @@ export interface DraftForm {
195
331
 
196
332
  export function draftEditor(d: Message, form: DraftForm, conflict: Message | null): View {
197
333
  const version = conflict ? conflict.version : d.version;
198
- return h`<article class="card ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
334
+ return h`<article class="card draft editing ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
199
335
  <div class="drop-hint">${S.dropFiles}</div>
200
- <div class="meta">${mailboxBadge(d.mailbox)}<span class="badge draft">${S.draft}</span></div>
336
+ <div class="meta"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
201
337
  ${when(d.note, () => h`<div class="note">${d.note}</div>`)}
202
338
  ${when(conflict, () => h`<p class="warn">${S.conflictTitle}</p><div class="subject">${S.yourVersion}</div>`)}
203
339
  <form hx-post="/drafts/${d.id}/save" hx-target="#draft-${d.id}" hx-swap="outerHTML">
@@ -218,9 +354,9 @@ export function draftEditor(d: Message, form: DraftForm, conflict: Message | nul
218
354
  <textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
219
355
  ${draftFiles(d, null)}
220
356
  <div class="actions">
357
+ <button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
221
358
  <button type="submit">${S.save}</button>
222
359
  <button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
223
- <button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
224
360
  </div>
225
361
  </form>
226
362
  ${when(conflict, () => h`<details open>
@@ -248,56 +384,117 @@ export function draftDone(id: string, text: string): View {
248
384
  }
249
385
 
250
386
  export function draftsPage(drafts: { draft: Message; history: MessageView[]; ctx: ContextView }[]): View {
251
- return h`<h1>${S.navDrafts}</h1>
252
- ${drafts.length ? join(drafts.map(d => draftCard(d.draft, d.history, d.ctx))) : h`<p class="empty">${S.draftsEmpty}</p>`}`;
253
- }
254
-
255
- export function inboxPage(threads: Thread[], mailboxes: string[], filter: { mailbox: string; status: string }, own: Set<string>): View {
256
- const tab = (status: string, label: string) => {
257
- const query = new URLSearchParams({ status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) });
258
- return h`<a href="/inbox?${query.toString()}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
259
- };
260
- return h`<h1>${S.navInbox}</h1>
261
- <form class="filters" method="get" action="/inbox">
262
- <input type="hidden" name="status" value="${filter.status}">
263
- <span class="select"><select name="mailbox" aria-label="${S.filter}" onchange="this.form.submit()">
264
- <option value="">${S.allMailboxes}</option>
265
- ${join(mailboxes.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
266
- </select></span>
267
- <nav class="tabs">${tab("unanswered", S.filterUnanswered)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
268
- </form>
269
- ${threads.length ? join(threads.map(t => threadRow(t, own))) : h`<p class="empty">${S.inboxEmpty}</p>`}`;
387
+ return h`<div class="page">
388
+ <h1>${S.navDrafts}</h1>
389
+ ${drafts.length ? join(drafts.map(d => draftCard(d.draft, d.history, d.ctx))) : h`<p class="empty">${S.draftsEmpty}</p>`}
390
+ </div>`;
270
391
  }
271
392
 
272
- function threadRow(t: Thread, own: Set<string>): View {
273
- return h`<a class="card thread-row" href="/threads/${t.id}">
274
- <div class="meta">
275
- ${mailboxBadge(t.mailbox)}
276
- ${when(t.unread, () => h`<span class="dot" title="${S.unread}"></span>`)}
277
- ${when(t.has_draft, () => h`<span class="badge draft">${S.hasDraft}</span>`)}
278
- <span>${formatDate(t.last_at)}</span>
279
- </div>
280
- <div class="subject">${t.subject || "—"}</div>
281
- <div class="meta"><span>${t.participants.filter(p => !own.has(p)).join(", ")}</span></div>
393
+ export interface InboxFilter {
394
+ mailbox: string;
395
+ status: string;
396
+ }
397
+
398
+ export function inboxQuery(filter: InboxFilter): string {
399
+ return new URLSearchParams({ status: filter.status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) }).toString();
400
+ }
401
+
402
+ /** The thread list; on a wide screen it stays beside the open thread. */
403
+ export function threadList(threads: Thread[], opts: { mailboxes: string[]; domains: string[]; filter: InboxFilter; own: Set<string>; current: string | null }): View {
404
+ const { filter } = opts;
405
+ const tab = (status: string, label: string) =>
406
+ h`<a class="chip" href="/inbox?${inboxQuery({ ...filter, status })}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
407
+ return h`<section class="list">
408
+ <header class="list-head">
409
+ <h1>${opts.domains.length ? opts.domains.join(" · ") : S.navInbox}</h1>
410
+ <form class="filters" method="get" action="/inbox">
411
+ <input type="hidden" name="status" value="${filter.status}">
412
+ <nav class="chips" aria-label="${S.filter}">${tab("unanswered", S.filterPending)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
413
+ ${when(opts.mailboxes.length > 1, () => h`<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.submit()">
414
+ <option value="">${S.allMailboxes}</option>
415
+ ${join(opts.mailboxes.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
416
+ </select></span>`)}
417
+ </form>
418
+ </header>
419
+ ${threads.length ? join(threads.map(t => threadRow(t, opts))) : h`<p class="empty">${S.inboxEmpty}</p>`}
420
+ </section>`;
421
+ }
422
+
423
+ function threadRow(t: Thread, opts: { mailboxes: string[]; filter: InboxFilter; own: Set<string>; current: string | null }): View {
424
+ const people = t.participants.filter(p => !opts.own.has(p));
425
+ return h`<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
426
+ <span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
427
+ <span class="row-main">
428
+ <span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
429
+ <span class="row-subject">${t.subject || "—"}</span>
430
+ ${when(t.has_draft || opts.mailboxes.length > 1 || t.unread, () => h`<span class="row-tags">
431
+ ${when(t.has_draft, () => h`<span class="badge draft">${S.hasDraft}</span>`)}
432
+ ${when(opts.mailboxes.length > 1, () => mailboxBadge(t.mailbox))}
433
+ ${when(t.unread, () => h`<span class="dot" title="${S.unread}"></span>`)}
434
+ </span>`)}
435
+ </span>
282
436
  </a>`;
283
437
  }
284
438
 
285
- export function threadPage(thread: Thread, items: View[], ctx: ContextView): View {
286
- return h`<h1>${thread.subject || "—"}</h1>
287
- <div class="meta thread-head">${mailboxBadge(thread.mailbox)}${archiveButton(thread)}</div>
288
- ${contextBlock(ctx)}
289
- <section class="messages">${join(items)}</section>`;
439
+ /** The thread list and the open thread side by side; a phone shows one of the two. */
440
+ export function inboxPage(list: View, thread: View | null): View {
441
+ return h`<div class="split ${thread ? "has-thread" : ""}">${list}<section class="pane">${thread ?? ""}</section></div>`;
442
+ }
443
+
444
+ export interface ThreadEntry {
445
+ at: string;
446
+ view: View;
447
+ }
448
+
449
+ /** The conversation, oldest first, with day separators, a reply box and the context panel. */
450
+ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: { filter: InboxFilter; own: Set<string>; reply: { allowed: boolean; replyAll: boolean } }): View {
451
+ const query = inboxQuery(opts.filter);
452
+ const rows = contextRows(ctx);
453
+ const people = thread.participants.filter(p => !opts.own.has(p));
454
+ const title = h`<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, thread.mailbox].join(" · ")}</span>`;
455
+ const items: View[] = [];
456
+ let day = "";
457
+ for (const entry of entries) {
458
+ const label = dayLabel(entry.at);
459
+ if (label !== day) items.push(h`<div class="day">${label}</div>`);
460
+ day = label;
461
+ items.push(entry.view);
462
+ }
463
+ return h`<div class="thread">
464
+ <header class="thread-head">
465
+ <a class="icon-btn back" href="/inbox?${query}" aria-label="${S.back}">${icon("back")}</a>
466
+ ${rows.length
467
+ ? h`<button type="button" class="thread-title" data-context-toggle aria-controls="context">${title}</button>`
468
+ : h`<div class="thread-title">${title}</div>`}
469
+ ${when(rows.length, () => h`<button type="button" class="context-btn" data-context-toggle aria-controls="context">${S.context}</button>`)}
470
+ ${archiveButton(thread)}
471
+ </header>
472
+ <div class="messages" data-scroll-end>${join(items)}</div>
473
+ ${when(opts.reply.allowed, () => h`<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
474
+ ${when(opts.reply.replyAll, () => h`<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
475
+ <textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
476
+ <button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
477
+ <button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
478
+ </form>`)}
479
+ ${when(rows.length, () => h`<aside class="context-panel" id="context" aria-label="${S.context}">
480
+ <div class="context-head"><h2>${S.context}</h2><button type="button" class="icon-btn" data-context-toggle aria-label="${S.close}">${icon("close")}</button></div>
481
+ <div class="context-body">${contextSections(rows)}</div>
482
+ </aside>
483
+ <div class="context-backdrop" data-context-toggle></div>`)}
484
+ </div>`;
290
485
  }
291
486
 
292
487
  export function archiveButton(thread: Thread): View {
488
+ const label = thread.archived ? S.unarchive : S.archive;
293
489
  return h`<form id="archive" hx-post="/threads/${thread.id}/archive" hx-swap="outerHTML">
294
490
  <input type="hidden" name="archived" value="${thread.archived ? "0" : "1"}">
295
- <button class="link">${thread.archived ? S.unarchive : S.archive}</button>
491
+ <button class="icon-btn" aria-label="${label}" title="${label}">${icon(thread.archived ? "unarchive" : "archive")}</button>
296
492
  </form>`;
297
493
  }
298
494
 
299
495
  export function devicesPage(sessions: Session[], currentId: string): View {
300
- return h`<h1>${S.navDevices}</h1>
496
+ return h`<div class="page">
497
+ <h1>${S.navDevices}</h1>
301
498
  ${sessions.length ? join(sessions.map(s => h`<article class="card" id="session-${s.id}">
302
499
  <div class="meta">
303
500
  <strong>${s.label ?? s.user_agent ?? S.unknownDevice}</strong>
@@ -311,5 +508,20 @@ ${sessions.length ? join(sessions.map(s => h`<article class="card" id="session-$
311
508
  <span>${S.createdBy}: ${s.created_by}</span>
312
509
  </div>
313
510
  ${when(s.id !== currentId, () => h`<div class="actions"><button class="danger" hx-post="/devices/${s.id}/revoke" hx-target="#session-${s.id}" hx-swap="delete">${S.revoke}</button></div>`)}
314
- </article>`)) : h`<p class="empty">${S.devicesEmpty}</p>`}`;
511
+ </article>`)) : h`<p class="empty">${S.devicesEmpty}</p>`}
512
+ </div>`;
513
+ }
514
+
515
+ export function settingsPage(theme: Theme): View {
516
+ return h`<div class="page">
517
+ <h1>${S.navSettings}</h1>
518
+ <form class="setting" method="post" action="/theme">
519
+ <label for="theme">${S.theme}</label>
520
+ <span class="select"><select id="theme" name="theme" onchange="this.form.submit()">
521
+ ${join((["system", "light", "dark"] as const).map(t =>
522
+ h`<option value="${t}" ${raw(t === theme ? "selected" : "")}>${{ system: S.themeSystem, light: S.themeLight, dark: S.themeDark }[t]}</option>`))}
523
+ </select></span>
524
+ </form>
525
+ <form class="setting" method="post" action="/logout"><button class="danger">${S.logout}</button></form>
526
+ </div>`;
315
527
  }