inboxer 0.2.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.
@@ -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.2.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",