inboxer 0.3.0 → 0.3.1

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/dist/ui/routes.js CHANGED
@@ -35,21 +35,32 @@ export function registerUi(app, mail, access, cfg) {
35
35
  to: m.to.filter(a => !own.has(bareAddress(a))),
36
36
  cc: m.cc.filter(a => !own.has(bareAddress(a))),
37
37
  });
38
- const page = async (c, title, body, current, status = 200) => {
38
+ /** Mailboxes a session can send from: every one in its scope but the catch-all. */
39
+ const senders = (session) => mail.listMailboxes(session.scope).filter(m => m.id !== CATCHALL);
40
+ const domainsOf = (session) => [...new Set(senders(session).map(m => domainOf(m.address)))];
41
+ const page = async (c, title, body, current, status = 200, fullScreen = false) => {
39
42
  const session = c.get("session");
40
- const draftCount = session ? (await mail.listDrafts(undefined, session.scope)).length : 0;
41
- const domains = session
42
- ? [...new Set(mail.listMailboxes(session.scope).filter(m => m.id !== CATCHALL).map(m => domainOf(m.address)))]
43
- : [];
44
- return c.html(V.layout(title, body, { theme: theme(c), page: current, draftCount, signedIn: !!session, domains }), status);
43
+ const shell = session
44
+ ? { draftCount: (await mail.listDrafts(undefined, session.scope)).length, domains: domainsOf(session), senders: senders(session) }
45
+ : {};
46
+ return c.html(V.layout(title, body, { theme: theme(c), page: current, signedIn: !!session, fullScreen, ...shell }), status);
45
47
  };
46
48
  // Sign-in: GET only shows a button, so link previews and scanners do not burn the link.
49
+ // A used or expired link on a browser that is already signed in just opens the app.
50
+ const signedInSession = async (c) => {
51
+ const value = await getSignedCookie(c, secret, SESSION_COOKIE);
52
+ return value ? access.authenticate(value) : null;
53
+ };
47
54
  app.get("/auth/:token", async (c) => {
48
55
  const valid = await access.isLinkValid(c.req.param("token"));
56
+ if (!valid && (await signedInSession(c)))
57
+ return c.redirect("/", 303);
49
58
  return page(c, S.signInTitle, V.signIn(c.req.param("token"), valid), null, valid ? 200 : 404);
50
59
  });
51
60
  app.post("/auth/:token", async (c) => {
52
61
  const signedIn = await access.consumeLoginLink(c.req.param("token"), clientInfo(c));
62
+ if (!signedIn && (await signedInSession(c)))
63
+ return c.redirect("/", 303);
53
64
  if (!signedIn)
54
65
  return page(c, S.signInTitle, V.signIn("", false), null, 404);
55
66
  await setSignedCookie(c, SESSION_COOKIE, signedIn.secret, secret, cookieOptions);
@@ -64,7 +75,7 @@ export function registerUi(app, mail, access, cfg) {
64
75
  const path = back && new URL(back).origin === new URL(c.req.url).origin ? new URL(back).pathname + new URL(back).search : "/";
65
76
  return c.redirect(path, 303);
66
77
  });
67
- const ui = ["/", "/inbox", "/threads/*", "/drafts/*", "/attachments/*", "/devices", "/devices/*", "/logout"];
78
+ const ui = ["/", "/inbox", "/threads/*", "/drafts/*", "/attachments/*", "/compose", "/devices", "/devices/*", "/settings", "/logout"];
68
79
  for (const path of ui) {
69
80
  app.use(path, async (c, next) => {
70
81
  const value = await getSignedCookie(c, secret, SESSION_COOKIE);
@@ -175,27 +186,81 @@ export function registerUi(app, mail, access, cfg) {
175
186
  return c.html(await draftView(c, id));
176
187
  });
177
188
  }
178
- app.get("/inbox", async (c) => {
179
- const mailbox = c.req.query("mailbox") ?? "";
189
+ /** The inbox filter from the query, carried along when a thread opens beside the list. */
190
+ const inboxFilter = (c) => {
180
191
  const requested = c.req.query("status");
181
192
  const status = requested === "all" || requested === "archived" ? requested : "unanswered";
182
- const scope = c.get("session").scope;
183
- const threads = await mail.listThreads({ mailbox: mailbox || undefined, status, limit: 200 }, scope);
184
- const mailboxes = mail.listMailboxes(scope);
185
- const own = new Set(mailboxes.map(m => bareAddress(m.address)));
186
- return page(c, S.navInbox, V.inboxPage(threads, mailboxes.map(m => m.id), { mailbox, status }, own), "inbox");
187
- });
193
+ return { mailbox: c.req.query("mailbox") ?? "", status };
194
+ };
195
+ const threadList = async (c, current) => {
196
+ const session = c.get("session");
197
+ const filter = inboxFilter(c);
198
+ const threads = await mail.listThreads({ mailbox: filter.mailbox || undefined, status: filter.status, limit: 200 }, session.scope);
199
+ const mailboxes = mail.listMailboxes(session.scope).map(m => m.id);
200
+ return V.threadList(threads, { mailboxes, domains: domainsOf(session), filter, own, current });
201
+ };
202
+ app.get("/inbox", async (c) => page(c, S.navInbox, V.inboxPage(await threadList(c, null), null), "inbox"));
188
203
  app.get("/threads/:id", async (c) => {
189
204
  const id = c.req.param("id");
190
- const scope = c.get("session").scope;
191
- let thread = await mail.requireThread(id, scope);
205
+ const session = c.get("session");
206
+ let thread = await mail.requireThread(id, session.scope);
192
207
  if (thread.unread) {
193
- await mail.mark([id], { read: true }, uiActor(c.get("session")));
194
- thread = await mail.requireThread(id, scope);
208
+ await mail.mark([id], { read: true }, uiActor(session));
209
+ thread = await mail.requireThread(id, session.scope);
210
+ }
211
+ const { messages, context, contacts } = await mail.getThread(id, session.scope);
212
+ const people = thread.participants.filter(p => !own.has(p));
213
+ const entries = await Promise.all(messages.map(async (m) => ({
214
+ at: m.date,
215
+ view: m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id), [], null) : V.messageBubble(shown(m), people.length > 1),
216
+ })));
217
+ const reply = { allowed: senders(session).some(m => m.id === thread.mailbox), replyAll: people.length > 1 };
218
+ const view = V.threadView(thread, entries, { context, contacts }, { filter: inboxFilter(c), own, reply });
219
+ return page(c, thread.subject || S.navInbox, V.inboxPage(await threadList(c, id), view), "inbox", 200, true);
220
+ });
221
+ /** Replies to the latest message; a reply sent from here gets the same undo window as a draft. */
222
+ app.post("/threads/:id/reply", async (c) => {
223
+ const id = c.req.param("id");
224
+ const actor = uiActor(c.get("session"));
225
+ const body = await c.req.parseBody();
226
+ const text = String(body.text ?? "");
227
+ const { messages } = await mail.getThread(id, actor.scope);
228
+ const latest = messages.filter(m => m.status !== "draft").at(-1);
229
+ const back = `/threads/${id}?${V.inboxQuery(inboxFilter(c))}`;
230
+ if (!latest || !text.trim())
231
+ return c.redirect(back, 303);
232
+ try {
233
+ const draft = await mail.createDraft({ replyToId: latest.id, replyAll: body.reply_all === "1", text }, actor);
234
+ if (body.action === "send")
235
+ await mail.schedule(draft.id, "send", actor);
236
+ }
237
+ catch (err) {
238
+ if (err instanceof InvalidRequestError)
239
+ return page(c, S.reply, V.message([err.message]), "inbox", 400);
240
+ throw err;
241
+ }
242
+ return c.redirect(back, 303);
243
+ });
244
+ app.post("/compose", async (c) => {
245
+ const actor = uiActor(c.get("session"));
246
+ const body = await c.req.parseBody();
247
+ try {
248
+ const draft = await mail.createDraft({
249
+ mailbox: String(body.mailbox ?? ""),
250
+ to: splitAddresses(String(body.to ?? "")),
251
+ cc: splitAddresses(String(body.cc ?? "")),
252
+ subject: String(body.subject ?? ""),
253
+ text: String(body.text ?? ""),
254
+ }, actor);
255
+ if (body.action === "send")
256
+ await mail.schedule(draft.id, "send", actor);
257
+ return c.redirect(`/threads/${draft.thread_id}?status=all`, 303);
258
+ }
259
+ catch (err) {
260
+ if (err instanceof InvalidRequestError)
261
+ return page(c, S.newMail, V.message([err.message]), null, 400);
262
+ throw err;
195
263
  }
196
- const { messages, context, contacts } = await mail.getThread(id, scope);
197
- const items = await Promise.all([...messages].reverse().map(async (m) => m.status === "draft" ? V.draftCard(await mail.store.requireMessage(m.id), [], null) : V.messageCard(shown(m))));
198
- return page(c, thread.subject || S.navInbox, V.threadPage(thread, items, { context, contacts }), "inbox");
199
264
  });
200
265
  app.post("/threads/:id/archive", async (c) => {
201
266
  const id = c.req.param("id");
@@ -219,6 +284,7 @@ export function registerUi(app, mail, access, cfg) {
219
284
  const session = c.get("session");
220
285
  return page(c, S.navDevices, V.devicesPage(await access.listSessions(session.scope), session.id), "devices");
221
286
  });
287
+ app.get("/settings", async (c) => page(c, S.navSettings, V.settingsPage(theme(c)), "settings"));
222
288
  app.post("/devices/:id/revoke", async (c) => {
223
289
  await access.revokeSession(c.req.param("id"), uiActor(c.get("session")));
224
290
  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; }
@@ -4,6 +4,10 @@ export declare const S: {
4
4
  readonly navDrafts: "Drafts";
5
5
  readonly navInbox: "Inbox";
6
6
  readonly navDevices: "Devices";
7
+ readonly navSettings: "Settings";
8
+ readonly mainNav: "Main";
9
+ readonly back: "Back";
10
+ readonly close: "Close";
7
11
  readonly logout: "Log out";
8
12
  readonly themeSystem: "System";
9
13
  readonly themeLight: "Light";
@@ -32,6 +36,13 @@ export declare const S: {
32
36
  readonly sentTo: "Sent to";
33
37
  readonly discarded: "Draft discarded.";
34
38
  readonly editedByHuman: "Edited by you";
39
+ readonly byAgent: "By agent";
40
+ readonly newMail: "New mail";
41
+ readonly saveDraft: "Save draft";
42
+ readonly reply: "Reply";
43
+ readonly replyAll: "Reply all";
44
+ readonly today: "Today";
45
+ readonly yesterday: "Yesterday";
35
46
  readonly thread: "Thread";
36
47
  readonly thisThread: "This thread";
37
48
  readonly context: "Context";
@@ -39,7 +50,7 @@ export declare const S: {
39
50
  readonly conflictTitle: "This draft changed while you were editing.";
40
51
  readonly yourVersion: "Your version";
41
52
  readonly currentVersion: "Current version";
42
- readonly filterUnanswered: "Unanswered";
53
+ readonly filterPending: "Pending";
43
54
  readonly filterAll: "All";
44
55
  readonly filterArchived: "Archived";
45
56
  readonly allMailboxes: "All mailboxes";
@@ -49,7 +60,6 @@ export declare const S: {
49
60
  readonly hasDraft: "draft";
50
61
  readonly archive: "Archive";
51
62
  readonly unarchive: "Move to inbox";
52
- readonly status: "Status";
53
63
  readonly devicesEmpty: "No signed-in devices.";
54
64
  readonly thisDevice: "This device";
55
65
  readonly revoke: "Revoke";
@@ -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",
@@ -32,6 +36,13 @@ export const S = {
32
36
  sentTo: "Sent to",
33
37
  discarded: "Draft discarded.",
34
38
  editedByHuman: "Edited by you",
39
+ byAgent: "By agent",
40
+ newMail: "New mail",
41
+ saveDraft: "Save draft",
42
+ reply: "Reply",
43
+ replyAll: "Reply all",
44
+ today: "Today",
45
+ yesterday: "Yesterday",
35
46
  thread: "Thread",
36
47
  thisThread: "This thread",
37
48
  context: "Context",
@@ -39,7 +50,7 @@ export const S = {
39
50
  conflictTitle: "This draft changed while you were editing.",
40
51
  yourVersion: "Your version",
41
52
  currentVersion: "Current version",
42
- filterUnanswered: "Unanswered",
53
+ filterPending: "Pending",
43
54
  filterAll: "All",
44
55
  filterArchived: "Archived",
45
56
  allMailboxes: "All mailboxes",
@@ -49,7 +60,6 @@ export const S = {
49
60
  hasDraft: "draft",
50
61
  archive: "Archive",
51
62
  unarchive: "Move to inbox",
52
- status: "Status",
53
63
  devicesEmpty: "No signed-in devices.",
54
64
  thisDevice: "This device",
55
65
  revoke: "Revoke",
@@ -3,23 +3,36 @@ import type { MessageView } from "../core/mail.ts";
3
3
  import type { Contact, Context, Message, Session, Thread } from "../types.ts";
4
4
  export type View = HtmlEscapedString;
5
5
  export type Theme = "system" | "light" | "dark";
6
- export type Page = "drafts" | "inbox" | "devices" | null;
7
- export declare function layout(title: string, body: View, opts: {
6
+ export type Page = "drafts" | "inbox" | "devices" | "settings" | null;
7
+ export interface Mailbox {
8
+ id: string;
9
+ address: string;
10
+ }
11
+ export interface LayoutOptions {
8
12
  theme: Theme;
9
13
  page: Page;
10
- draftCount?: number;
11
14
  signedIn: boolean;
15
+ draftCount?: number;
12
16
  domains?: string[];
13
- }): View;
17
+ /** Mailboxes the session can send from; New mail shows only when there is one. */
18
+ senders?: Mailbox[];
19
+ /** Thread pages fill the screen on a phone, so the tab bar gives way to the reply box. */
20
+ fullScreen?: boolean;
21
+ }
22
+ export declare function layout(title: string, body: View, opts: LayoutOptions): View;
14
23
  export declare function message(lines: string[]): View;
15
24
  export declare function signIn(token: string, valid: boolean): View;
16
25
  /** Image types a browser renders without running code; SVG is left out on purpose. */
17
26
  export declare function isPreviewable(contentType: string): boolean;
27
+ /** A message in a draft's history on the Drafts page. */
18
28
  export declare function messageCard(m: MessageView): View;
29
+ /** A message in a thread: received ones on the left, ours on the right. */
30
+ export declare function messageBubble(m: MessageView, showSender: boolean): View;
19
31
  export interface ContextView {
20
32
  context: Context | null;
21
33
  contacts: Contact[];
22
34
  }
35
+ /** A draft for review: a card on the Drafts page, a bubble on our side of a thread. */
23
36
  export declare function draftCard(d: Message, history: MessageView[], ctx: ContextView | null): View;
24
37
  export interface DraftForm {
25
38
  to: string;
@@ -36,10 +49,34 @@ export declare function draftsPage(drafts: {
36
49
  history: MessageView[];
37
50
  ctx: ContextView;
38
51
  }[]): View;
39
- export declare function inboxPage(threads: Thread[], mailboxes: string[], filter: {
52
+ export interface InboxFilter {
40
53
  mailbox: string;
41
54
  status: string;
42
- }, own: Set<string>): View;
43
- export declare function threadPage(thread: Thread, items: View[], ctx: ContextView): View;
55
+ }
56
+ export declare function inboxQuery(filter: InboxFilter): string;
57
+ /** The thread list; on a wide screen it stays beside the open thread. */
58
+ export declare function threadList(threads: Thread[], opts: {
59
+ mailboxes: string[];
60
+ domains: string[];
61
+ filter: InboxFilter;
62
+ own: Set<string>;
63
+ current: string | null;
64
+ }): View;
65
+ /** The thread list and the open thread side by side; a phone shows one of the two. */
66
+ export declare function inboxPage(list: View, thread: View | null): View;
67
+ export interface ThreadEntry {
68
+ at: string;
69
+ view: View;
70
+ }
71
+ /** The conversation, oldest first, with day separators, a reply box and the context panel. */
72
+ export declare function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: {
73
+ filter: InboxFilter;
74
+ own: Set<string>;
75
+ reply: {
76
+ allowed: boolean;
77
+ replyAll: boolean;
78
+ };
79
+ }): View;
44
80
  export declare function archiveButton(thread: Thread): View;
45
81
  export declare function devicesPage(sessions: Session[], currentId: string): View;
82
+ export declare function settingsPage(theme: Theme): View;
package/dist/ui/views.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { html, raw } from "hono/html";
2
+ import { bareAddress } from "../core/address.js";
2
3
  import { ASSETS } from "./assets.js";
3
4
  import { S } from "./strings.js";
4
5
  /** Views never await, so `html` returns a plain escaped string. */
@@ -11,43 +12,126 @@ function join(items) {
11
12
  function when(condition, view) {
12
13
  return condition ? view() : "";
13
14
  }
14
- function formatDate(iso) {
15
+ const ICONS = {
16
+ back: '<path d="M15 18l-6-6 6-6"/>',
17
+ 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"/>',
18
+ 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"/>',
19
+ drafts: '<path d="M4 20h4L19 9l-4-4L4 16z"/><path d="M13 7l4 4"/>',
20
+ inbox: '<path d="M3 13l3-8h12l3 8v6a1 1 0 01-1 1H4a1 1 0 01-1-1z"/><path d="M3 13h5l1 3h6l1-3h5"/>',
21
+ plus: '<path d="M12 5v14M5 12h14"/>',
22
+ devices: '<rect x="6" y="2" width="12" height="20" rx="2"/><path d="M11 18h2"/>',
23
+ 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"/>',
24
+ send: '<path d="M5 12h14"/><path d="M13 6l6 6-6 6"/>',
25
+ close: '<path d="M6 6l12 12M18 6L6 18"/>',
26
+ };
27
+ function icon(name) {
28
+ 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>`);
29
+ }
30
+ const sameDay = (a, b) => a.toDateString() === b.toDateString();
31
+ function formatTime(iso) {
32
+ return new Date(iso).toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
33
+ }
34
+ function formatDay(iso) {
15
35
  const date = new Date(iso);
16
- const sameDay = date.toDateString() === new Date().toDateString();
17
- return sameDay
18
- ? date.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit" })
36
+ const now = new Date();
37
+ return date.getFullYear() === now.getFullYear()
38
+ ? date.toLocaleDateString("en", { month: "short", day: "numeric" })
19
39
  : date.toLocaleDateString("en", { month: "short", day: "numeric", year: "numeric" });
20
40
  }
41
+ /** A time today, a day otherwise. */
42
+ function formatDate(iso) {
43
+ return sameDay(new Date(iso), new Date()) ? formatTime(iso) : formatDay(iso);
44
+ }
45
+ function dayLabel(iso) {
46
+ const date = new Date(iso);
47
+ const yesterday = new Date(Date.now() - 86_400_000);
48
+ if (sameDay(date, new Date()))
49
+ return S.today;
50
+ if (sameDay(date, yesterday))
51
+ return S.yesterday;
52
+ return formatDay(iso);
53
+ }
54
+ /** Display name from `Name <a@b.com>`, else the bare address. */
55
+ function displayName(address) {
56
+ const match = /^\s*"?([^"<]+?)"?\s*</.exec(address);
57
+ return match ? match[1] : bareAddress(address);
58
+ }
59
+ function initials(address) {
60
+ const name = displayName(address);
61
+ const words = (name.includes("@") ? name.split("@")[0] : name).split(/[\s._-]+/).filter(Boolean);
62
+ return (words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? "?").slice(0, 2)).toUpperCase();
63
+ }
21
64
  export function layout(title, body, opts) {
22
- const nav = (page, href, label, extra = "") => h `<a href="${href}" ${raw(opts.page === page ? 'aria-current="page"' : "")}>${label}${extra}</a>`;
65
+ const link = (page, href, label, name, extra = "") => h `<a href="${href}" ${raw(opts.page === page ? 'aria-current="page"' : "")}>${icon(name)}<span>${label}</span>${extra}</a>`;
66
+ const count = opts.draftCount ? h `<span class="count">${opts.draftCount}</span>` : "";
67
+ const canSend = !!opts.senders?.length;
23
68
  return h `<!doctype html>
24
69
  <html lang="en" ${raw(opts.theme === "system" ? "" : `data-theme="${opts.theme}"`)}>
25
70
  <head>
26
71
  <meta charset="utf-8">
27
- <meta name="viewport" content="width=device-width, initial-scale=1">
72
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
28
73
  <title>${title} · ${S.appName}</title>
29
74
  <link rel="stylesheet" href="${ASSETS["style.css"].url}">
30
75
  <script src="${ASSETS["htmx.min.js"].url}" defer></script>
31
76
  <script src="${ASSETS["app.js"].url}" defer></script>
32
77
  </head>
33
- <body>
34
- ${when(opts.signedIn, () => h `<header>
35
- <nav>
36
- ${nav("drafts", "/", S.navDrafts, opts.draftCount ? h ` <span class="count">${opts.draftCount}</span>` : "")}
37
- ${nav("inbox", "/inbox", S.navInbox)}
38
- ${nav("devices", "/devices", S.navDevices)}
78
+ <body class="${opts.signedIn ? "app" : ""} ${opts.fullScreen ? "full" : ""}">
79
+ ${when(opts.signedIn, () => h `<aside class="sidebar">
80
+ <div class="brand">${S.appName}<span>.</span></div>
81
+ ${when(opts.domains?.length, () => h `<div class="domain">${opts.domains.join(" · ")}</div>`)}
82
+ ${when(canSend, () => h `<button type="button" class="primary new-mail" data-compose>${icon("plus")}${S.newMail}</button>`)}
83
+ <nav class="side-nav" aria-label="${S.mainNav}">
84
+ ${link("drafts", "/", S.navDrafts, "drafts", count)}
85
+ ${link("inbox", "/inbox", S.navInbox, "inbox")}
86
+ ${link("devices", "/devices", S.navDevices, "devices")}
39
87
  </nav>
40
- <form method="post" action="/theme">
41
- <span class="select"><select name="theme" aria-label="${S.theme}" onchange="this.form.submit()">
42
- ${join(["system", "light", "dark"].map(t => h `<option value="${t}" ${raw(t === opts.theme ? "selected" : "")}>${{ system: S.themeSystem, light: S.themeLight, dark: S.themeDark }[t]}</option>`))}
43
- </select></span>
44
- </form>
45
- <form method="post" action="/logout"><button class="link">${S.logout}</button></form>
46
- </header>`)}
47
- <main>${when(opts.domains?.length, () => h `<div class="domain">${opts.domains.join(" · ")}</div>`)}${body}</main>
88
+ <nav class="side-nav side-end" aria-label="${S.navSettings}">${link("settings", "/settings", S.navSettings, "settings")}</nav>
89
+ </aside>`)}
90
+ <main>${body}</main>
91
+ ${when(opts.signedIn, () => h `<nav class="tabbar" aria-label="${S.mainNav}">
92
+ ${link("drafts", "/", S.navDrafts, "drafts", count)}
93
+ ${link("inbox", "/inbox", S.navInbox, "inbox")}
94
+ ${when(canSend, () => h `<button type="button" class="tab-compose" data-compose aria-label="${S.newMail}"><span>${icon("plus")}</span></button>`)}
95
+ ${link("devices", "/devices", S.navDevices, "devices")}
96
+ ${link("settings", "/settings", S.navSettings, "settings")}
97
+ </nav>`)}
98
+ ${when(opts.signedIn && canSend, () => composeDialog(opts.senders))}
48
99
  </body>
49
100
  </html>`;
50
101
  }
102
+ /** New mail, opened from the sidebar or the tab bar; a bottom sheet on a phone. */
103
+ function composeDialog(senders) {
104
+ return h `<dialog class="sheet" id="compose" aria-label="${S.newMail}">
105
+ <form method="post" action="/compose">
106
+ <div class="grabber" aria-hidden="true"></div>
107
+ <button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
108
+ <div class="field compact">
109
+ <label for="compose-from">${S.from}</label>
110
+ ${senders.length > 1
111
+ ? h `<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h `<option value="${m.id}">${m.address}</option>`))}</select></span>`
112
+ : h `<input type="hidden" name="mailbox" value="${senders[0].id}"><output id="compose-from">${senders[0].address}</output>`}
113
+ </div>
114
+ <div class="field">
115
+ <label for="compose-to">${S.to}</label>
116
+ <input id="compose-to" name="to" autocomplete="off" required>
117
+ <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>
118
+ </div>
119
+ <div class="field" id="compose-cc-row" hidden>
120
+ <label for="compose-cc">${S.cc}</label>
121
+ <input id="compose-cc" name="cc" autocomplete="off">
122
+ </div>
123
+ <div class="field">
124
+ <label for="compose-subject">${S.subject}</label>
125
+ <input id="compose-subject" name="subject" required>
126
+ </div>
127
+ <textarea name="text" aria-label="${S.body}" required></textarea>
128
+ <div class="sheet-actions">
129
+ <button type="submit" name="action" value="save">${S.saveDraft}</button>
130
+ <button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
131
+ </div>
132
+ </form>
133
+ </dialog>`;
134
+ }
51
135
  export function message(lines) {
52
136
  return h `<div class="centered">${join(lines.map(l => h `<p>${l}</p>`))}</div>`;
53
137
  }
@@ -60,7 +144,7 @@ export function signIn(token, valid) {
60
144
  </div>`;
61
145
  }
62
146
  function mailboxBadge(mailbox) {
63
- return h `<span class="badge">${mailbox}</span>`;
147
+ return h `<span class="badge mailbox">${mailbox}</span>`;
64
148
  }
65
149
  const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
66
150
  /** Image types a browser renders without running code; SVG is left out on purpose. */
@@ -95,6 +179,12 @@ function withoutImagePlaceholders(m) {
95
179
  }
96
180
  return text.replace(/\n{3,}/g, "\n\n").trim();
97
181
  }
182
+ function recipients(m) {
183
+ if (!m.to.length && !m.cc.length)
184
+ return "";
185
+ 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>`;
186
+ }
187
+ /** A message in a draft's history on the Drafts page. */
98
188
  export function messageCard(m) {
99
189
  return h `<article class="card ${m.direction}">
100
190
  <div class="meta">
@@ -102,26 +192,44 @@ export function messageCard(m) {
102
192
  <span>${formatDate(m.date)}</span>
103
193
  ${when(m.direction === "out" && m.status !== "draft", () => h `<span>${m.status}</span>`)}
104
194
  </div>
105
- ${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>`)}
195
+ ${recipients(m)}
106
196
  <pre class="body">${withoutImagePlaceholders(m)}</pre>
107
197
  ${attachments(m)}
108
198
  </article>`;
109
199
  }
110
- /** Read-only context agents attached to the thread and its participants. */
111
- function contextBlock(ctx) {
112
- if (!ctx)
113
- return "";
114
- const rows = [
115
- ...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
200
+ /** A message in a thread: received ones on the left, ours on the right. */
201
+ export function messageBubble(m, showSender) {
202
+ const mine = m.direction === "out";
203
+ const extra = m.cc.length || m.to.length > (mine ? 1 : 0);
204
+ return h `<article class="msg ${mine ? "mine" : "theirs"}" id="m-${m.id}">
205
+ ${when(showSender && !mine, () => h `<div class="msg-from">${displayName(m.from)}</div>`)}
206
+ ${extra ? recipients(m) : ""}
207
+ <pre class="body">${withoutImagePlaceholders(m)}</pre>
208
+ ${attachments(m)}
209
+ <span class="msg-time">${formatTime(m.date)}${mine ? ` · ${m.status}` : ""}</span>
210
+ </article>`;
211
+ }
212
+ function contextRows(ctx) {
213
+ return [
116
214
  ...(ctx.context ? [{ who: S.thisThread, meta: ctx.context.meta, note: ctx.context.note }] : []),
215
+ ...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
117
216
  ].filter(r => r.note || Object.keys(r.meta).length);
118
- if (!rows.length)
119
- return "";
120
- return h `<details class="context"><summary>${S.context}</summary>${join(rows.map(r => h `<section>
217
+ }
218
+ function contextSections(rows) {
219
+ return join(rows.map(r => h `<section>
121
220
  <div class="who">${r.who}</div>
122
221
  ${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>`)}
123
222
  ${when(r.note, () => h `<p>${r.note}</p>`)}
124
- </section>`))}</details>`;
223
+ </section>`));
224
+ }
225
+ /** Read-only context agents attached to the thread and its participants, folded on a draft card. */
226
+ function contextBlock(ctx) {
227
+ if (!ctx)
228
+ return "";
229
+ const rows = contextRows(ctx);
230
+ if (!rows.length)
231
+ return "";
232
+ return h `<details class="context"><summary>${S.context}</summary>${contextSections(rows)}</details>`;
125
233
  }
126
234
  /** A send or discard in its undo window; reloads itself when the window closes. */
127
235
  function pendingCard(d) {
@@ -134,26 +242,28 @@ function pendingCard(d) {
134
242
  <i class="countdown" style="animation-duration: ${left}ms"></i>
135
243
  </article>`;
136
244
  }
245
+ /** A draft for review: a card on the Drafts page, a bubble on our side of a thread. */
137
246
  export function draftCard(d, history, ctx) {
138
247
  if (d.pending)
139
248
  return pendingCard(d);
140
- return h `<article class="card" id="draft-${d.id}">
249
+ return h `<article class="card draft" id="draft-${d.id}">
141
250
  <div class="meta">
142
- ${mailboxBadge(d.mailbox)}
143
251
  <span class="badge draft">${S.draft}</span>
144
- ${when(d.edited_by_human, () => h `<span>${S.editedByHuman}</span>`)}
145
- <span>${formatDate(d.created_at)}</span>
252
+ ${mailboxBadge(d.mailbox)}
253
+ <span>${d.edited_by_human ? S.editedByHuman : S.byAgent} · ${formatDate(d.created_at)}</span>
254
+ </div>
255
+ <div class="draft-head">
256
+ <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>
257
+ <div class="subject">${d.subject}</div>
146
258
  </div>
147
- <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>
148
- <div class="subject">${d.subject}</div>
149
259
  ${contextBlock(ctx)}
150
260
  ${when(d.note, () => h `<div class="note">${d.note}</div>`)}
151
261
  <pre class="body">${d.text}</pre>
152
262
  ${attachments(d)}
153
263
  <div class="actions">
264
+ <button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
154
265
  <button hx-get="/drafts/${d.id}/edit" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.edit}</button>
155
266
  <button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
156
- <button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
157
267
  </div>
158
268
  ${when(history.length, () => h `<details>
159
269
  <summary>${S.thread} (${history.length})</summary>
@@ -163,9 +273,9 @@ export function draftCard(d, history, ctx) {
163
273
  }
164
274
  export function draftEditor(d, form, conflict) {
165
275
  const version = conflict ? conflict.version : d.version;
166
- return h `<article class="card ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
276
+ return h `<article class="card draft editing ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
167
277
  <div class="drop-hint">${S.dropFiles}</div>
168
- <div class="meta">${mailboxBadge(d.mailbox)}<span class="badge draft">${S.draft}</span></div>
278
+ <div class="meta"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
169
279
  ${when(d.note, () => h `<div class="note">${d.note}</div>`)}
170
280
  ${when(conflict, () => h `<p class="warn">${S.conflictTitle}</p><div class="subject">${S.yourVersion}</div>`)}
171
281
  <form hx-post="/drafts/${d.id}/save" hx-target="#draft-${d.id}" hx-swap="outerHTML">
@@ -186,9 +296,9 @@ export function draftEditor(d, form, conflict) {
186
296
  <textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
187
297
  ${draftFiles(d, null)}
188
298
  <div class="actions">
299
+ <button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
189
300
  <button type="submit">${S.save}</button>
190
301
  <button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
191
- <button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
192
302
  </div>
193
303
  </form>
194
304
  ${when(conflict, () => h `<details open>
@@ -213,51 +323,100 @@ export function draftDone(id, text) {
213
323
  return h `<article class="card notice" id="draft-${id}">${text}</article>`;
214
324
  }
215
325
  export function draftsPage(drafts) {
216
- return h `<h1>${S.navDrafts}</h1>
217
- ${drafts.length ? join(drafts.map(d => draftCard(d.draft, d.history, d.ctx))) : h `<p class="empty">${S.draftsEmpty}</p>`}`;
218
- }
219
- export function inboxPage(threads, mailboxes, filter, own) {
220
- const tab = (status, label) => {
221
- const query = new URLSearchParams({ status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) });
222
- return h `<a href="/inbox?${query.toString()}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
223
- };
224
- return h `<h1>${S.navInbox}</h1>
225
- <form class="filters" method="get" action="/inbox">
226
- <input type="hidden" name="status" value="${filter.status}">
227
- <span class="select"><select name="mailbox" aria-label="${S.filter}" onchange="this.form.submit()">
228
- <option value="">${S.allMailboxes}</option>
229
- ${join(mailboxes.map(m => h `<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
230
- </select></span>
231
- <nav class="tabs">${tab("unanswered", S.filterUnanswered)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
232
- </form>
233
- ${threads.length ? join(threads.map(t => threadRow(t, own))) : h `<p class="empty">${S.inboxEmpty}</p>`}`;
326
+ return h `<div class="page">
327
+ <h1>${S.navDrafts}</h1>
328
+ ${drafts.length ? join(drafts.map(d => draftCard(d.draft, d.history, d.ctx))) : h `<p class="empty">${S.draftsEmpty}</p>`}
329
+ </div>`;
234
330
  }
235
- function threadRow(t, own) {
236
- return h `<a class="card thread-row" href="/threads/${t.id}">
237
- <div class="meta">
238
- ${mailboxBadge(t.mailbox)}
239
- ${when(t.unread, () => h `<span class="dot" title="${S.unread}"></span>`)}
240
- ${when(t.has_draft, () => h `<span class="badge draft">${S.hasDraft}</span>`)}
241
- <span>${formatDate(t.last_at)}</span>
242
- </div>
243
- <div class="subject">${t.subject || "—"}</div>
244
- <div class="meta"><span>${t.participants.filter(p => !own.has(p)).join(", ")}</span></div>
331
+ export function inboxQuery(filter) {
332
+ return new URLSearchParams({ status: filter.status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) }).toString();
333
+ }
334
+ /** The thread list; on a wide screen it stays beside the open thread. */
335
+ export function threadList(threads, opts) {
336
+ const { filter } = opts;
337
+ const tab = (status, label) => h `<a class="chip" href="/inbox?${inboxQuery({ ...filter, status })}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
338
+ return h `<section class="list">
339
+ <header class="list-head">
340
+ <h1>${opts.domains.length ? opts.domains.join(" · ") : S.navInbox}</h1>
341
+ <form class="filters" method="get" action="/inbox">
342
+ <input type="hidden" name="status" value="${filter.status}">
343
+ <nav class="chips" aria-label="${S.filter}">${tab("unanswered", S.filterPending)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
344
+ ${when(opts.mailboxes.length > 1, () => h `<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.submit()">
345
+ <option value="">${S.allMailboxes}</option>
346
+ ${join(opts.mailboxes.map(m => h `<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
347
+ </select></span>`)}
348
+ </form>
349
+ </header>
350
+ ${threads.length ? join(threads.map(t => threadRow(t, opts))) : h `<p class="empty">${S.inboxEmpty}</p>`}
351
+ </section>`;
352
+ }
353
+ function threadRow(t, opts) {
354
+ const people = t.participants.filter(p => !opts.own.has(p));
355
+ return h `<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
356
+ <span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
357
+ <span class="row-main">
358
+ <span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
359
+ <span class="row-subject">${t.subject || "—"}</span>
360
+ ${when(t.has_draft || opts.mailboxes.length > 1 || t.unread, () => h `<span class="row-tags">
361
+ ${when(t.has_draft, () => h `<span class="badge draft">${S.hasDraft}</span>`)}
362
+ ${when(opts.mailboxes.length > 1, () => mailboxBadge(t.mailbox))}
363
+ ${when(t.unread, () => h `<span class="dot" title="${S.unread}"></span>`)}
364
+ </span>`)}
365
+ </span>
245
366
  </a>`;
246
367
  }
247
- export function threadPage(thread, items, ctx) {
248
- return h `<h1>${thread.subject || "—"}</h1>
249
- <div class="meta thread-head">${mailboxBadge(thread.mailbox)}${archiveButton(thread)}</div>
250
- ${contextBlock(ctx)}
251
- <section class="messages">${join(items)}</section>`;
368
+ /** The thread list and the open thread side by side; a phone shows one of the two. */
369
+ export function inboxPage(list, thread) {
370
+ return h `<div class="split ${thread ? "has-thread" : ""}">${list}<section class="pane">${thread ?? ""}</section></div>`;
371
+ }
372
+ /** The conversation, oldest first, with day separators, a reply box and the context panel. */
373
+ export function threadView(thread, entries, ctx, opts) {
374
+ const query = inboxQuery(opts.filter);
375
+ const rows = contextRows(ctx);
376
+ const people = thread.participants.filter(p => !opts.own.has(p));
377
+ const title = h `<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, thread.mailbox].join(" · ")}</span>`;
378
+ const items = [];
379
+ let day = "";
380
+ for (const entry of entries) {
381
+ const label = dayLabel(entry.at);
382
+ if (label !== day)
383
+ items.push(h `<div class="day">${label}</div>`);
384
+ day = label;
385
+ items.push(entry.view);
386
+ }
387
+ return h `<div class="thread">
388
+ <header class="thread-head">
389
+ <a class="icon-btn back" href="/inbox?${query}" aria-label="${S.back}">${icon("back")}</a>
390
+ ${rows.length
391
+ ? h `<button type="button" class="thread-title" data-context-toggle aria-controls="context">${title}</button>`
392
+ : h `<div class="thread-title">${title}</div>`}
393
+ ${when(rows.length, () => h `<button type="button" class="context-btn" data-context-toggle aria-controls="context">${S.context}</button>`)}
394
+ ${archiveButton(thread)}
395
+ </header>
396
+ <div class="messages" data-scroll-end>${join(items)}</div>
397
+ ${when(opts.reply.allowed, () => h `<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
398
+ ${when(opts.reply.replyAll, () => h `<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
399
+ <textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
400
+ <button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
401
+ <button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
402
+ </form>`)}
403
+ ${when(rows.length, () => h `<aside class="context-panel" id="context" aria-label="${S.context}">
404
+ <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>
405
+ <div class="context-body">${contextSections(rows)}</div>
406
+ </aside>
407
+ <div class="context-backdrop" data-context-toggle></div>`)}
408
+ </div>`;
252
409
  }
253
410
  export function archiveButton(thread) {
411
+ const label = thread.archived ? S.unarchive : S.archive;
254
412
  return h `<form id="archive" hx-post="/threads/${thread.id}/archive" hx-swap="outerHTML">
255
413
  <input type="hidden" name="archived" value="${thread.archived ? "0" : "1"}">
256
- <button class="link">${thread.archived ? S.unarchive : S.archive}</button>
414
+ <button class="icon-btn" aria-label="${label}" title="${label}">${icon(thread.archived ? "unarchive" : "archive")}</button>
257
415
  </form>`;
258
416
  }
259
417
  export function devicesPage(sessions, currentId) {
260
- return h `<h1>${S.navDevices}</h1>
418
+ return h `<div class="page">
419
+ <h1>${S.navDevices}</h1>
261
420
  ${sessions.length ? join(sessions.map(s => h `<article class="card" id="session-${s.id}">
262
421
  <div class="meta">
263
422
  <strong>${s.label ?? s.user_agent ?? S.unknownDevice}</strong>
@@ -271,5 +430,18 @@ ${sessions.length ? join(sessions.map(s => h `<article class="card" id="session-
271
430
  <span>${S.createdBy}: ${s.created_by}</span>
272
431
  </div>
273
432
  ${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>`)}
274
- </article>`)) : h `<p class="empty">${S.devicesEmpty}</p>`}`;
433
+ </article>`)) : h `<p class="empty">${S.devicesEmpty}</p>`}
434
+ </div>`;
435
+ }
436
+ export function settingsPage(theme) {
437
+ return h `<div class="page">
438
+ <h1>${S.navSettings}</h1>
439
+ <form class="setting" method="post" action="/theme">
440
+ <label for="theme">${S.theme}</label>
441
+ <span class="select"><select id="theme" name="theme" onchange="this.form.submit()">
442
+ ${join(["system", "light", "dark"].map(t => h `<option value="${t}" ${raw(t === theme ? "selected" : "")}>${{ system: S.themeSystem, light: S.themeLight, dark: S.themeDark }[t]}</option>`))}
443
+ </select></span>
444
+ </form>
445
+ <form class="setting" method="post" action="/logout"><button class="danger">${S.logout}</button></form>
446
+ </div>`;
275
447
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inboxer",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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",