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.
- package/dist/ui/routes.js +88 -22
- package/dist/ui/static/app.js +27 -0
- package/dist/ui/static/style.css +276 -63
- package/dist/ui/strings.d.ts +12 -2
- package/dist/ui/strings.js +12 -2
- package/dist/ui/views.d.ts +44 -7
- package/dist/ui/views.js +250 -78
- package/package.json +1 -1
- package/src/ui/routes.ts +87 -24
- package/src/ui/static/app.js +27 -0
- package/src/ui/static/style.css +276 -63
- package/src/ui/strings.ts +12 -2
- package/src/ui/views.ts +293 -81
package/src/ui/strings.ts
CHANGED
|
@@ -4,6 +4,10 @@ export const S = {
|
|
|
4
4
|
navDrafts: "Drafts",
|
|
5
5
|
navInbox: "Inbox",
|
|
6
6
|
navDevices: "Devices",
|
|
7
|
+
navSettings: "Settings",
|
|
8
|
+
mainNav: "Main",
|
|
9
|
+
back: "Back",
|
|
10
|
+
close: "Close",
|
|
7
11
|
logout: "Log out",
|
|
8
12
|
themeSystem: "System",
|
|
9
13
|
themeLight: "Light",
|
|
@@ -33,6 +37,13 @@ export const S = {
|
|
|
33
37
|
sentTo: "Sent to",
|
|
34
38
|
discarded: "Draft discarded.",
|
|
35
39
|
editedByHuman: "Edited by you",
|
|
40
|
+
byAgent: "By agent",
|
|
41
|
+
newMail: "New mail",
|
|
42
|
+
saveDraft: "Save draft",
|
|
43
|
+
reply: "Reply",
|
|
44
|
+
replyAll: "Reply all",
|
|
45
|
+
today: "Today",
|
|
46
|
+
yesterday: "Yesterday",
|
|
36
47
|
thread: "Thread",
|
|
37
48
|
thisThread: "This thread",
|
|
38
49
|
context: "Context",
|
|
@@ -42,7 +53,7 @@ export const S = {
|
|
|
42
53
|
yourVersion: "Your version",
|
|
43
54
|
currentVersion: "Current version",
|
|
44
55
|
|
|
45
|
-
|
|
56
|
+
filterPending: "Pending",
|
|
46
57
|
filterAll: "All",
|
|
47
58
|
filterArchived: "Archived",
|
|
48
59
|
allMailboxes: "All mailboxes",
|
|
@@ -53,7 +64,6 @@ export const S = {
|
|
|
53
64
|
|
|
54
65
|
archive: "Archive",
|
|
55
66
|
unarchive: "Move to inbox",
|
|
56
|
-
status: "Status",
|
|
57
67
|
|
|
58
68
|
devicesEmpty: "No signed-in devices.",
|
|
59
69
|
thisDevice: "This device",
|
package/src/ui/views.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { html, raw } from "hono/html";
|
|
2
2
|
import type { HtmlEscapedString } from "hono/utils/html";
|
|
3
|
+
import { bareAddress } from "../core/address.ts";
|
|
3
4
|
import type { MessageView } from "../core/mail.ts";
|
|
4
5
|
import type { Contact, Context, Message, Session, Thread } from "../types.ts";
|
|
5
6
|
import { ASSETS } from "./assets.ts";
|
|
@@ -7,7 +8,7 @@ import { S } from "./strings.ts";
|
|
|
7
8
|
|
|
8
9
|
export type View = HtmlEscapedString;
|
|
9
10
|
export type Theme = "system" | "light" | "dark";
|
|
10
|
-
export type Page = "drafts" | "inbox" | "devices" | null;
|
|
11
|
+
export type Page = "drafts" | "inbox" | "devices" | "settings" | null;
|
|
11
12
|
|
|
12
13
|
/** Views never await, so `html` returns a plain escaped string. */
|
|
13
14
|
function h(strings: TemplateStringsArray, ...values: unknown[]): View {
|
|
@@ -22,47 +23,153 @@ function when(condition: unknown, view: () => View): View | "" {
|
|
|
22
23
|
return condition ? view() : "";
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
const ICONS = {
|
|
27
|
+
back: '<path d="M15 18l-6-6 6-6"/>',
|
|
28
|
+
archive: '<rect x="3" y="4" width="18" height="5" rx="1"/><path d="M5 9v10a1 1 0 001 1h12a1 1 0 001-1V9"/><path d="M10 13h4"/>',
|
|
29
|
+
unarchive: '<rect x="3" y="4" width="18" height="5" rx="1"/><path d="M5 9v10a1 1 0 001 1h12a1 1 0 001-1V9"/><path d="M12 17v-5M9.5 14.5L12 12l2.5 2.5"/>',
|
|
30
|
+
drafts: '<path d="M4 20h4L19 9l-4-4L4 16z"/><path d="M13 7l4 4"/>',
|
|
31
|
+
inbox: '<path d="M3 13l3-8h12l3 8v6a1 1 0 01-1 1H4a1 1 0 01-1-1z"/><path d="M3 13h5l1 3h6l1-3h5"/>',
|
|
32
|
+
plus: '<path d="M12 5v14M5 12h14"/>',
|
|
33
|
+
devices: '<rect x="6" y="2" width="12" height="20" rx="2"/><path d="M11 18h2"/>',
|
|
34
|
+
settings: '<circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M2 12h3M19 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1"/>',
|
|
35
|
+
send: '<path d="M5 12h14"/><path d="M13 6l6 6-6 6"/>',
|
|
36
|
+
close: '<path d="M6 6l12 12M18 6L6 18"/>',
|
|
37
|
+
} as const;
|
|
38
|
+
|
|
39
|
+
function icon(name: keyof typeof ICONS): View {
|
|
40
|
+
return raw(`<svg class="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[name]}</svg>`) as View;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const sameDay = (a: Date, b: Date) => a.toDateString() === b.toDateString();
|
|
44
|
+
|
|
45
|
+
function formatTime(iso: string): string {
|
|
46
|
+
return new Date(iso).toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function formatDay(iso: string): string {
|
|
26
50
|
const date = new Date(iso);
|
|
27
|
-
const
|
|
28
|
-
return
|
|
29
|
-
? date.
|
|
51
|
+
const now = new Date();
|
|
52
|
+
return date.getFullYear() === now.getFullYear()
|
|
53
|
+
? date.toLocaleDateString("en", { month: "short", day: "numeric" })
|
|
30
54
|
: date.toLocaleDateString("en", { month: "short", day: "numeric", year: "numeric" });
|
|
31
55
|
}
|
|
32
56
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
57
|
+
/** A time today, a day otherwise. */
|
|
58
|
+
function formatDate(iso: string): string {
|
|
59
|
+
return sameDay(new Date(iso), new Date()) ? formatTime(iso) : formatDay(iso);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function dayLabel(iso: string): string {
|
|
63
|
+
const date = new Date(iso);
|
|
64
|
+
const yesterday = new Date(Date.now() - 86_400_000);
|
|
65
|
+
if (sameDay(date, new Date())) return S.today;
|
|
66
|
+
if (sameDay(date, yesterday)) return S.yesterday;
|
|
67
|
+
return formatDay(iso);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Display name from `Name <a@b.com>`, else the bare address. */
|
|
71
|
+
function displayName(address: string): string {
|
|
72
|
+
const match = /^\s*"?([^"<]+?)"?\s*</.exec(address);
|
|
73
|
+
return match ? match[1]! : bareAddress(address);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function initials(address: string): string {
|
|
77
|
+
const name = displayName(address);
|
|
78
|
+
const words = (name.includes("@") ? name.split("@")[0]! : name).split(/[\s._-]+/).filter(Boolean);
|
|
79
|
+
return (words.length > 1 ? words[0]![0]! + words[1]![0]! : (words[0] ?? "?").slice(0, 2)).toUpperCase();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface Mailbox {
|
|
83
|
+
id: string;
|
|
84
|
+
address: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface LayoutOptions {
|
|
88
|
+
theme: Theme;
|
|
89
|
+
page: Page;
|
|
90
|
+
signedIn: boolean;
|
|
91
|
+
draftCount?: number;
|
|
92
|
+
domains?: string[];
|
|
93
|
+
/** Mailboxes the session can send from; New mail shows only when there is one. */
|
|
94
|
+
senders?: Mailbox[];
|
|
95
|
+
/** Thread pages fill the screen on a phone, so the tab bar gives way to the reply box. */
|
|
96
|
+
fullScreen?: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function layout(title: string, body: View, opts: LayoutOptions): View {
|
|
100
|
+
const link = (page: Page, href: string, label: string, name: keyof typeof ICONS, extra: View | "" = "") =>
|
|
101
|
+
h`<a href="${href}" ${raw(opts.page === page ? 'aria-current="page"' : "")}>${icon(name)}<span>${label}</span>${extra}</a>`;
|
|
102
|
+
const count = opts.draftCount ? h`<span class="count">${opts.draftCount}</span>` : "";
|
|
103
|
+
const canSend = !!opts.senders?.length;
|
|
36
104
|
return h`<!doctype html>
|
|
37
105
|
<html lang="en" ${raw(opts.theme === "system" ? "" : `data-theme="${opts.theme}"`)}>
|
|
38
106
|
<head>
|
|
39
107
|
<meta charset="utf-8">
|
|
40
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
108
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
41
109
|
<title>${title} · ${S.appName}</title>
|
|
42
110
|
<link rel="stylesheet" href="${ASSETS["style.css"]!.url}">
|
|
43
111
|
<script src="${ASSETS["htmx.min.js"]!.url}" defer></script>
|
|
44
112
|
<script src="${ASSETS["app.js"]!.url}" defer></script>
|
|
45
113
|
</head>
|
|
46
|
-
<body>
|
|
47
|
-
${when(opts.signedIn, () => h`<
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
114
|
+
<body class="${opts.signedIn ? "app" : ""} ${opts.fullScreen ? "full" : ""}">
|
|
115
|
+
${when(opts.signedIn, () => h`<aside class="sidebar">
|
|
116
|
+
<div class="brand">${S.appName}<span>.</span></div>
|
|
117
|
+
${when(opts.domains?.length, () => h`<div class="domain">${opts.domains!.join(" · ")}</div>`)}
|
|
118
|
+
${when(canSend, () => h`<button type="button" class="primary new-mail" data-compose>${icon("plus")}${S.newMail}</button>`)}
|
|
119
|
+
<nav class="side-nav" aria-label="${S.mainNav}">
|
|
120
|
+
${link("drafts", "/", S.navDrafts, "drafts", count)}
|
|
121
|
+
${link("inbox", "/inbox", S.navInbox, "inbox")}
|
|
122
|
+
${link("devices", "/devices", S.navDevices, "devices")}
|
|
52
123
|
</nav>
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
124
|
+
<nav class="side-nav side-end" aria-label="${S.navSettings}">${link("settings", "/settings", S.navSettings, "settings")}</nav>
|
|
125
|
+
</aside>`)}
|
|
126
|
+
<main>${body}</main>
|
|
127
|
+
${when(opts.signedIn, () => h`<nav class="tabbar" aria-label="${S.mainNav}">
|
|
128
|
+
${link("drafts", "/", S.navDrafts, "drafts", count)}
|
|
129
|
+
${link("inbox", "/inbox", S.navInbox, "inbox")}
|
|
130
|
+
${when(canSend, () => h`<button type="button" class="tab-compose" data-compose aria-label="${S.newMail}"><span>${icon("plus")}</span></button>`)}
|
|
131
|
+
${link("devices", "/devices", S.navDevices, "devices")}
|
|
132
|
+
${link("settings", "/settings", S.navSettings, "settings")}
|
|
133
|
+
</nav>`)}
|
|
134
|
+
${when(opts.signedIn && canSend, () => composeDialog(opts.senders!))}
|
|
62
135
|
</body>
|
|
63
136
|
</html>`;
|
|
64
137
|
}
|
|
65
138
|
|
|
139
|
+
/** New mail, opened from the sidebar or the tab bar; a bottom sheet on a phone. */
|
|
140
|
+
function composeDialog(senders: Mailbox[]): View {
|
|
141
|
+
return h`<dialog class="sheet" id="compose" aria-label="${S.newMail}">
|
|
142
|
+
<form method="post" action="/compose">
|
|
143
|
+
<div class="grabber" aria-hidden="true"></div>
|
|
144
|
+
<button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
|
|
145
|
+
<div class="field compact">
|
|
146
|
+
<label for="compose-from">${S.from}</label>
|
|
147
|
+
${senders.length > 1
|
|
148
|
+
? h`<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h`<option value="${m.id}">${m.address}</option>`))}</select></span>`
|
|
149
|
+
: h`<input type="hidden" name="mailbox" value="${senders[0]!.id}"><output id="compose-from">${senders[0]!.address}</output>`}
|
|
150
|
+
</div>
|
|
151
|
+
<div class="field">
|
|
152
|
+
<label for="compose-to">${S.to}</label>
|
|
153
|
+
<input id="compose-to" name="to" autocomplete="off" required>
|
|
154
|
+
<button type="button" class="link" onclick="this.remove();var r=document.getElementById('compose-cc-row');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>
|
|
155
|
+
</div>
|
|
156
|
+
<div class="field" id="compose-cc-row" hidden>
|
|
157
|
+
<label for="compose-cc">${S.cc}</label>
|
|
158
|
+
<input id="compose-cc" name="cc" autocomplete="off">
|
|
159
|
+
</div>
|
|
160
|
+
<div class="field">
|
|
161
|
+
<label for="compose-subject">${S.subject}</label>
|
|
162
|
+
<input id="compose-subject" name="subject" required>
|
|
163
|
+
</div>
|
|
164
|
+
<textarea name="text" aria-label="${S.body}" required></textarea>
|
|
165
|
+
<div class="sheet-actions">
|
|
166
|
+
<button type="submit" name="action" value="save">${S.saveDraft}</button>
|
|
167
|
+
<button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
|
|
168
|
+
</div>
|
|
169
|
+
</form>
|
|
170
|
+
</dialog>`;
|
|
171
|
+
}
|
|
172
|
+
|
|
66
173
|
export function message(lines: string[]): View {
|
|
67
174
|
return h`<div class="centered">${join(lines.map(l => h`<p>${l}</p>`))}</div>`;
|
|
68
175
|
}
|
|
@@ -76,7 +183,7 @@ export function signIn(token: string, valid: boolean): View {
|
|
|
76
183
|
}
|
|
77
184
|
|
|
78
185
|
function mailboxBadge(mailbox: string): View {
|
|
79
|
-
return h`<span class="badge">${mailbox}</span>`;
|
|
186
|
+
return h`<span class="badge mailbox">${mailbox}</span>`;
|
|
80
187
|
}
|
|
81
188
|
|
|
82
189
|
const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
|
|
@@ -114,6 +221,12 @@ function withoutImagePlaceholders(m: MessageView): string {
|
|
|
114
221
|
return text.replace(/\n{3,}/g, "\n\n").trim();
|
|
115
222
|
}
|
|
116
223
|
|
|
224
|
+
function recipients(m: MessageView): View | "" {
|
|
225
|
+
if (!m.to.length && !m.cc.length) return "";
|
|
226
|
+
return h`<div class="meta">${when(m.to.length, () => h`<span>${S.to}: ${m.to.join(", ")}</span>`)}${when(m.cc.length, () => h`<span>${S.cc}: ${m.cc.join(", ")}</span>`)}</div>`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** A message in a draft's history on the Drafts page. */
|
|
117
230
|
export function messageCard(m: MessageView): View {
|
|
118
231
|
return h`<article class="card ${m.direction}">
|
|
119
232
|
<div class="meta">
|
|
@@ -121,9 +234,22 @@ export function messageCard(m: MessageView): View {
|
|
|
121
234
|
<span>${formatDate(m.date)}</span>
|
|
122
235
|
${when(m.direction === "out" && m.status !== "draft", () => h`<span>${m.status}</span>`)}
|
|
123
236
|
</div>
|
|
124
|
-
${
|
|
237
|
+
${recipients(m)}
|
|
238
|
+
<pre class="body">${withoutImagePlaceholders(m)}</pre>
|
|
239
|
+
${attachments(m)}
|
|
240
|
+
</article>`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** A message in a thread: received ones on the left, ours on the right. */
|
|
244
|
+
export function messageBubble(m: MessageView, showSender: boolean): View {
|
|
245
|
+
const mine = m.direction === "out";
|
|
246
|
+
const extra = m.cc.length || m.to.length > (mine ? 1 : 0);
|
|
247
|
+
return h`<article class="msg ${mine ? "mine" : "theirs"}" id="m-${m.id}">
|
|
248
|
+
${when(showSender && !mine, () => h`<div class="msg-from">${displayName(m.from)}</div>`)}
|
|
249
|
+
${extra ? recipients(m) : ""}
|
|
125
250
|
<pre class="body">${withoutImagePlaceholders(m)}</pre>
|
|
126
251
|
${attachments(m)}
|
|
252
|
+
<span class="msg-time">${formatTime(m.date)}${mine ? ` · ${m.status}` : ""}</span>
|
|
127
253
|
</article>`;
|
|
128
254
|
}
|
|
129
255
|
|
|
@@ -132,19 +258,27 @@ export interface ContextView {
|
|
|
132
258
|
contacts: Contact[];
|
|
133
259
|
}
|
|
134
260
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (!ctx) return "";
|
|
138
|
-
const rows = [
|
|
139
|
-
...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
|
|
261
|
+
function contextRows(ctx: ContextView): { who: string; meta: Context["meta"]; note: string | null }[] {
|
|
262
|
+
return [
|
|
140
263
|
...(ctx.context ? [{ who: S.thisThread, meta: ctx.context.meta, note: ctx.context.note }] : []),
|
|
264
|
+
...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
|
|
141
265
|
].filter(r => r.note || Object.keys(r.meta).length);
|
|
142
|
-
|
|
143
|
-
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function contextSections(rows: ReturnType<typeof contextRows>): View {
|
|
269
|
+
return join(rows.map(r => h`<section>
|
|
144
270
|
<div class="who">${r.who}</div>
|
|
145
271
|
${when(Object.keys(r.meta).length, () => h`<dl>${join(Object.entries(r.meta).map(([k, v]) => h`<dt>${k}</dt><dd>${String(v)}</dd>`))}</dl>`)}
|
|
146
272
|
${when(r.note, () => h`<p>${r.note}</p>`)}
|
|
147
|
-
</section>`))
|
|
273
|
+
</section>`));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Read-only context agents attached to the thread and its participants, folded on a draft card. */
|
|
277
|
+
function contextBlock(ctx: ContextView | null): View | "" {
|
|
278
|
+
if (!ctx) return "";
|
|
279
|
+
const rows = contextRows(ctx);
|
|
280
|
+
if (!rows.length) return "";
|
|
281
|
+
return h`<details class="context"><summary>${S.context}</summary>${contextSections(rows)}</details>`;
|
|
148
282
|
}
|
|
149
283
|
|
|
150
284
|
/** A send or discard in its undo window; reloads itself when the window closes. */
|
|
@@ -159,25 +293,27 @@ function pendingCard(d: Message): View {
|
|
|
159
293
|
</article>`;
|
|
160
294
|
}
|
|
161
295
|
|
|
296
|
+
/** A draft for review: a card on the Drafts page, a bubble on our side of a thread. */
|
|
162
297
|
export function draftCard(d: Message, history: MessageView[], ctx: ContextView | null): View {
|
|
163
298
|
if (d.pending) return pendingCard(d);
|
|
164
|
-
return h`<article class="card" id="draft-${d.id}">
|
|
299
|
+
return h`<article class="card draft" id="draft-${d.id}">
|
|
165
300
|
<div class="meta">
|
|
166
|
-
${mailboxBadge(d.mailbox)}
|
|
167
301
|
<span class="badge draft">${S.draft}</span>
|
|
168
|
-
${
|
|
169
|
-
<span>${formatDate(d.created_at)}</span>
|
|
302
|
+
${mailboxBadge(d.mailbox)}
|
|
303
|
+
<span>${d.edited_by_human ? S.editedByHuman : S.byAgent} · ${formatDate(d.created_at)}</span>
|
|
304
|
+
</div>
|
|
305
|
+
<div class="draft-head">
|
|
306
|
+
<div class="meta"><span>${S.to}: <strong>${d.to.join(", ")}</strong></span>${when(d.cc.length, () => h`<span>${S.cc}: ${d.cc.join(", ")}</span>`)}</div>
|
|
307
|
+
<div class="subject">${d.subject}</div>
|
|
170
308
|
</div>
|
|
171
|
-
<div class="meta"><span>${S.to}: <strong>${d.to.join(", ")}</strong></span>${when(d.cc.length, () => h`<span>${S.cc}: ${d.cc.join(", ")}</span>`)}</div>
|
|
172
|
-
<div class="subject">${d.subject}</div>
|
|
173
309
|
${contextBlock(ctx)}
|
|
174
310
|
${when(d.note, () => h`<div class="note">${d.note}</div>`)}
|
|
175
311
|
<pre class="body">${d.text}</pre>
|
|
176
312
|
${attachments(d)}
|
|
177
313
|
<div class="actions">
|
|
314
|
+
<button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
|
|
178
315
|
<button hx-get="/drafts/${d.id}/edit" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.edit}</button>
|
|
179
316
|
<button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
|
|
180
|
-
<button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
|
|
181
317
|
</div>
|
|
182
318
|
${when(history.length, () => h`<details>
|
|
183
319
|
<summary>${S.thread} (${history.length})</summary>
|
|
@@ -195,9 +331,9 @@ export interface DraftForm {
|
|
|
195
331
|
|
|
196
332
|
export function draftEditor(d: Message, form: DraftForm, conflict: Message | null): View {
|
|
197
333
|
const version = conflict ? conflict.version : d.version;
|
|
198
|
-
return h`<article class="card ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
|
|
334
|
+
return h`<article class="card draft editing ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
|
|
199
335
|
<div class="drop-hint">${S.dropFiles}</div>
|
|
200
|
-
<div class="meta"
|
|
336
|
+
<div class="meta"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
|
|
201
337
|
${when(d.note, () => h`<div class="note">${d.note}</div>`)}
|
|
202
338
|
${when(conflict, () => h`<p class="warn">${S.conflictTitle}</p><div class="subject">${S.yourVersion}</div>`)}
|
|
203
339
|
<form hx-post="/drafts/${d.id}/save" hx-target="#draft-${d.id}" hx-swap="outerHTML">
|
|
@@ -218,9 +354,9 @@ export function draftEditor(d: Message, form: DraftForm, conflict: Message | nul
|
|
|
218
354
|
<textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
|
|
219
355
|
${draftFiles(d, null)}
|
|
220
356
|
<div class="actions">
|
|
357
|
+
<button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
|
|
221
358
|
<button type="submit">${S.save}</button>
|
|
222
359
|
<button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
|
|
223
|
-
<button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
|
|
224
360
|
</div>
|
|
225
361
|
</form>
|
|
226
362
|
${when(conflict, () => h`<details open>
|
|
@@ -248,56 +384,117 @@ export function draftDone(id: string, text: string): View {
|
|
|
248
384
|
}
|
|
249
385
|
|
|
250
386
|
export function draftsPage(drafts: { draft: Message; history: MessageView[]; ctx: ContextView }[]): View {
|
|
251
|
-
return h`<
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export function inboxPage(threads: Thread[], mailboxes: string[], filter: { mailbox: string; status: string }, own: Set<string>): View {
|
|
256
|
-
const tab = (status: string, label: string) => {
|
|
257
|
-
const query = new URLSearchParams({ status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) });
|
|
258
|
-
return h`<a href="/inbox?${query.toString()}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
|
|
259
|
-
};
|
|
260
|
-
return h`<h1>${S.navInbox}</h1>
|
|
261
|
-
<form class="filters" method="get" action="/inbox">
|
|
262
|
-
<input type="hidden" name="status" value="${filter.status}">
|
|
263
|
-
<span class="select"><select name="mailbox" aria-label="${S.filter}" onchange="this.form.submit()">
|
|
264
|
-
<option value="">${S.allMailboxes}</option>
|
|
265
|
-
${join(mailboxes.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
|
|
266
|
-
</select></span>
|
|
267
|
-
<nav class="tabs">${tab("unanswered", S.filterUnanswered)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
|
|
268
|
-
</form>
|
|
269
|
-
${threads.length ? join(threads.map(t => threadRow(t, own))) : h`<p class="empty">${S.inboxEmpty}</p>`}`;
|
|
387
|
+
return h`<div class="page">
|
|
388
|
+
<h1>${S.navDrafts}</h1>
|
|
389
|
+
${drafts.length ? join(drafts.map(d => draftCard(d.draft, d.history, d.ctx))) : h`<p class="empty">${S.draftsEmpty}</p>`}
|
|
390
|
+
</div>`;
|
|
270
391
|
}
|
|
271
392
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
393
|
+
export interface InboxFilter {
|
|
394
|
+
mailbox: string;
|
|
395
|
+
status: string;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export function inboxQuery(filter: InboxFilter): string {
|
|
399
|
+
return new URLSearchParams({ status: filter.status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) }).toString();
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** The thread list; on a wide screen it stays beside the open thread. */
|
|
403
|
+
export function threadList(threads: Thread[], opts: { mailboxes: string[]; domains: string[]; filter: InboxFilter; own: Set<string>; current: string | null }): View {
|
|
404
|
+
const { filter } = opts;
|
|
405
|
+
const tab = (status: string, label: string) =>
|
|
406
|
+
h`<a class="chip" href="/inbox?${inboxQuery({ ...filter, status })}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
|
|
407
|
+
return h`<section class="list">
|
|
408
|
+
<header class="list-head">
|
|
409
|
+
<h1>${opts.domains.length ? opts.domains.join(" · ") : S.navInbox}</h1>
|
|
410
|
+
<form class="filters" method="get" action="/inbox">
|
|
411
|
+
<input type="hidden" name="status" value="${filter.status}">
|
|
412
|
+
<nav class="chips" aria-label="${S.filter}">${tab("unanswered", S.filterPending)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
|
|
413
|
+
${when(opts.mailboxes.length > 1, () => h`<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.submit()">
|
|
414
|
+
<option value="">${S.allMailboxes}</option>
|
|
415
|
+
${join(opts.mailboxes.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
|
|
416
|
+
</select></span>`)}
|
|
417
|
+
</form>
|
|
418
|
+
</header>
|
|
419
|
+
${threads.length ? join(threads.map(t => threadRow(t, opts))) : h`<p class="empty">${S.inboxEmpty}</p>`}
|
|
420
|
+
</section>`;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function threadRow(t: Thread, opts: { mailboxes: string[]; filter: InboxFilter; own: Set<string>; current: string | null }): View {
|
|
424
|
+
const people = t.participants.filter(p => !opts.own.has(p));
|
|
425
|
+
return h`<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
|
|
426
|
+
<span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
|
|
427
|
+
<span class="row-main">
|
|
428
|
+
<span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
|
|
429
|
+
<span class="row-subject">${t.subject || "—"}</span>
|
|
430
|
+
${when(t.has_draft || opts.mailboxes.length > 1 || t.unread, () => h`<span class="row-tags">
|
|
431
|
+
${when(t.has_draft, () => h`<span class="badge draft">${S.hasDraft}</span>`)}
|
|
432
|
+
${when(opts.mailboxes.length > 1, () => mailboxBadge(t.mailbox))}
|
|
433
|
+
${when(t.unread, () => h`<span class="dot" title="${S.unread}"></span>`)}
|
|
434
|
+
</span>`)}
|
|
435
|
+
</span>
|
|
282
436
|
</a>`;
|
|
283
437
|
}
|
|
284
438
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
439
|
+
/** The thread list and the open thread side by side; a phone shows one of the two. */
|
|
440
|
+
export function inboxPage(list: View, thread: View | null): View {
|
|
441
|
+
return h`<div class="split ${thread ? "has-thread" : ""}">${list}<section class="pane">${thread ?? ""}</section></div>`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export interface ThreadEntry {
|
|
445
|
+
at: string;
|
|
446
|
+
view: View;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** The conversation, oldest first, with day separators, a reply box and the context panel. */
|
|
450
|
+
export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: { filter: InboxFilter; own: Set<string>; reply: { allowed: boolean; replyAll: boolean } }): View {
|
|
451
|
+
const query = inboxQuery(opts.filter);
|
|
452
|
+
const rows = contextRows(ctx);
|
|
453
|
+
const people = thread.participants.filter(p => !opts.own.has(p));
|
|
454
|
+
const title = h`<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, thread.mailbox].join(" · ")}</span>`;
|
|
455
|
+
const items: View[] = [];
|
|
456
|
+
let day = "";
|
|
457
|
+
for (const entry of entries) {
|
|
458
|
+
const label = dayLabel(entry.at);
|
|
459
|
+
if (label !== day) items.push(h`<div class="day">${label}</div>`);
|
|
460
|
+
day = label;
|
|
461
|
+
items.push(entry.view);
|
|
462
|
+
}
|
|
463
|
+
return h`<div class="thread">
|
|
464
|
+
<header class="thread-head">
|
|
465
|
+
<a class="icon-btn back" href="/inbox?${query}" aria-label="${S.back}">${icon("back")}</a>
|
|
466
|
+
${rows.length
|
|
467
|
+
? h`<button type="button" class="thread-title" data-context-toggle aria-controls="context">${title}</button>`
|
|
468
|
+
: h`<div class="thread-title">${title}</div>`}
|
|
469
|
+
${when(rows.length, () => h`<button type="button" class="context-btn" data-context-toggle aria-controls="context">${S.context}</button>`)}
|
|
470
|
+
${archiveButton(thread)}
|
|
471
|
+
</header>
|
|
472
|
+
<div class="messages" data-scroll-end>${join(items)}</div>
|
|
473
|
+
${when(opts.reply.allowed, () => h`<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
|
|
474
|
+
${when(opts.reply.replyAll, () => h`<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
|
|
475
|
+
<textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
|
|
476
|
+
<button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
|
|
477
|
+
<button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
|
|
478
|
+
</form>`)}
|
|
479
|
+
${when(rows.length, () => h`<aside class="context-panel" id="context" aria-label="${S.context}">
|
|
480
|
+
<div class="context-head"><h2>${S.context}</h2><button type="button" class="icon-btn" data-context-toggle aria-label="${S.close}">${icon("close")}</button></div>
|
|
481
|
+
<div class="context-body">${contextSections(rows)}</div>
|
|
482
|
+
</aside>
|
|
483
|
+
<div class="context-backdrop" data-context-toggle></div>`)}
|
|
484
|
+
</div>`;
|
|
290
485
|
}
|
|
291
486
|
|
|
292
487
|
export function archiveButton(thread: Thread): View {
|
|
488
|
+
const label = thread.archived ? S.unarchive : S.archive;
|
|
293
489
|
return h`<form id="archive" hx-post="/threads/${thread.id}/archive" hx-swap="outerHTML">
|
|
294
490
|
<input type="hidden" name="archived" value="${thread.archived ? "0" : "1"}">
|
|
295
|
-
<button class="
|
|
491
|
+
<button class="icon-btn" aria-label="${label}" title="${label}">${icon(thread.archived ? "unarchive" : "archive")}</button>
|
|
296
492
|
</form>`;
|
|
297
493
|
}
|
|
298
494
|
|
|
299
495
|
export function devicesPage(sessions: Session[], currentId: string): View {
|
|
300
|
-
return h`<
|
|
496
|
+
return h`<div class="page">
|
|
497
|
+
<h1>${S.navDevices}</h1>
|
|
301
498
|
${sessions.length ? join(sessions.map(s => h`<article class="card" id="session-${s.id}">
|
|
302
499
|
<div class="meta">
|
|
303
500
|
<strong>${s.label ?? s.user_agent ?? S.unknownDevice}</strong>
|
|
@@ -311,5 +508,20 @@ ${sessions.length ? join(sessions.map(s => h`<article class="card" id="session-$
|
|
|
311
508
|
<span>${S.createdBy}: ${s.created_by}</span>
|
|
312
509
|
</div>
|
|
313
510
|
${when(s.id !== currentId, () => h`<div class="actions"><button class="danger" hx-post="/devices/${s.id}/revoke" hx-target="#session-${s.id}" hx-swap="delete">${S.revoke}</button></div>`)}
|
|
314
|
-
</article>`)) : h`<p class="empty">${S.devicesEmpty}</p>`}
|
|
511
|
+
</article>`)) : h`<p class="empty">${S.devicesEmpty}</p>`}
|
|
512
|
+
</div>`;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export function settingsPage(theme: Theme): View {
|
|
516
|
+
return h`<div class="page">
|
|
517
|
+
<h1>${S.navSettings}</h1>
|
|
518
|
+
<form class="setting" method="post" action="/theme">
|
|
519
|
+
<label for="theme">${S.theme}</label>
|
|
520
|
+
<span class="select"><select id="theme" name="theme" onchange="this.form.submit()">
|
|
521
|
+
${join((["system", "light", "dark"] as const).map(t =>
|
|
522
|
+
h`<option value="${t}" ${raw(t === theme ? "selected" : "")}>${{ system: S.themeSystem, light: S.themeLight, dark: S.themeDark }[t]}</option>`))}
|
|
523
|
+
</select></span>
|
|
524
|
+
</form>
|
|
525
|
+
<form class="setting" method="post" action="/logout"><button class="danger">${S.logout}</button></form>
|
|
526
|
+
</div>`;
|
|
315
527
|
}
|