inboxer 0.3.0 → 0.4.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/src/ui/views.ts CHANGED
@@ -34,6 +34,7 @@ const ICONS = {
34
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
35
  send: '<path d="M5 12h14"/><path d="M13 6l6 6-6 6"/>',
36
36
  close: '<path d="M6 6l12 12M18 6L6 18"/>',
37
+ attach: '<path d="M20.5 11.5l-8.2 8.2a5 5 0 01-7-7l8.2-8.2a3.3 3.3 0 014.7 4.7l-8.2 8.2a1.7 1.7 0 01-2.4-2.4l7.6-7.6"/>',
37
38
  } as const;
38
39
 
39
40
  function icon(name: keyof typeof ICONS): View {
@@ -89,7 +90,6 @@ export interface LayoutOptions {
89
90
  page: Page;
90
91
  signedIn: boolean;
91
92
  draftCount?: number;
92
- domains?: string[];
93
93
  /** Mailboxes the session can send from; New mail shows only when there is one. */
94
94
  senders?: Mailbox[];
95
95
  /** Thread pages fill the screen on a phone, so the tab bar gives way to the reply box. */
@@ -114,7 +114,6 @@ export function layout(title: string, body: View, opts: LayoutOptions): View {
114
114
  <body class="${opts.signedIn ? "app" : ""} ${opts.fullScreen ? "full" : ""}">
115
115
  ${when(opts.signedIn, () => h`<aside class="sidebar">
116
116
  <div class="brand">${S.appName}<span>.</span></div>
117
- ${when(opts.domains?.length, () => h`<div class="domain">${opts.domains!.join(" · ")}</div>`)}
118
117
  ${when(canSend, () => h`<button type="button" class="primary new-mail" data-compose>${icon("plus")}${S.newMail}</button>`)}
119
118
  <nav class="side-nav" aria-label="${S.mainNav}">
120
119
  ${link("drafts", "/", S.navDrafts, "drafts", count)}
@@ -132,6 +131,7 @@ ${when(opts.signedIn, () => h`<nav class="tabbar" aria-label="${S.mainNav}">
132
131
  ${link("settings", "/settings", S.navSettings, "settings")}
133
132
  </nav>`)}
134
133
  ${when(opts.signedIn && canSend, () => composeDialog(opts.senders!))}
134
+ ${when(opts.signedIn, () => h`<dialog class="sheet" id="edit-sheet" aria-label="${S.edit}"></dialog>`)}
135
135
  </body>
136
136
  </html>`;
137
137
  }
@@ -139,7 +139,7 @@ ${when(opts.signedIn && canSend, () => composeDialog(opts.senders!))}
139
139
  /** New mail, opened from the sidebar or the tab bar; a bottom sheet on a phone. */
140
140
  function composeDialog(senders: Mailbox[]): View {
141
141
  return h`<dialog class="sheet" id="compose" aria-label="${S.newMail}">
142
- <form method="post" action="/compose">
142
+ <form method="post" action="/compose" enctype="multipart/form-data" data-drop>
143
143
  <div class="grabber" aria-hidden="true"></div>
144
144
  <button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
145
145
  <div class="field compact">
@@ -163,6 +163,8 @@ function composeDialog(senders: Mailbox[]): View {
163
163
  </div>
164
164
  <textarea name="text" aria-label="${S.body}" required></textarea>
165
165
  <div class="sheet-actions">
166
+ <label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" id="compose-files" multiple hidden></label>
167
+ <output class="sheet-files" id="compose-file-names"></output>
166
168
  <button type="submit" name="action" value="save">${S.saveDraft}</button>
167
169
  <button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
168
170
  </div>
@@ -226,20 +228,6 @@ function recipients(m: MessageView): View | "" {
226
228
  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
229
  }
228
230
 
229
- /** A message in a draft's history on the Drafts page. */
230
- export function messageCard(m: MessageView): View {
231
- return h`<article class="card ${m.direction}">
232
- <div class="meta">
233
- <strong>${m.from}</strong>
234
- <span>${formatDate(m.date)}</span>
235
- ${when(m.direction === "out" && m.status !== "draft", () => h`<span>${m.status}</span>`)}
236
- </div>
237
- ${recipients(m)}
238
- <pre class="body">${withoutImagePlaceholders(m)}</pre>
239
- ${attachments(m)}
240
- </article>`;
241
- }
242
-
243
231
  /** A message in a thread: received ones on the left, ours on the right. */
244
232
  export function messageBubble(m: MessageView, showSender: boolean): View {
245
233
  const mine = m.direction === "out";
@@ -273,14 +261,6 @@ function contextSections(rows: ReturnType<typeof contextRows>): View {
273
261
  </section>`));
274
262
  }
275
263
 
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>`;
282
- }
283
-
284
264
  /** A send or discard in its undo window; reloads itself when the window closes. */
285
265
  function pendingCard(d: Message): View {
286
266
  const left = Math.max(0, Date.parse(d.pending!.at) - Date.now());
@@ -293,8 +273,8 @@ function pendingCard(d: Message): View {
293
273
  </article>`;
294
274
  }
295
275
 
296
- /** A draft for review: a card on the Drafts page, a bubble on our side of a thread. */
297
- export function draftCard(d: Message, history: MessageView[], ctx: ContextView | null): View {
276
+ /** A draft for review, on our side of its thread. */
277
+ export function draftCard(d: Message): View {
298
278
  if (d.pending) return pendingCard(d);
299
279
  return h`<article class="card draft" id="draft-${d.id}">
300
280
  <div class="meta">
@@ -306,19 +286,14 @@ export function draftCard(d: Message, history: MessageView[], ctx: ContextView |
306
286
  <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
287
  <div class="subject">${d.subject}</div>
308
288
  </div>
309
- ${contextBlock(ctx)}
310
289
  ${when(d.note, () => h`<div class="note">${d.note}</div>`)}
311
290
  <pre class="body">${d.text}</pre>
312
291
  ${attachments(d)}
313
292
  <div class="actions">
314
293
  <button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
315
- <button hx-get="/drafts/${d.id}/edit" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.edit}</button>
294
+ <button hx-get="/drafts/${d.id}/edit" hx-target="#edit-sheet" hx-swap="innerHTML">${S.edit}</button>
316
295
  <button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
317
296
  </div>
318
- ${when(history.length, () => h`<details>
319
- <summary>${S.thread} (${history.length})</summary>
320
- ${join(history.map(messageCard))}
321
- </details>`)}
322
297
  </article>`;
323
298
  }
324
299
 
@@ -329,52 +304,57 @@ export interface DraftForm {
329
304
  text: string;
330
305
  }
331
306
 
307
+ /** The edit sheet's content; one draft is edited at a time. */
332
308
  export function draftEditor(d: Message, form: DraftForm, conflict: Message | null): View {
333
309
  const version = conflict ? conflict.version : d.version;
334
- return h`<article class="card draft editing ${conflict ? "conflict" : ""}" id="draft-${d.id}" data-drop>
310
+ return h`<form class="${conflict ? "conflict" : ""}" hx-post="/drafts/${d.id}/save" hx-target="#edit-sheet" hx-swap="innerHTML" data-drop>
311
+ <div class="grabber" aria-hidden="true"></div>
335
312
  <div class="drop-hint">${S.dropFiles}</div>
336
- <div class="meta"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
313
+ <button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
314
+ <div class="sheet-head"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
337
315
  ${when(d.note, () => h`<div class="note">${d.note}</div>`)}
338
- ${when(conflict, () => h`<p class="warn">${S.conflictTitle}</p><div class="subject">${S.yourVersion}</div>`)}
339
- <form hx-post="/drafts/${d.id}/save" hx-target="#draft-${d.id}" hx-swap="outerHTML">
340
- <input type="hidden" name="version" value="${version}">
341
- <div class="field">
342
- <label for="to-${d.id}">${S.to}</label>
343
- <input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
344
- ${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>`)}
345
- </div>
346
- <div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
347
- <label for="cc-${d.id}">${S.cc}</label>
348
- <input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
349
- </div>
350
- <div class="field">
351
- <label for="subject-${d.id}">${S.subject}</label>
352
- <input id="subject-${d.id}" name="subject" value="${form.subject}" required>
353
- </div>
354
- <textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
355
- ${draftFiles(d, null)}
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>
358
- <button type="submit">${S.save}</button>
359
- <button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
360
- </div>
361
- </form>
362
- ${when(conflict, () => h`<details open>
363
- <summary>${S.currentVersion}</summary>
364
- <div class="card">
316
+ ${when(conflict, () => h`<div class="sheet-conflict">
317
+ <p class="warn">${S.conflictTitle}</p>
318
+ <details>
319
+ <summary>${S.currentVersion}</summary>
365
320
  <div class="meta"><span>${S.to}: ${conflict!.to.join(", ")}</span>${when(conflict!.cc.length, () => h`<span>${S.cc}: ${conflict!.cc.join(", ")}</span>`)}</div>
366
321
  <div class="subject">${conflict!.subject}</div>
367
322
  <pre class="body">${conflict!.text}</pre>
368
- </div>
369
- </details>`)}
370
- </article>`;
323
+ </details>
324
+ </div>`)}
325
+ <input type="hidden" name="version" value="${version}">
326
+ <div class="field">
327
+ <label for="to-${d.id}">${S.to}</label>
328
+ <input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
329
+ ${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>`)}
330
+ </div>
331
+ <div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
332
+ <label for="cc-${d.id}">${S.cc}</label>
333
+ <input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
334
+ </div>
335
+ <div class="field">
336
+ <label for="subject-${d.id}">${S.subject}</label>
337
+ <input id="subject-${d.id}" name="subject" value="${form.subject}" required>
338
+ </div>
339
+ <textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
340
+ <div class="sheet-actions">
341
+ ${draftFiles(d, null)}
342
+ <button type="submit">${S.save}</button>
343
+ <button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
344
+ </div>
345
+ </form>`;
346
+ }
347
+
348
+ /** A reply opened in the edit sheet from the reply box; the thread reloads when the sheet closes, to show the new draft. */
349
+ export function newReplyEditor(d: Message): View {
350
+ return h`<div data-reload-on-close hidden></div>${draftEditor(d, { to: d.to.join(", "), cc: d.cc.join(", "), subject: d.subject, text: d.text }, null)}`;
371
351
  }
372
352
 
373
353
  /** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
374
354
  export function draftFiles(d: Message, error: string | null): View {
375
355
  return h`<div class="draft-files" id="files-${d.id}">
356
+ <label class="icon-btn" aria-label="${S.attach}">${icon("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>
376
357
  ${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>`))}
377
- <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>
378
358
  ${when(error, () => h`<p class="warn">${error}</p>`)}
379
359
  </div>`;
380
360
  }
@@ -383,11 +363,23 @@ export function draftDone(id: string, text: string): View {
383
363
  return h`<article class="card notice" id="draft-${id}">${text}</article>`;
384
364
  }
385
365
 
386
- export function draftsPage(drafts: { draft: Message; history: MessageView[]; ctx: ContextView }[]): View {
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>`;
366
+ /** Drafts waiting for review, listed like the inbox; each opens its thread. */
367
+ export function draftList(drafts: Message[], current: string | null): View {
368
+ return h`<section class="list">
369
+ <header class="list-head"><h1>${S.navDrafts}</h1></header>
370
+ ${drafts.length ? join(drafts.map(d => h`<a class="row" href="/drafts/${d.id}" ${raw(d.id === current ? 'aria-current="page"' : "")}>
371
+ <span class="avatar" aria-hidden="true">${initials(d.to[0] ?? d.mailbox)}</span>
372
+ <span class="row-main">
373
+ <span class="row-top"><span class="who">${d.to.map(displayName).join(", ") || "—"}</span><time datetime="${d.created_at}">${formatDate(d.created_at)}</time></span>
374
+ <span class="row-subject">${d.subject || "—"}</span>
375
+ <span class="row-snippet">${d.text}</span>
376
+ <span class="row-tags">
377
+ ${mailboxBadge(d.mailbox)}
378
+ <span class="row-by">${d.edited_by_human ? S.editedByHuman : S.byAgent}</span>
379
+ </span>
380
+ </span>
381
+ </a>`)) : h`<p class="empty">${S.draftsEmpty}</p>`}
382
+ </section>`;
391
383
  }
392
384
 
393
385
  export interface InboxFilter {
@@ -447,7 +439,7 @@ export interface ThreadEntry {
447
439
  }
448
440
 
449
441
  /** 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 {
442
+ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextView, opts: { back: string; filter: InboxFilter; own: Set<string>; reply: { allowed: boolean; replyAll: boolean } }): View {
451
443
  const query = inboxQuery(opts.filter);
452
444
  const rows = contextRows(ctx);
453
445
  const people = thread.participants.filter(p => !opts.own.has(p));
@@ -462,7 +454,7 @@ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextV
462
454
  }
463
455
  return h`<div class="thread">
464
456
  <header class="thread-head">
465
- <a class="icon-btn back" href="/inbox?${query}" aria-label="${S.back}">${icon("back")}</a>
457
+ <a class="icon-btn back" href="${opts.back}" aria-label="${S.back}">${icon("back")}</a>
466
458
  ${rows.length
467
459
  ? h`<button type="button" class="thread-title" data-context-toggle aria-controls="context">${title}</button>`
468
460
  : h`<div class="thread-title">${title}</div>`}
@@ -472,6 +464,7 @@ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextV
472
464
  <div class="messages" data-scroll-end>${join(items)}</div>
473
465
  ${when(opts.reply.allowed, () => h`<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
474
466
  ${when(opts.reply.replyAll, () => h`<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
467
+ <button type="button" class="icon-btn" aria-label="${S.attach}" title="${S.attach}" hx-post="/threads/${thread.id}/reply/full" hx-target="#edit-sheet" hx-swap="innerHTML">${icon("attach")}</button>
475
468
  <textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
476
469
  <button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
477
470
  <button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
@@ -493,23 +486,22 @@ export function archiveButton(thread: Thread): View {
493
486
  }
494
487
 
495
488
  export function devicesPage(sessions: Session[], currentId: string): View {
496
- return h`<div class="page">
497
- <h1>${S.navDevices}</h1>
498
- ${sessions.length ? join(sessions.map(s => h`<article class="card" id="session-${s.id}">
499
- <div class="meta">
500
- <strong>${s.label ?? s.user_agent ?? S.unknownDevice}</strong>
501
- ${when(s.id === currentId, () => h`<span class="badge">${S.thisDevice}</span>`)}
502
- ${when(s.scope, () => join(s.scope!.map(mailboxBadge)))}
503
- </div>
504
- ${when(s.label && s.user_agent, () => h`<div class="meta"><span>${s.user_agent}</span></div>`)}
505
- <div class="meta">
506
- <span>${S.signedIn}: ${formatDate(s.created_at)}</span>
507
- <span>${S.lastSeen}: ${formatDate(s.last_seen)}</span>
508
- <span>${S.createdBy}: ${s.created_by}</span>
509
- </div>
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>`)}
511
- </article>`)) : h`<p class="empty">${S.devicesEmpty}</p>`}
512
- </div>`;
489
+ return h`<section class="list">
490
+ <header class="list-head"><h1>${S.navDevices}</h1></header>
491
+ ${sessions.length ? join(sessions.map(s => h`<div class="row device" id="session-${s.id}">
492
+ <span class="avatar" aria-hidden="true">${icon("devices")}</span>
493
+ <span class="row-main">
494
+ <span class="row-top"><span class="who">${s.label ?? s.user_agent ?? S.unknownDevice}</span><time datetime="${s.last_seen}">${formatDate(s.last_seen)}</time></span>
495
+ ${when(s.label && s.user_agent, () => h`<span class="row-subject">${s.user_agent}</span>`)}
496
+ <span class="row-tags">
497
+ ${when(s.id === currentId, () => h`<span class="badge">${S.thisDevice}</span>`)}
498
+ ${when(s.scope, () => join(s.scope!.map(mailboxBadge)))}
499
+ <span class="row-by">${S.signedIn} ${formatDate(s.created_at)} · ${S.createdBy} ${s.created_by}</span>
500
+ </span>
501
+ </span>
502
+ ${when(s.id !== currentId, () => h`<button class="danger" hx-post="/devices/${s.id}/revoke" hx-target="#session-${s.id}" hx-swap="delete">${S.revoke}</button>`)}
503
+ </div>`)) : h`<p class="empty">${S.devicesEmpty}</p>`}
504
+ </section>`;
513
505
  }
514
506
 
515
507
  export function settingsPage(theme: Theme): View {