inboxer 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +376 -2
- package/dist/app.d.ts +6 -0
- package/dist/app.js +56 -0
- package/dist/auth.d.ts +33 -0
- package/dist/auth.js +111 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.js +90 -0
- package/dist/core/address.d.ts +6 -0
- package/dist/core/address.js +16 -0
- package/dist/core/attachments.d.ts +9 -0
- package/dist/core/attachments.js +30 -0
- package/dist/core/context.d.ts +10 -0
- package/dist/core/context.js +21 -0
- package/dist/core/mail.d.ts +170 -0
- package/dist/core/mail.js +656 -0
- package/dist/core/sync.d.ts +16 -0
- package/dist/core/sync.js +44 -0
- package/dist/core/text.d.ts +8 -0
- package/dist/core/text.js +45 -0
- package/dist/core/threads.d.ts +21 -0
- package/dist/core/threads.js +81 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +51 -0
- package/dist/mcp.d.ts +5 -0
- package/dist/mcp.js +198 -0
- package/dist/provider/index.d.ts +3 -0
- package/dist/provider/index.js +11 -0
- package/dist/provider/resend.d.ts +8 -0
- package/dist/provider/resend.js +184 -0
- package/dist/provider/types.d.ts +77 -0
- package/dist/provider/types.js +6 -0
- package/dist/store.d.ts +54 -0
- package/dist/store.js +148 -0
- package/dist/types.d.ts +138 -0
- package/dist/types.js +1 -0
- package/dist/ui/assets.d.ts +8 -0
- package/dist/ui/assets.js +13 -0
- package/dist/ui/routes.d.ts +11 -0
- package/dist/ui/routes.js +232 -0
- package/dist/ui/static/app.js +27 -0
- package/dist/ui/static/htmx.min.js +1 -0
- package/dist/ui/static/style.css +179 -0
- package/dist/ui/strings.d.ts +67 -0
- package/dist/ui/strings.js +67 -0
- package/dist/ui/views.d.ts +45 -0
- package/dist/ui/views.js +275 -0
- package/package.json +81 -4
- package/skills/inboxer/SKILL.md +118 -0
- package/src/app.ts +56 -0
- package/src/auth.ts +119 -0
- package/src/config.ts +92 -0
- package/src/core/address.ts +19 -0
- package/src/core/attachments.ts +33 -0
- package/src/core/context.ts +28 -0
- package/src/core/mail.ts +737 -0
- package/src/core/sync.ts +51 -0
- package/src/core/text.ts +52 -0
- package/src/core/threads.ts +102 -0
- package/src/index.ts +93 -0
- package/src/mcp.ts +233 -0
- package/src/provider/index.ts +14 -0
- package/src/provider/resend.ts +235 -0
- package/src/provider/types.ts +82 -0
- package/src/store.ts +187 -0
- package/src/types.ts +140 -0
- package/src/ui/assets.ts +21 -0
- package/src/ui/routes.ts +252 -0
- package/src/ui/static/app.js +27 -0
- package/src/ui/static/htmx.min.js +1 -0
- package/src/ui/static/style.css +179 -0
- package/src/ui/strings.ts +73 -0
- package/src/ui/views.ts +315 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Every user-facing UI string. Translate here. */
|
|
2
|
+
export const S = {
|
|
3
|
+
appName: "Inboxer",
|
|
4
|
+
navDrafts: "Drafts",
|
|
5
|
+
navInbox: "Inbox",
|
|
6
|
+
navDevices: "Devices",
|
|
7
|
+
logout: "Log out",
|
|
8
|
+
themeSystem: "System",
|
|
9
|
+
themeLight: "Light",
|
|
10
|
+
themeDark: "Dark",
|
|
11
|
+
theme: "Theme",
|
|
12
|
+
|
|
13
|
+
draftsEmpty: "No drafts waiting for review.",
|
|
14
|
+
to: "To",
|
|
15
|
+
cc: "Cc",
|
|
16
|
+
bcc: "Bcc",
|
|
17
|
+
subject: "Subject",
|
|
18
|
+
body: "Message",
|
|
19
|
+
from: "From",
|
|
20
|
+
edit: "Edit",
|
|
21
|
+
send: "Send",
|
|
22
|
+
discard: "Discard",
|
|
23
|
+
save: "Save",
|
|
24
|
+
saveAndSend: "Save & Send",
|
|
25
|
+
cancel: "Cancel",
|
|
26
|
+
attach: "Attach",
|
|
27
|
+
remove: "Remove",
|
|
28
|
+
dropFiles: "Drop files to attach",
|
|
29
|
+
tooLarge: "is larger than",
|
|
30
|
+
sending: "Sending to",
|
|
31
|
+
discarding: "Discarding draft",
|
|
32
|
+
undo: "Undo",
|
|
33
|
+
sentTo: "Sent to",
|
|
34
|
+
discarded: "Draft discarded.",
|
|
35
|
+
editedByHuman: "Edited by you",
|
|
36
|
+
thread: "Thread",
|
|
37
|
+
thisThread: "This thread",
|
|
38
|
+
context: "Context",
|
|
39
|
+
draft: "Draft",
|
|
40
|
+
|
|
41
|
+
conflictTitle: "This draft changed while you were editing.",
|
|
42
|
+
yourVersion: "Your version",
|
|
43
|
+
currentVersion: "Current version",
|
|
44
|
+
|
|
45
|
+
filterUnanswered: "Unanswered",
|
|
46
|
+
filterAll: "All",
|
|
47
|
+
filterArchived: "Archived",
|
|
48
|
+
allMailboxes: "All mailboxes",
|
|
49
|
+
filter: "Filter",
|
|
50
|
+
inboxEmpty: "No threads.",
|
|
51
|
+
unread: "unread",
|
|
52
|
+
hasDraft: "draft",
|
|
53
|
+
|
|
54
|
+
archive: "Archive",
|
|
55
|
+
unarchive: "Move to inbox",
|
|
56
|
+
status: "Status",
|
|
57
|
+
|
|
58
|
+
devicesEmpty: "No signed-in devices.",
|
|
59
|
+
thisDevice: "This device",
|
|
60
|
+
revoke: "Revoke",
|
|
61
|
+
createdBy: "Link from",
|
|
62
|
+
lastSeen: "Last seen",
|
|
63
|
+
signedIn: "Signed in",
|
|
64
|
+
unknownDevice: "Unknown browser",
|
|
65
|
+
|
|
66
|
+
signInTitle: "Sign in on this device",
|
|
67
|
+
signInButton: "Sign in",
|
|
68
|
+
linkUsed: "This link was already used or expired.",
|
|
69
|
+
notSignedIn: "You are not signed in. Ask your agent for a login link.",
|
|
70
|
+
signedOut: "You are signed out.",
|
|
71
|
+
notFound: "Not found.",
|
|
72
|
+
error: "Something went wrong.",
|
|
73
|
+
} as const;
|
package/src/ui/views.ts
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { html, raw } from "hono/html";
|
|
2
|
+
import type { HtmlEscapedString } from "hono/utils/html";
|
|
3
|
+
import type { MessageView } from "../core/mail.ts";
|
|
4
|
+
import type { Contact, Context, Message, Session, Thread } from "../types.ts";
|
|
5
|
+
import { ASSETS } from "./assets.ts";
|
|
6
|
+
import { S } from "./strings.ts";
|
|
7
|
+
|
|
8
|
+
export type View = HtmlEscapedString;
|
|
9
|
+
export type Theme = "system" | "light" | "dark";
|
|
10
|
+
export type Page = "drafts" | "inbox" | "devices" | null;
|
|
11
|
+
|
|
12
|
+
/** Views never await, so `html` returns a plain escaped string. */
|
|
13
|
+
function h(strings: TemplateStringsArray, ...values: unknown[]): View {
|
|
14
|
+
return html(strings, ...values) as View;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function join(items: View[]): View {
|
|
18
|
+
return raw(items.join("")) as View;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function when(condition: unknown, view: () => View): View | "" {
|
|
22
|
+
return condition ? view() : "";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function formatDate(iso: string): string {
|
|
26
|
+
const date = new Date(iso);
|
|
27
|
+
const sameDay = date.toDateString() === new Date().toDateString();
|
|
28
|
+
return sameDay
|
|
29
|
+
? date.toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit" })
|
|
30
|
+
: date.toLocaleDateString("en", { month: "short", day: "numeric", year: "numeric" });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function layout(title: string, body: View, opts: { theme: Theme; page: Page; draftCount?: number; signedIn: boolean; domains?: string[] }): View {
|
|
34
|
+
const nav = (page: Page, href: string, label: string, extra: View | "" = "") =>
|
|
35
|
+
h`<a href="${href}" ${raw(opts.page === page ? 'aria-current="page"' : "")}>${label}${extra}</a>`;
|
|
36
|
+
return h`<!doctype html>
|
|
37
|
+
<html lang="en" ${raw(opts.theme === "system" ? "" : `data-theme="${opts.theme}"`)}>
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="utf-8">
|
|
40
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
41
|
+
<title>${title} · ${S.appName}</title>
|
|
42
|
+
<link rel="stylesheet" href="${ASSETS["style.css"]!.url}">
|
|
43
|
+
<script src="${ASSETS["htmx.min.js"]!.url}" defer></script>
|
|
44
|
+
<script src="${ASSETS["app.js"]!.url}" defer></script>
|
|
45
|
+
</head>
|
|
46
|
+
<body>
|
|
47
|
+
${when(opts.signedIn, () => h`<header>
|
|
48
|
+
<nav>
|
|
49
|
+
${nav("drafts", "/", S.navDrafts, opts.draftCount ? h` <span class="count">${opts.draftCount}</span>` : "")}
|
|
50
|
+
${nav("inbox", "/inbox", S.navInbox)}
|
|
51
|
+
${nav("devices", "/devices", S.navDevices)}
|
|
52
|
+
</nav>
|
|
53
|
+
<form method="post" action="/theme">
|
|
54
|
+
<span class="select"><select name="theme" aria-label="${S.theme}" onchange="this.form.submit()">
|
|
55
|
+
${join((["system", "light", "dark"] as const).map(t =>
|
|
56
|
+
h`<option value="${t}" ${raw(t === opts.theme ? "selected" : "")}>${{ system: S.themeSystem, light: S.themeLight, dark: S.themeDark }[t]}</option>`))}
|
|
57
|
+
</select></span>
|
|
58
|
+
</form>
|
|
59
|
+
<form method="post" action="/logout"><button class="link">${S.logout}</button></form>
|
|
60
|
+
</header>`)}
|
|
61
|
+
<main>${when(opts.domains?.length, () => h`<div class="domain">${opts.domains!.join(" · ")}</div>`)}${body}</main>
|
|
62
|
+
</body>
|
|
63
|
+
</html>`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function message(lines: string[]): View {
|
|
67
|
+
return h`<div class="centered">${join(lines.map(l => h`<p>${l}</p>`))}</div>`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function signIn(token: string, valid: boolean): View {
|
|
71
|
+
if (!valid) return message([S.linkUsed]);
|
|
72
|
+
return h`<div class="centered">
|
|
73
|
+
<h1>${S.signInTitle}</h1>
|
|
74
|
+
<form method="post" action="/auth/${token}"><button class="primary">${S.signInButton}</button></form>
|
|
75
|
+
</div>`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function mailboxBadge(mailbox: string): View {
|
|
79
|
+
return h`<span class="badge">${mailbox}</span>`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
|
|
83
|
+
|
|
84
|
+
/** Image types a browser renders without running code; SVG is left out on purpose. */
|
|
85
|
+
export function isPreviewable(contentType: string): boolean {
|
|
86
|
+
return PREVIEWABLE.has(contentType);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function formatSize(bytes: number | null): string {
|
|
90
|
+
if (bytes === null) return "";
|
|
91
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
92
|
+
if (bytes < 1048576) return `${Math.round(bytes / 1024)} KB`;
|
|
93
|
+
return `${(bytes / 1048576).toFixed(1)} MB`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Images first as thumbnails, inline ones included; the rest as file links. */
|
|
97
|
+
function attachments(m: Pick<MessageView, "id" | "attachments">): View | "" {
|
|
98
|
+
if (!m.attachments.length) return "";
|
|
99
|
+
const href = (id: string) => `/attachments/${encodeURIComponent(m.id)}/${encodeURIComponent(id)}`;
|
|
100
|
+
const images = m.attachments.filter(a => isPreviewable(a.content_type));
|
|
101
|
+
const files = m.attachments.filter(a => !isPreviewable(a.content_type));
|
|
102
|
+
return h`${when(images.length, () => h`<div class="images">${join(images.map(a =>
|
|
103
|
+
h`<a href="${href(a.id)}" target="_blank" rel="noopener"><img src="${href(a.id)}" alt="${a.filename}" loading="lazy"></a>`))}</div>`)}
|
|
104
|
+
${when(files.length, () => h`<div class="files">${join(files.map(a =>
|
|
105
|
+
h`<a class="file" href="${href(a.id)}" target="_blank" rel="noopener"><span>${a.filename}</span><span class="size">${formatSize(a.size)}</span></a>`))}</div>`)}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Mail clients write "[image: name.png]" in the text part where an image sat; the image shows below instead. */
|
|
109
|
+
function withoutImagePlaceholders(m: MessageView): string {
|
|
110
|
+
let text = m.text;
|
|
111
|
+
for (const a of m.attachments) {
|
|
112
|
+
if (isPreviewable(a.content_type)) text = text.split(`[image: ${a.filename}]`).join("");
|
|
113
|
+
}
|
|
114
|
+
return text.replace(/\n{3,}/g, "\n\n").trim();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function messageCard(m: MessageView): View {
|
|
118
|
+
return h`<article class="card ${m.direction}">
|
|
119
|
+
<div class="meta">
|
|
120
|
+
<strong>${m.from}</strong>
|
|
121
|
+
<span>${formatDate(m.date)}</span>
|
|
122
|
+
${when(m.direction === "out" && m.status !== "draft", () => h`<span>${m.status}</span>`)}
|
|
123
|
+
</div>
|
|
124
|
+
${when(m.to.length || m.cc.length, () => h`<div class="meta">${when(m.to.length, () => h`<span>${S.to}: ${m.to.join(", ")}</span>`)}${when(m.cc.length, () => h`<span>${S.cc}: ${m.cc.join(", ")}</span>`)}</div>`)}
|
|
125
|
+
<pre class="body">${withoutImagePlaceholders(m)}</pre>
|
|
126
|
+
${attachments(m)}
|
|
127
|
+
</article>`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ContextView {
|
|
131
|
+
context: Context | null;
|
|
132
|
+
contacts: Contact[];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Read-only context agents attached to the thread and its participants. */
|
|
136
|
+
function contextBlock(ctx: ContextView | null): View | "" {
|
|
137
|
+
if (!ctx) return "";
|
|
138
|
+
const rows = [
|
|
139
|
+
...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
|
|
140
|
+
...(ctx.context ? [{ who: S.thisThread, meta: ctx.context.meta, note: ctx.context.note }] : []),
|
|
141
|
+
].filter(r => r.note || Object.keys(r.meta).length);
|
|
142
|
+
if (!rows.length) return "";
|
|
143
|
+
return h`<details class="context"><summary>${S.context}</summary>${join(rows.map(r => h`<section>
|
|
144
|
+
<div class="who">${r.who}</div>
|
|
145
|
+
${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
|
+
${when(r.note, () => h`<p>${r.note}</p>`)}
|
|
147
|
+
</section>`))}</details>`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A send or discard in its undo window; reloads itself when the window closes. */
|
|
151
|
+
function pendingCard(d: Message): View {
|
|
152
|
+
const left = Math.max(0, Date.parse(d.pending!.at) - Date.now());
|
|
153
|
+
return h`<article class="card pending" id="draft-${d.id}" hx-get="/drafts/${d.id}/card" hx-trigger="load delay:${left + 400}ms" hx-swap="outerHTML">
|
|
154
|
+
<div class="pending-row">
|
|
155
|
+
<span>${d.pending!.action === "send" ? h`${S.sending} <strong>${d.to.join(", ")}</strong>` : S.discarding}</span>
|
|
156
|
+
<button hx-post="/drafts/${d.id}/undo" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.undo}</button>
|
|
157
|
+
</div>
|
|
158
|
+
<i class="countdown" style="animation-duration: ${left}ms"></i>
|
|
159
|
+
</article>`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function draftCard(d: Message, history: MessageView[], ctx: ContextView | null): View {
|
|
163
|
+
if (d.pending) return pendingCard(d);
|
|
164
|
+
return h`<article class="card" id="draft-${d.id}">
|
|
165
|
+
<div class="meta">
|
|
166
|
+
${mailboxBadge(d.mailbox)}
|
|
167
|
+
<span class="badge draft">${S.draft}</span>
|
|
168
|
+
${when(d.edited_by_human, () => h`<span>${S.editedByHuman}</span>`)}
|
|
169
|
+
<span>${formatDate(d.created_at)}</span>
|
|
170
|
+
</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
|
+
${contextBlock(ctx)}
|
|
174
|
+
${when(d.note, () => h`<div class="note">${d.note}</div>`)}
|
|
175
|
+
<pre class="body">${d.text}</pre>
|
|
176
|
+
${attachments(d)}
|
|
177
|
+
<div class="actions">
|
|
178
|
+
<button hx-get="/drafts/${d.id}/edit" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.edit}</button>
|
|
179
|
+
<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
|
+
</div>
|
|
182
|
+
${when(history.length, () => h`<details>
|
|
183
|
+
<summary>${S.thread} (${history.length})</summary>
|
|
184
|
+
${join(history.map(messageCard))}
|
|
185
|
+
</details>`)}
|
|
186
|
+
</article>`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface DraftForm {
|
|
190
|
+
to: string;
|
|
191
|
+
cc: string;
|
|
192
|
+
subject: string;
|
|
193
|
+
text: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function draftEditor(d: Message, form: DraftForm, conflict: Message | null): View {
|
|
197
|
+
const version = conflict ? conflict.version : d.version;
|
|
198
|
+
return h`<article class="card ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
|
|
199
|
+
<div class="drop-hint">${S.dropFiles}</div>
|
|
200
|
+
<div class="meta">${mailboxBadge(d.mailbox)}<span class="badge draft">${S.draft}</span></div>
|
|
201
|
+
${when(d.note, () => h`<div class="note">${d.note}</div>`)}
|
|
202
|
+
${when(conflict, () => h`<p class="warn">${S.conflictTitle}</p><div class="subject">${S.yourVersion}</div>`)}
|
|
203
|
+
<form hx-post="/drafts/${d.id}/save" hx-target="#draft-${d.id}" hx-swap="outerHTML">
|
|
204
|
+
<input type="hidden" name="version" value="${version}">
|
|
205
|
+
<div class="field">
|
|
206
|
+
<label for="to-${d.id}">${S.to}</label>
|
|
207
|
+
<input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
|
|
208
|
+
${when(!form.cc, () => h`<button type="button" class="link" onclick="this.remove();var r=document.getElementById('cc-row-${d.id}');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>`)}
|
|
209
|
+
</div>
|
|
210
|
+
<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
|
|
211
|
+
<label for="cc-${d.id}">${S.cc}</label>
|
|
212
|
+
<input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
|
|
213
|
+
</div>
|
|
214
|
+
<div class="field">
|
|
215
|
+
<label for="subject-${d.id}">${S.subject}</label>
|
|
216
|
+
<input id="subject-${d.id}" name="subject" value="${form.subject}" required>
|
|
217
|
+
</div>
|
|
218
|
+
<textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
|
|
219
|
+
${draftFiles(d, null)}
|
|
220
|
+
<div class="actions">
|
|
221
|
+
<button type="submit">${S.save}</button>
|
|
222
|
+
<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
|
+
</div>
|
|
225
|
+
</form>
|
|
226
|
+
${when(conflict, () => h`<details open>
|
|
227
|
+
<summary>${S.currentVersion}</summary>
|
|
228
|
+
<div class="card">
|
|
229
|
+
<div class="meta"><span>${S.to}: ${conflict!.to.join(", ")}</span>${when(conflict!.cc.length, () => h`<span>${S.cc}: ${conflict!.cc.join(", ")}</span>`)}</div>
|
|
230
|
+
<div class="subject">${conflict!.subject}</div>
|
|
231
|
+
<pre class="body">${conflict!.text}</pre>
|
|
232
|
+
</div>
|
|
233
|
+
</details>`)}
|
|
234
|
+
</article>`;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
|
|
238
|
+
export function draftFiles(d: Message, error: string | null): View {
|
|
239
|
+
return h`<div class="draft-files" id="files-${d.id}">
|
|
240
|
+
${join(d.attachments.map(a => h`<span class="file"><span>${a.filename}</span><span class="size">${formatSize(a.size)}</span><button type="button" class="link" aria-label="${S.remove} ${a.filename}" hx-post="/drafts/${d.id}/attachments/${a.id}/remove" hx-target="#files-${d.id}" hx-swap="outerHTML">×</button></span>`))}
|
|
241
|
+
<label class="file attach">${S.attach}<input type="file" name="files" multiple hidden hx-post="/drafts/${d.id}/attachments" hx-encoding="multipart/form-data" hx-trigger="change" hx-target="#files-${d.id}" hx-swap="outerHTML" hx-include="this"></label>
|
|
242
|
+
${when(error, () => h`<p class="warn">${error}</p>`)}
|
|
243
|
+
</div>`;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function draftDone(id: string, text: string): View {
|
|
247
|
+
return h`<article class="card notice" id="draft-${id}">${text}</article>`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function draftsPage(drafts: { draft: Message; history: MessageView[]; ctx: ContextView }[]): View {
|
|
251
|
+
return h`<h1>${S.navDrafts}</h1>
|
|
252
|
+
${drafts.length ? join(drafts.map(d => draftCard(d.draft, d.history, d.ctx))) : h`<p class="empty">${S.draftsEmpty}</p>`}`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function inboxPage(threads: Thread[], mailboxes: string[], filter: { mailbox: string; status: string }, own: Set<string>): View {
|
|
256
|
+
const tab = (status: string, label: string) => {
|
|
257
|
+
const query = new URLSearchParams({ status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) });
|
|
258
|
+
return h`<a href="/inbox?${query.toString()}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
|
|
259
|
+
};
|
|
260
|
+
return h`<h1>${S.navInbox}</h1>
|
|
261
|
+
<form class="filters" method="get" action="/inbox">
|
|
262
|
+
<input type="hidden" name="status" value="${filter.status}">
|
|
263
|
+
<span class="select"><select name="mailbox" aria-label="${S.filter}" onchange="this.form.submit()">
|
|
264
|
+
<option value="">${S.allMailboxes}</option>
|
|
265
|
+
${join(mailboxes.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
|
|
266
|
+
</select></span>
|
|
267
|
+
<nav class="tabs">${tab("unanswered", S.filterUnanswered)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
|
|
268
|
+
</form>
|
|
269
|
+
${threads.length ? join(threads.map(t => threadRow(t, own))) : h`<p class="empty">${S.inboxEmpty}</p>`}`;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function threadRow(t: Thread, own: Set<string>): View {
|
|
273
|
+
return h`<a class="card thread-row" href="/threads/${t.id}">
|
|
274
|
+
<div class="meta">
|
|
275
|
+
${mailboxBadge(t.mailbox)}
|
|
276
|
+
${when(t.unread, () => h`<span class="dot" title="${S.unread}"></span>`)}
|
|
277
|
+
${when(t.has_draft, () => h`<span class="badge draft">${S.hasDraft}</span>`)}
|
|
278
|
+
<span>${formatDate(t.last_at)}</span>
|
|
279
|
+
</div>
|
|
280
|
+
<div class="subject">${t.subject || "—"}</div>
|
|
281
|
+
<div class="meta"><span>${t.participants.filter(p => !own.has(p)).join(", ")}</span></div>
|
|
282
|
+
</a>`;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function threadPage(thread: Thread, items: View[], ctx: ContextView): View {
|
|
286
|
+
return h`<h1>${thread.subject || "—"}</h1>
|
|
287
|
+
<div class="meta thread-head">${mailboxBadge(thread.mailbox)}${archiveButton(thread)}</div>
|
|
288
|
+
${contextBlock(ctx)}
|
|
289
|
+
<section class="messages">${join(items)}</section>`;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function archiveButton(thread: Thread): View {
|
|
293
|
+
return h`<form id="archive" hx-post="/threads/${thread.id}/archive" hx-swap="outerHTML">
|
|
294
|
+
<input type="hidden" name="archived" value="${thread.archived ? "0" : "1"}">
|
|
295
|
+
<button class="link">${thread.archived ? S.unarchive : S.archive}</button>
|
|
296
|
+
</form>`;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function devicesPage(sessions: Session[], currentId: string): View {
|
|
300
|
+
return h`<h1>${S.navDevices}</h1>
|
|
301
|
+
${sessions.length ? join(sessions.map(s => h`<article class="card" id="session-${s.id}">
|
|
302
|
+
<div class="meta">
|
|
303
|
+
<strong>${s.label ?? s.user_agent ?? S.unknownDevice}</strong>
|
|
304
|
+
${when(s.id === currentId, () => h`<span class="badge">${S.thisDevice}</span>`)}
|
|
305
|
+
${when(s.scope, () => join(s.scope!.map(mailboxBadge)))}
|
|
306
|
+
</div>
|
|
307
|
+
${when(s.label && s.user_agent, () => h`<div class="meta"><span>${s.user_agent}</span></div>`)}
|
|
308
|
+
<div class="meta">
|
|
309
|
+
<span>${S.signedIn}: ${formatDate(s.created_at)}</span>
|
|
310
|
+
<span>${S.lastSeen}: ${formatDate(s.last_seen)}</span>
|
|
311
|
+
<span>${S.createdBy}: ${s.created_by}</span>
|
|
312
|
+
</div>
|
|
313
|
+
${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>`}`;
|
|
315
|
+
}
|