kaizen-agent 1.77.1 → 1.78.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,7 +4,7 @@ import { load, post } from "./api.ts";
4
4
  import { via } from "./cards.ts";
5
5
  import { mic, stopDictation } from "./dictation.ts";
6
6
  import { $, dataUrls, html, ico, modal, motion, pageOf, pager, pagerHtml, raw, SKEL, wirePager } from "./dom.ts";
7
- import { taskCombo, newDir, plogo, setShown, short, showable } from "./projects.ts";
7
+ import { plogo, setShown, short, showable } from "./projects.ts";
8
8
  import { playSound, soundPick, toast } from "./toast.ts";
9
9
  import { go, view } from "./views.ts";
10
10
 
@@ -24,6 +24,9 @@ const SRC = "Icebox";
24
24
  // The reply being written to a gathered post: its item, the text, and whether it is out.
25
25
  // The reply style is per project: a promo voice in one need not leak into another's drafts.
26
26
  let iceReply = null;
27
+ // The task ChatGPT drafted for the open promote form: its item key, whether it is still coming,
28
+ // the title and details, or why there is none. The person's own typing always wins.
29
+ let iceTask = null;
27
30
  const iceStyle = {};
28
31
  const icePg = pager("icebox");
29
32
  const rStyle = (dir) => {
@@ -54,6 +57,71 @@ let iceSwipe = null;
54
57
  let swHeld = false,
55
58
  swLate = false;
56
59
  const PLAT = { x: "X", tiktok: "TikTok", instagram: "Instagram", threads: "Threads" };
60
+ // What an item is: a client asked for it, you found it, or people say it (the server's KINDS).
61
+ const KIND = { client: "Client", finding: "Finding", people: "People say" };
62
+ // The capture box outlives every rebuild: its field and mic are kept nodes, so the text, the caret
63
+ // and a dictation in progress survive a server change. Files and the picked board wait with it.
64
+ const cap = { ta: null, mic: null, files: [], board: "", boardDir: null, dir: null, busy: false };
65
+ // Cards or Sort, per browser; the board and kind filters; the item menu that is open ("<item key> <menu>").
66
+ let iceView = "cards";
67
+ try {
68
+ iceView = localStorage.getItem("kz-ice-view") === "sort" ? "sort" : "cards";
69
+ } catch (e) {}
70
+ let iceBoard = "",
71
+ iceMenu = "",
72
+ // When the open menu was drawn: the redraw that shows it restores the scroll, and that scroll
73
+ // event must not shut it again.
74
+ iceMenuAt = 0,
75
+ iceMenuFor = "";
76
+ const iceKinds = new Set();
77
+ // Wired on the first open, not at import: tests load this module with no window.
78
+ let narrowQ = null;
79
+ function wireOnce() {
80
+ if (narrowQ) return;
81
+ narrowQ = matchMedia("(max-width:640px)");
82
+ // A window crossing 640 px swaps cards for the list.
83
+ narrowQ.addEventListener("change", () => view === "sources" && srcOpen() && openSources());
84
+ // A click anywhere but a menu or its button shuts the open item menu.
85
+ document.addEventListener("click", (e) => {
86
+ if (!iceMenu || (e.target as Element).closest?.(".ice-mpop,[data-m]")) return;
87
+ iceMenu = "";
88
+ if (view === "sources" && srcOpen()) openSources();
89
+ });
90
+ }
91
+ // A new collection: its name and whether it is a client's, asked in the board's own dialog
92
+ // (the desktop app has no window.prompt). Resolves null when cancelled.
93
+ function askCollection(where = ""): Promise<{ name: string; client: boolean } | null> {
94
+ return new Promise((done) => {
95
+ const dl = modal(html`<label class="hint" for="ice-cn" style="margin:0">New collection${where ? ` in ${where}` : ""}: a client or a topic</label><input class="sel" id="ice-cn" maxlength="40" placeholder="e.g. Arupadatu, Pricing" autocomplete="off" spellcheck="false"><label class="ice-cn-cl"><input type="checkbox" id="ice-cn-c"> A client — its items count as Client</label><div class="row"><button type="button" class="btn ghost" value="">Cancel</button><button class="btn pri">Create</button></div>`);
96
+ const f = dl.querySelector("form"), inp = dl.querySelector("#ice-cn") as HTMLInputElement;
97
+ let answer = null;
98
+ dl.querySelector(".btn.ghost").onclick = () => dl.close();
99
+ f.onsubmit = (e) => {
100
+ e.preventDefault();
101
+ const name = inp.value.trim();
102
+ if (!name) return inp.focus();
103
+ answer = { name, client: (dl.querySelector("#ice-cn-c") as HTMLInputElement).checked };
104
+ dl.close();
105
+ };
106
+ dl.addEventListener("close", () => done(answer));
107
+ inp.focus();
108
+ });
109
+ }
110
+ // A person mark for a client's collection.
111
+ const PERSON = raw(
112
+ '<svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="5.2" r="2.6" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M3 13.6c.7-2.5 2.6-3.8 5-3.8s4.3 1.3 5 3.8" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',
113
+ );
114
+ const sameName = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
115
+ // The day a snooze lands on, said as the server works it out (1d, 1w, 1m or a date).
116
+ const wakeDay = (until) => {
117
+ const d = new Date();
118
+ if (until === "1d") d.setDate(d.getDate() + 1);
119
+ else if (until === "1w") d.setDate(d.getDate() + 7);
120
+ else if (until === "1m") d.setMonth(d.getMonth() + 1);
121
+ else return new Date(until + "T00:00:00");
122
+ return d;
123
+ };
124
+ const ymd = (d) => d.toLocaleDateString("sv");
57
125
  export const srcOpen = () => $("panel").classList.contains("open") && $("ptitle").textContent === SRC;
58
126
  const ago = (at) => {
59
127
  const m = Math.round((Date.now() - Date.parse(at)) / 60000);
@@ -125,8 +193,10 @@ export async function openSources() {
125
193
  return;
126
194
  }
127
195
  if (view !== "sources") return;
196
+ wireOnce();
128
197
  const gen = ++store.pageGen;
129
- stopDictation(true);
198
+ // A dictation into the capture box keeps going: its field is carried over, not rebuilt.
199
+ stopDictation(!$("ice-cap"));
130
200
  // What is half typed survives a refresh from the server.
131
201
  const typed = srcOpen()
132
202
  ? [
@@ -145,8 +215,10 @@ export async function openSources() {
145
215
  );
146
216
  // And a promote form half filled, for the item it was typed on.
147
217
  // And which control of which inbox row had focus, by item key: row indices shift when a row goes.
148
- const fRow = srcOpen() && document.activeElement?.closest?.(".ice-row"),
218
+ const fRow = srcOpen() && document.activeElement?.closest?.(".ice-row,.ice-card"),
149
219
  fPick = fRow ? [fRow.dataset.k, document.activeElement.id.replace(/-\d+$/, "")] : null;
220
+ // And a Snooze date half picked in an open menu.
221
+ const sdKeep = srcOpen() && $("ice-sd")?.value ? [iceMenu, $("ice-sd").value] : null;
150
222
  const iceDraft =
151
223
  srcOpen() && $("ice-title") ? [$("ice-title").dataset.k, $("ice-title").value, $("ice-details").value] : null;
152
224
  // And a category typed on a row but not yet saved.
@@ -211,7 +283,7 @@ export async function openSources() {
211
283
  // left out of the list, the count and Swipe until its date (the server says `asleep`).
212
284
  awake = ((d && d.icebox) || []).filter((it) => !it.asleep),
213
285
  ice = [...awake, ...((d && d.dismissed) || [])],
214
- waiting = awake.length,
286
+ waiting = awake.filter((it) => it.status === "new").length,
215
287
  G = (d && d.gatherer) || {},
216
288
  chatOn = G.use === "chatgpt" && G.connected;
217
289
  // A source belongs to one project, named on its row. Picking another only arms Move: a select
@@ -261,7 +333,9 @@ export async function openSources() {
261
333
  ? "Dismissed"
262
334
  : it.status === "done"
263
335
  ? "Done"
264
- : it.category || srcOf(it)?.category || platOf(srcOf(it) || { url: it.source }),
336
+ : it.status === "promoted"
337
+ ? "Promoted"
338
+ : it.category || srcOf(it)?.category || platOf(srcOf(it) || { url: it.source }),
265
339
  count = (xs, f) => {
266
340
  const m = new Map();
267
341
  xs.forEach((it) => {
@@ -279,27 +353,31 @@ export async function openSources() {
279
353
  }
280
354
  const inProj = (it) => dir || !store.shown.size || store.shown.has(it.dir),
281
355
  pv = ice.filter(inProj);
282
- const byCat = count(pv, catOf);
356
+ const isWaiting = (it) => !["promoted", "dismissed", "done"].includes(it.status);
357
+ // Boards, then kinds, narrow before category and source. A board is its name: two projects'
358
+ // boards of one name are one chip in All projects.
359
+ const boards = [...new Map(((d && d.boards) || []).filter(inProj).map((b) => [b.name.toLowerCase(), b])).values()];
360
+ if (iceBoard && !boards.some((b) => sameName(b.name, iceBoard))) iceBoard = "";
361
+ const onBoard = (it) => !iceBoard || sameName(it.board, iceBoard),
362
+ ofKind = (it) => !iceKinds.size || iceKinds.has(it.kind);
363
+ const byCat = count(pv.filter((it) => onBoard(it) && ofKind(it)), catOf);
283
364
  if (iceCat && !byCat.has(iceCat)) iceCat = "";
284
- const cv = pv.filter((it) => !iceCat || catOf(it) === iceCat);
365
+ const cv = pv.filter((it) => onBoard(it) && ofKind(it) && (!iceCat || catOf(it) === iceCat));
285
366
  const bySrc = count(cv, srcKey);
286
367
  if (iceSrc && !bySrc.has(iceSrc)) iceSrc = "";
287
368
  const keys = new Set(ice.map(iceKey));
288
369
  if (iceForm && !keys.has(iceForm)) iceForm = null;
289
370
  if (icePro !== iceForm) icePro = null;
290
- const groups = new Map();
291
- ice.forEach((it, i) => {
292
- if (!inProj(it) || (iceCat ? catOf(it) !== iceCat : it.status === "dismissed" || it.status === "done") || (iceSrc && srcKey(it) !== iceSrc)) return;
293
- const k = catOf(it);
294
- groups.has(k) || groups.set(k, []);
295
- groups.get(k).push(i);
296
- });
297
- // Rows in the order they are drawn, which is the order j and k walk.
298
- const filtered = [...groups.values()].flat();
371
+ // Newest first, in the order they are drawn, which is the order j and k walk. Category is a filter.
372
+ const filtered = ice
373
+ .map((_, i) => i)
374
+ .filter((i) => {
375
+ const it = ice[i];
376
+ return inProj(it) && onBoard(it) && ofKind(it) && (iceCat ? catOf(it) === iceCat : it.status === "new") && (!iceSrc || srcKey(it) === iceSrc);
377
+ })
378
+ .sort((a, b) => (Date.parse(ice[b].at) || 0) - (Date.parse(ice[a].at) || 0));
299
379
  // Only the page: j and k, select-all and bulk actions stay on what shows.
300
380
  const order = pageOf(icePg, filtered);
301
- const onPage = new Set(order);
302
- const isWaiting = (it) => !["promoted", "dismissed", "done"].includes(it.status);
303
381
  // A checked request a filter hides is unchecked: a bulk action only ever acts on what shows.
304
382
  {
305
383
  const vis = new Set(order.map((i) => iceKey(ice[i])));
@@ -325,8 +403,8 @@ export async function openSources() {
325
403
  const srcIco = (it) => fav(it.source, "link", srcOf(it)?.social);
326
404
  const curSrc = iceSrc && [...bySrc].find(([k]) => k === iceSrc)?.[1].it;
327
405
  const chips = html`${
328
- // Dismissed and Done are hidden until picked, so even a lone one is a choice.
329
- byCat.size > 1 || byCat.has("Dismissed") || byCat.has("Done")
406
+ // Promoted, Dismissed and Done are hidden until picked, so even a lone one is a choice.
407
+ byCat.size > 1 || byCat.has("Dismissed") || byCat.has("Done") || byCat.has("Promoted")
330
408
  ? pick(
331
409
  "ice-fc",
332
410
  "Category",
@@ -345,14 +423,35 @@ export async function openSources() {
345
423
  )}`,
346
424
  )
347
425
  : ""}`;
348
- const bar = html`<div class="tk-bar ice-bar">${order.length ? html`<input type="checkbox" id="ice-all" aria-label="Select every request shown"${nSel && nSel === order.length ? " checked" : ""}>` : ""}<span class="count">${iceCat === "Dismissed" || iceCat === "Done" ? `${order.length} ${iceCat.toLowerCase()}` : `${order.length < waiting ? `${order.length} of ${waiting}` : waiting} waiting`}</span><span class="end"></span>${String(chips) ? html`<details class="ice-filt"><summary class="ib${iceCat || iceSrc ? " on" : ""}" aria-label="Filter requests" title="Filter requests">${ico("filter")}</summary><div class="ice-fpop">${chips}</div></details>` : ""}${order.some((i) => isWaiting(ice[i])) ? html`<button class="btn ghost sm" id="ice-sw" title="Sort one at a time: swipe right to promote, left to dismiss"><span aria-hidden="true">⇆</span> Swipe</button>` : ""}<button class="btn ghost sm" id="ice-new" title="Add a request by hand">${ico("plus")} Add</button><button class="btn sm" id="src-go"${list.length ? "" : " disabled"}>${ico("refresh")} Gather all</button><button class="btn ghost sm" id="src-tog" aria-expanded="${String(!!srcShow)}" aria-controls="src-sec">${ico("link")} Sources · ${list.length}</button></div>`;
426
+ // Under 640 px there are no cards: the list shows, and the switch goes.
427
+ const narrow = narrowQ.matches,
428
+ cardsOn = iceView === "cards" && !narrow;
429
+ // The boards bar: All, each board with what waits on it, + Board; the kind filters on the right.
430
+ const nOn = (b) => pv.filter((it) => isWaiting(it) && sameName(it.board, b.name)).length;
431
+ const boardsBar = html`<div class="ice-boards"><div class="ice-chips" role="group" aria-label="Collections"><button class="ice-chip${iceBoard ? "" : " on"}" data-bd="" aria-pressed="${String(!iceBoard)}">All</button>${boards.map((b) => html`<button class="ice-chip${sameName(iceBoard, b.name) ? " on" : ""}" data-bd="${b.name}" aria-pressed="${String(sameName(iceBoard, b.name))}"${b.client ? raw(' title="A client\'s collection: its items are Client"') : ""}>${b.client ? PERSON : ""}<span>${b.name}</span><i>${nOn(b)}</i></button>`)}<button class="ice-chip add" id="ice-nb" title="Make a collection for a client or a topic">${ico("plus")}Collection</button></div><div class="ice-chips" role="group" aria-label="Kinds">${Object.entries(KIND).map(([k, l]) => html`<button class="ice-chip k-${k}${iceKinds.has(k) ? " on" : ""}" data-kf="${k}" aria-pressed="${String(iceKinds.has(k))}">${l}</button>`)}</div></div>`;
432
+ const bar = html`<div class="tk-bar ice-bar">${!cardsOn && !narrow && order.length ? html`<input type="checkbox" id="ice-all" aria-label="Select every request shown"${nSel && nSel === order.length ? " checked" : ""}>` : ""}${narrow ? "" : html`<div class="ice-view" role="group" aria-label="View"><button data-view="cards" aria-pressed="${String(cardsOn)}">Cards</button><button data-view="sort" aria-pressed="${String(!cardsOn)}">Sort</button></div>`}<span class="count">${iceCat === "Dismissed" || iceCat === "Done" || iceCat === "Promoted" ? `${order.length} ${iceCat.toLowerCase()}` : `${order.length < waiting ? `${order.length} of ${waiting}` : waiting} waiting`}</span><span class="end"></span>${String(chips) ? html`<details class="ice-filt"><summary class="ib${iceCat || iceSrc ? " on" : ""}" aria-label="Filter requests" title="Filter by category or source">${ico("filter")}</summary><div class="ice-fpop">${chips}</div></details>` : ""}${order.some((i) => isWaiting(ice[i])) ? html`<button class="btn ghost sm" id="ice-sw" title="Sort one at a time: swipe right to promote, left to dismiss"><span aria-hidden="true">⇆</span> Swipe</button>` : ""}${narrow ? "" : html`<button class="btn sm" id="src-tog" aria-expanded="${String(!!srcShow)}" aria-controls="src-sec" title="Sources, and Gather all">${ico("link")} Sources · ${list.length}</button>`}</div>`;
433
+ // The capture box: what is typed, pasted, attached or dictated lands in the icebox on the picked
434
+ // board. In All projects it names the project, as the Add pop-up did. Field and mic are slotted in.
435
+ const capPs = dir ? [] : showable();
436
+ if (!dir && !capPs.some((p) => p.dir === cap.dir))
437
+ cap.dir = (store.shown.size === 1 ? [...store.shown][0] : null) || capPs[0]?.dir || null;
438
+ const capTo0 = dir || cap.dir;
439
+ // A board picked for another project never goes along when the box's project changes.
440
+ if (cap.board && cap.boardDir && cap.boardDir !== capTo0) cap.board = "";
441
+ const capTo = capTo0,
442
+ capP = capPs.find((p) => p.dir === cap.dir);
443
+ const capBoards = ((d && d.boards) || []).filter((b) => b.dir === capTo);
444
+ const capBox = html`<div class="ice-cap" id="ice-cap"><span id="ice-cap-slot"></span>${cap.files.length ? html`<div class="ice-att">${cap.files.map((f, n) => html`<span class="ice-file">${ico("clip")}<span>${f.name}</span><button type="button" class="ib sm" data-rf="${n}" aria-label="Remove ${f.name}" title="Remove">${ico("x")}</button></span>`)}</div>` : ""}<div class="ice-cap-row"><button type="button" class="ib" id="ice-pick" aria-label="Attach files" title="Attach files">${ico("clip")}</button><span id="ice-mic-slot"></span><input type="file" id="ice-file" multiple hidden>${dir ? "" : pick("ice-cp", "Project", capP ? html`${plogo(capP.dir, capP.label)}<span>${short(capP.label)}</span>` : html`<span>Choose project</span>`, html`${capPs.map((p) => opt(p.dir, p.dir === cap.dir, html`${plogo(p.dir, p.label)}<span>${p.label}</span>`, p.label))}`)}${pick("ice-cb", "Collection", html`<span>${cap.board || "Inbox"}</span>`, html`${opt("", !cap.board, html`<span>Inbox</span>`, "inbox")}${capBoards.map((b) => opt(b.name, sameName(cap.board, b.name), html`${b.client ? PERSON : ""}<span>${b.name}</span>`, b.name))}${cap.board && !capBoards.some((b) => sameName(b.name, cap.board)) ? opt(cap.board, true, html`<span>${cap.board}</span><i>new</i>`, cap.board) : ""}${opt("\n", false, html`${ico("plus")}<span>New collection…</span>`, "new collection")}`)}<span class="end"></span><button type="button" class="btn pri sm" id="ice-save" aria-label="Save to the icebox"${cap.busy ? " disabled" : ""}>${ico("send")}<span>${cap.busy ? "Saving…" : "Save ↵"}</span></button></div></div>`;
349
445
  const bulk = iceSel.size
350
- ? html`<div class="ice-bulk" role="toolbar" aria-label="Selected requests"><span>${iceSel.size} selected</span><span class="end"></span><button class="btn sm" id="ice-bp" title="Promote (p)">${ico("plus")} Promote</button><button class="btn ghost sm" id="ice-bd" title="Dismiss (d)">${ico("x")} Dismiss</button><button class="btn ghost sm" id="ice-bc" title="Clear selection (Esc)">Clear</button></div>`
446
+ ? html`<div class="ice-bulk" role="toolbar" aria-label="Selected requests"><span>${iceSel.size} selected</span><span class="end"></span><button class="btn sm" id="ice-bp" title="Promote (p)">${ico("plus")} Promote</button><button class="btn ghost sm" id="ice-bz" title="Snooze a week (h)">${ico("clock")} Snooze</button><button class="btn ghost sm" id="ice-bd" title="Dismiss (d)">${ico("x")} Dismiss</button><button class="btn ghost sm" id="ice-bc" title="Clear selection (Esc)">Clear</button></div>`
351
447
  : "";
352
448
  // The open item's form: a clean title for the task's card and the person's own details;
353
449
  // what was gathered is added to the task's notes by the server.
354
- const form = (it) =>
355
- html`<div class="ice-form"><label for="ice-title" class="hint" style="margin:0">Task title</label><input class="sel" id="ice-title" data-k="${iceKey(it)}" maxlength="200" value="${it.text}" aria-label="Task title"><label for="ice-details" class="hint" style="margin:0">Details</label><textarea class="sel" id="ice-details" rows="3" aria-label="Details"></textarea><div class="ice-form-acts"><span class="end"></span><button class="btn ghost sm" id="ice-cancel">Cancel</button><button class="btn pri sm" id="ice-ok">Promote</button></div></div>`;
450
+ const form = (it) => {
451
+ const t = iceTask && iceTask.k === iceKey(it) ? iceTask : null,
452
+ say = t?.wait ? "Drafting a task with ChatGPT…" : t?.kept ? "ChatGPT's draft came after you started typing, so your words stay. Redraft to use it." : t?.note ? `No draft: ${t.note}` : t?.title ? "Drafted by ChatGPT. Edit it before promoting." : "";
453
+ return html`<div class="ice-form"><label for="ice-title" class="hint" style="margin:0">Task title</label><input class="sel" id="ice-title" data-k="${iceKey(it)}" maxlength="200" value="${t?.title || it.text}" aria-label="Task title"><label for="ice-details" class="hint" style="margin:0">Details</label><textarea class="sel" id="ice-details" rows="${t?.details ? 5 : 3}" aria-label="Details">${t?.details || ""}</textarea>${say ? html`<span class="hint ice-tdraft" id="ice-tdn" role="status" style="margin:0">${say}</span>` : ""}<div class="ice-form-acts">${G.connected ? html`<button class="btn ghost sm" id="ice-td"${t?.wait ? " disabled" : ""} title="Ask ChatGPT for another draft">${ico("ai")}${t?.title ? "Redraft" : "Draft with ChatGPT"}</button>` : ""}<span class="end"></span><button class="btn ghost sm" id="ice-cancel">Cancel</button><button class="btn pri sm" id="ice-ok">Promote</button></div></div>`;
454
+ };
356
455
  // A gathered post can be answered: Reply drafts, the box is the approval, Send reply posts that text.
357
456
  const replyBox = (it) => {
358
457
  if (!it.post) return "";
@@ -368,24 +467,87 @@ export async function openSources() {
368
467
  if (r.wait) return html`<div class="ice-form-acts"><span class="hint">Drafting…</span></div>`;
369
468
  return html`<div class="ice-form"><label for="ice-reply" class="hint" style="margin:0">Your reply${r.note ? ` · ${r.note}` : ""}</label><textarea class="sel" id="ice-reply" rows="3" maxlength="2000" aria-label="Your reply"${r.busy || r.again ? " disabled" : ""}>${r.text}</textarea><span class="hint" id="ice-rn" style="margin:0">${r.again ? "Writing another…" : `${r.text.length} chars`}</span><div class="ice-form-acts"><span class="end"></span>${G.connected ? html`${style(r.busy || r.again)}<button class="btn ghost sm" id="ice-rg"${r.busy || r.again ? " disabled" : ""}>Regenerate</button>` : ""}<button class="btn ghost sm" id="ice-rc"${r.busy ? " disabled" : ""}>Cancel</button><button class="btn pri sm" id="ice-rs"${r.busy || r.again || !r.text.trim() ? " disabled" : ""}>${r.busy ? "Sending…" : "Send reply"}</button></div></div>`;
370
469
  };
371
- const imgs = (it) =>
372
- (it.images || []).filter((u) => /^https:\/\//.test(u)).length ? html`<details class="ice-imgs"><summary>Show images (${it.images.filter((u) => /^https:\/\//.test(u)).length}) — loads them from the source's site</summary>${it.images.filter((u) => /^https:\/\//.test(u)).map((u, n) => { const src = `/ice-image?dir=${encodeURIComponent(it.dir)}&id=${encodeURIComponent(it.id)}&i=${n}`; return html`<a href="${src}" target="_blank" rel="noopener noreferrer"><img data-src="${src}" alt="" referrerpolicy="no-referrer"></a>`; })}</details>` : "";
470
+ const imgs = (it, card = false) =>
471
+ (it.images || []).filter((u) => /^https:\/\//.test(u)).length ? html`<details class="ice-imgs"><summary${card ? raw(' title="Loads them from the source\'s site"') : ""}>${card ? `${it.images.filter((u) => /^https:\/\//.test(u)).length} pictures · show` : `Show images (${it.images.filter((u) => /^https:\/\//.test(u)).length}) — loads them from the source's site`}</summary>${it.images.filter((u) => /^https:\/\//.test(u)).map((u, n) => { const src = `/ice-image?dir=${encodeURIComponent(it.dir)}&id=${encodeURIComponent(it.id)}&i=${n}`; return html`<a href="${src}" target="_blank" rel="noopener noreferrer"><img data-src="${src}" alt="" referrerpolicy="no-referrer"></a>`; })}</details>` : "";
472
+ // The pieces rows and cards share. Only a waiting item has menus; Snooze needs one too.
473
+ const live = (it) => it.status === "new";
474
+ const kindOf = (it) => html`<span class="ice-k k-${it.kind || "none"}">${KIND[it.kind] || "Unsorted"}</span>`;
475
+ const menuBtn = (i, it, m, inner, cls, label) =>
476
+ html`<button type="button" class="${cls}" id="ice-m${m[0]}-${i}" data-m="${m}" data-mi="${i}" aria-haspopup="menu" aria-expanded="${String(iceMenu === iceKey(it) + " " + m)}" title="${label}" aria-label="${label}: ${it.text}">${inner}</button>`;
477
+ // The open item menu, drawn inside its row or card: Snooze, Kind or Board.
478
+ const menu = (i, it) => {
479
+ const k = iceKey(it),
480
+ m = iceMenu.startsWith(k + " ") ? iceMenu.slice(k.length + 1) : "";
481
+ if (!m) return "";
482
+ const b = (attr, v, label, on = false) => html`<button type="button" role="menuitem" ${raw(attr)}="${v}"${on ? raw(' class="on" aria-current="true"') : ""}>${label}</button>`;
483
+ const day = (n) => ymd(new Date(Date.now() + n * 864e5));
484
+ const inner =
485
+ m === "snooze"
486
+ ? html`${b("data-sz", "1d", "Tomorrow")}${b("data-sz", "1w", "Next week")}${b("data-sz", "1m", "Next month")}<div class="ice-date"><input type="date" class="sel" id="ice-sd" min="${day(1)}" max="${day(365)}" aria-label="Snooze until"><button type="button" class="btn sm" data-sz="">Snooze</button></div>`
487
+ : m === "kind"
488
+ ? html`${Object.entries(KIND).map(([v, l]) => b("data-kd", v, l, it.kind === v && it.sorted !== "rules"))}`
489
+ : html`${b("data-bo", "", "Inbox", !it.board)}${((d && d.boards) || []).filter((x) => x.dir === it.dir).map((x) => b("data-bo", x.name, html`${x.client ? PERSON : ""}${x.name}`, sameName(it.board, x.name)))}<button type="button" role="menuitem" data-bo-new="1">${ico("plus")}New collection…</button>`;
490
+ return html`<div class="menu-pop ice-mpop" role="menu" data-mi="${i}" aria-label="${m === "snooze" ? "Snooze until" : m === "kind" ? "Kind" : "Collection"}">${inner}</div>`;
491
+ };
492
+ const badges = (it) =>
493
+ html`${it.status === "done" && it.written ? html`<span title="Written back ${ago(it.written)}">written back</span>` : ""}${it.status === "done" && it.writeError ? html`<span title="${it.writeError}">write-back failed</span>` : ""}${it.status === "promoted" ? html`<span title="Promoted to Tasks: ${it.idea || ""}">promoted</span>` : ""}${it.replied ? html`<span title="Replied ${ago(it.replied)}">replied</span>` : ""}`;
494
+ const proj = (it) => (many ? html`<span class="nm" title="${it.project || ""}">${plogo(it.dir, it.project || "")}${short(it.project || "")}</span>` : "");
373
495
  const row = (i) => {
374
496
  const it = ice[i],
375
497
  k = iceKey(it),
376
498
  open = iceForm === k;
377
- const head = html`<div class="ice-row${iceCur === k ? " cur" : ""}${iceSel.has(k) ? " sel" : ""}" data-i="${i}" data-k="${k}"><input type="checkbox" id="ice-ck-${i}" data-ck="${i}"${iceSel.has(k) ? " checked" : ""} aria-label="Select: ${it.text}"><span class="ice-src" title="${srcName(it)}">${fav(it.source, "link", list.find((x) => x.dir === it.dir && x.url === it.source)?.social)}</span><button class="ice-t" id="ice-o-${i}" data-o="${i}" aria-expanded="${String(open)}" title="${it.text}">${it.text}</button><span class="ice-meta">${many ? html`<span class="nm" title="${it.project || ""}">${plogo(it.dir, it.project || "")}${short(it.project || "")}</span>` : ""}${it.status === "done" && it.written ? html`<span title="Written back ${ago(it.written)}">written back</span>` : ""}${it.status === "done" && it.writeError ? html`<span title="${it.writeError}">write-back failed</span>` : ""}${it.status === "promoted" ? html`<span title="Promoted to Tasks: ${it.idea || ""}">promoted</span>` : ""}${it.replied ? html`<span title="Replied ${ago(it.replied)}">replied</span>` : ""}<span class="ice-age">${ago(it.at)}</span><span class="ice-ra">${it.status === "promoted" || it.status === "done" ? "" : html`<button class="btn ghost sm" id="ice-pr-${i}" data-pr="${i}" title="Promote to Tasks (p)" aria-label="Promote to Tasks: ${it.text}">${ico("plus")}</button>`}${it.status === "promoted" || it.status === "done" ? "" : it.status === "dismissed" ? html`<button class="btn ghost sm" id="ice-rs-${i}" data-rs="${i}" title="Restore to waiting" aria-label="Restore: ${it.text}">Restore</button>` : html`<button class="btn ghost sm" id="ice-ds-${i}" data-ds="${i}" title="Dismiss (d)" aria-label="Dismiss: ${it.text}">${ico("x")}</button>`}</span></span></div>`;
499
+ const head = html`<div class="ice-row${iceCur === k ? " cur" : ""}${iceSel.has(k) ? " sel" : ""}" data-i="${i}" data-k="${k}"><input type="checkbox" id="ice-ck-${i}" data-ck="${i}"${iceSel.has(k) ? " checked" : ""} aria-label="Select: ${it.text}">${live(it) ? menuBtn(i, it, "kind", kindOf(it), "ice-kb", "Kind") : kindOf(it)}<span class="ice-src" title="${srcName(it)}">${fav(it.source, "link", srcOf(it)?.social)}</span><button class="ice-t" id="ice-o-${i}" data-o="${i}" aria-expanded="${String(open)}" title="${it.text}">${it.text}</button><span class="ice-meta">${proj(it)}${badges(it)}${live(it) ? menuBtn(i, it, "board", it.board || "Inbox", "ice-bo" + (it.board ? "" : " none"), "Collection") : it.board ? html`<span>${it.board}</span>` : ""}<span class="ice-age">${ago(it.at)}</span><span class="ice-ra">${it.status === "promoted" || it.status === "done" ? "" : html`<button class="btn ghost sm" id="ice-pr-${i}" data-pr="${i}" title="Promote to Tasks (p)" aria-label="Promote to Tasks: ${it.text}">${ico("plus")}</button>`}${live(it) ? menuBtn(i, it, "snooze", ico("clock"), "btn ghost sm", "Snooze (h: a week)") : ""}${it.status === "promoted" || it.status === "done" ? "" : it.status === "dismissed" ? html`<button class="btn ghost sm" id="ice-rs-${i}" data-rs="${i}" title="Restore to waiting" aria-label="Restore: ${it.text}">Restore</button>` : html`<button class="btn ghost sm" id="ice-ds-${i}" data-ds="${i}" title="Dismiss (d)" aria-label="Dismiss: ${it.text}">${ico("x")}</button>`}</span></span>${menu(i, it)}</div>`;
378
500
  const more = open
379
501
  ? html`<div class="ice-open">${it.notes ? html`<div class="ice-notes">${it.notes}</div>` : ""}${imgs(it)}<span class="hint" style="margin:0">From ${srcName(it)} · ${ago(it.at)}${it.post ? html` · <a href="${web(it.post)}" target="_blank" rel="noopener">open post</a>` : ""}</span>${replyBox(it)}${icePro === k ? form(it) : ""}</div>`
380
502
  : "";
381
503
  return html`${head}${more}`;
382
504
  };
505
+ const hue = (t) => [...t].reduce((a, c) => (a * 31 + c.charCodeAt(0)) % 360, 7);
506
+ // A phone row (under 640 px): kind, two lines, board and age, a thumbnail for a link (its
507
+ // site's hue and letter) or pictures (an icon and the count: nothing is fetched from their
508
+ // site), → Task. A swipe decides it: right a task, left dismissed; a long press snoozes.
509
+ const thumb = (it) => {
510
+ const lk = it.link && /^https?:\/\//i.test(it.link.url) ? it.link : null,
511
+ n = (it.images || []).filter((u) => /^https:\/\//.test(u)).length;
512
+ if (lk) {
513
+ const site = host(lk.url).replace(/^www\./, "");
514
+ return html`<span class="ice-th" style="--h:${hue(site)}" title="${lk.title || site}" aria-hidden="true">${(site[0] || "").toUpperCase()}</span>`;
515
+ }
516
+ return n ? html`<span class="ice-th pic" title="${n} pictures" aria-hidden="true">${ico("img")}<i>${n}</i></span>` : "";
517
+ };
518
+ const prow = (i) => {
519
+ const it = ice[i],
520
+ k = iceKey(it),
521
+ open = iceForm === k,
522
+ done = it.status === "promoted" || it.status === "done";
523
+ const head = html`<div class="ice-row ice-prow${iceCur === k ? " cur" : ""}" data-i="${i}" data-k="${k}"${live(it) ? raw(' data-swipe="1"') : ""}><div class="ice-pbg" aria-hidden="true"><span class="pro">${ico("check")}Task</span><span class="dis">Dismiss${ico("x")}</span></div><div class="ice-pf"><div class="ice-pm"><div class="ice-ph">${live(it) ? menuBtn(i, it, "kind", kindOf(it), "ice-kb", "Kind") : kindOf(it)}${it.sorted === "rules" && live(it) ? html`<span class="ice-uns">unsorted</span>` : ""}<span class="ice-meta">${badges(it)}</span></div><button class="ice-t" id="ice-o-${i}" data-o="${i}" aria-expanded="${String(open)}">${it.text}</button><span class="ice-pmeta">${proj(it)}${it.board ? html`<span>${it.board}</span>` : ""}<span>${ago(it.at)}</span></span></div>${thumb(it)}${done ? "" : it.status === "dismissed" ? html`<button class="btn ghost sm" id="ice-rs-${i}" data-rs="${i}" aria-label="Restore: ${it.text}">Restore</button>` : html`<button class="ib ice-ptask" id="ice-pr-${i}" data-pr="${i}" aria-label="Make a task: ${it.text}" title="Make a task">${ico("arrow")}</button>`}</div>${menu(i, it)}</div>`;
524
+ // Opened, a phone row also offers what its gestures do, for anyone who cannot swipe or hold.
525
+ const acts = live(it)
526
+ ? html`<div class="ice-form-acts ice-pacts">${menuBtn(i, it, "snooze", html`${ico("clock")}Snooze`, "btn ghost sm", "Snooze")}${menuBtn(i, it, "board", html`${it.board || "Inbox"}`, "btn ghost sm", "Collection")}<span class="end"></span><button class="btn ghost sm" id="ice-ds-${i}" data-ds="${i}" aria-label="Dismiss: ${it.text}">${ico("x")}Dismiss</button></div>`
527
+ : "";
528
+ const more = open
529
+ ? html`<div class="ice-open">${it.notes ? html`<div class="ice-notes">${it.notes}</div>` : ""}${imgs(it)}<span class="hint" style="margin:0">From ${srcName(it)} · ${ago(it.at)}${it.post ? html` · <a href="${web(it.post)}" target="_blank" rel="noopener">open post</a>` : ""}</span>${acts}${replyBox(it)}${icePro === k ? form(it) : ""}</div>`
530
+ : "";
531
+ return html`${head}${more}`;
532
+ };
533
+ // A card: what it is, the words, where it sits, how old. A link leads with its title and summary,
534
+ // coloured from the site's name; nothing is fetched from the site to draw it.
535
+ const cardOf = (i) => {
536
+ const it = ice[i],
537
+ k = iceKey(it),
538
+ lk = it.link && /^https?:\/\//i.test(it.link.url) ? it.link : null,
539
+ site = lk ? host(lk.url).replace(/^www\./, "") : "";
540
+ const acts = html`${it.status === "promoted" || it.status === "done" ? "" : html`<button class="btn ghost sm" id="ice-pr-${i}" data-pr="${i}" title="Promote to Tasks (p)" aria-label="Promote to Tasks: ${it.text}">${ico("arrow")}Task</button>`}${live(it) ? html`${menuBtn(i, it, "snooze", html`${ico("clock")}Snooze`, "btn ghost sm", "Snooze")}${menuBtn(i, it, "kind", "Kind", "btn ghost sm", "Kind")}${menuBtn(i, it, "board", "Collection", "btn ghost sm", "Collection")}` : ""}<span class="end"></span>${it.status === "promoted" || it.status === "done" ? "" : it.status === "dismissed" ? html`<button class="btn ghost sm" id="ice-rs-${i}" data-rs="${i}" title="Restore to waiting" aria-label="Restore: ${it.text}">Restore</button>` : html`<button class="btn ghost sm" id="ice-ds-${i}" data-ds="${i}" title="Dismiss (d)" aria-label="Dismiss: ${it.text}">${ico("x")}</button>`}`;
541
+ return html`<article class="ice-card${iceCur === k ? " cur" : ""}" data-i="${i}" data-k="${k}">${lk ? html`<a class="ice-lk" href="${web(lk.url)}" target="_blank" rel="noopener noreferrer" style="--h:${hue(site)}"><b>${lk.title || site}</b>${lk.summary ? html`<span>${lk.summary}</span>` : ""}<small>${site}</small></a>` : ""}<div class="ice-cb"><div class="ice-ch">${kindOf(it)}${it.sorted === "rules" && live(it) ? html`<span class="ice-uns" title="Kind set by a rule: pick one with Kind">unsorted</span>` : ""}<span class="ice-meta">${badges(it)}</span></div><button class="ice-ct" id="ice-o-${i}" data-o="${i}" title="Open in the Sort list">${it.text}</button>${imgs(it, true)}<div class="ice-cf">${it.board ? html`<span class="ice-cbd">${it.board}</span>` : ""}${(it.tags || []).map((t) => html`<span class="ice-tag">#${t}</span>`)}${proj(it)}<span class="end"></span><span class="ice-when">${it.source !== "manual" ? `${srcName(it)} · ` : ""}${ago(it.at)}</span></div></div><div class="ice-ca">${acts}</div>${menu(i, it)}</article>`;
542
+ };
383
543
  const inbox =
384
544
  waiting && !order.length
385
545
  ? html`<div class="ice-zero"><h4>No matches</h4><p style="margin-top:10px"><button class="btn sm" id="ice-unf">Clear filters</button></p></div>`
386
546
  : order.length
387
- ? html`<div class="tk-list ice-list">${[...groups].map(([g, ix]) => (ix.some((i) => onPage.has(i)) ? html`<div class="ice-cat">${g}<i>${ix.length}</i></div>${ix.filter((i) => onPage.has(i)).map(row)}` : ""))}${pagerHtml(icePg)}</div>`
388
- : html`<div class="ice-zero"><h4>Nothing waiting</h4><p>Requests gathered from your sources wait here until you turn them into tasks.</p>${list.length ? "" : html`<p style="margin-top:10px"><button class="btn sm pri" id="ice-addsrc">${ico("plus")} Add a source</button></p>`}</div>`;
547
+ ? cardsOn
548
+ ? html`<div class="ice-cards">${order.map(cardOf)}</div><div class="ice-cpg">${pagerHtml(icePg)}</div>`
549
+ : html`<div class="tk-list ice-list${narrow ? " ice-plist" : ""}">${order.map(narrow ? prow : row)}${pagerHtml(icePg)}</div>`
550
+ : html`<div class="ice-zero"><h4>Nothing waiting</h4><p>Drop anything above: what a client asked for, something you found, what people say.</p>${list.length ? "" : html`<p style="margin-top:10px"><button class="btn sm pri" id="ice-addsrc">${ico("plus")} Add a source</button></p>`}</div>`;
389
551
  // Swipe: the waiting requests the filters show, least skipped first; a restored one
390
552
  // comes back on top. Nothing is written by a skip.
391
553
  const deck = iceSwipe
@@ -435,7 +597,7 @@ export async function openSources() {
435
597
  // a rebuild while open shows it in place.
436
598
  const drawer = !!srcShow,
437
599
  slide = drawer && !$("src-sec")?.classList.contains("open");
438
- const sec = html`<div class="src-scrim${drawer && !slide ? " on" : ""}" id="src-scrim"></div><aside class="src-sec${drawer && !slide ? " open" : ""}" id="src-sec" aria-label="Sources"${drawer ? "" : " inert"}><header><div class="t"><b>Sources</b><div class="src-chips"><a id="src-to-settings" class="schip" role="button" tabindex="0" title="${d && d.every && d.every !== "off" ? `Checked every ${d.every}` : "Auto-check off"}: change in Settings">${ico("clock")}${d && d.every && d.every !== "off" ? (d.every) : "Off"}</a>${G.connected ? html`<span class="schip on" title="ChatGPT${G.email ? ": " + (G.email) : ""}">${ico("ai")}ChatGPT<a id="cg-out" role="button" tabindex="0" aria-label="Disconnect ChatGPT" title="Disconnect">${ico("x")}</a></span>` : html`<a id="cg-in" class="schip" role="button" tabindex="0" title="Connect ChatGPT">${ico("ai")}ChatGPT</a>`}${(d.google || {}).connected ? html`<span class="schip on" title="Google connected">${ico("google")}Google<a id="gg-out" role="button" tabindex="0" aria-label="Disconnect Google" title="Disconnect">${ico("x")}</a></span>` : html`<a id="gg-in" class="schip" role="button" tabindex="0" title="Connect Google">${ico("google")}Google</a>`}</div></div><div class="src-hda">${list.length ? html`<button class="btn sm" id="src-new" aria-expanded="${String(addOn)}" aria-controls="src-addbox">${ico("plus")} Add</button>` : ""}<button class="ib" id="src-x" aria-label="Close sources" title="Close">${ico("close")}</button></div></header><div class="body">${addBox}${list.length ? html`<div class="src-list">${cards}</div>` : emptyState}</div></aside>`;
600
+ const sec = html`<div class="src-scrim${drawer && !slide ? " on" : ""}" id="src-scrim"></div><aside class="src-sec${drawer && !slide ? " open" : ""}" id="src-sec" aria-label="Sources"${drawer ? "" : " inert"}><header><div class="t"><b>Sources</b><div class="src-chips"><a id="src-to-settings" class="schip" role="button" tabindex="0" title="${d && d.every && d.every !== "off" ? `Checked every ${d.every}` : "Auto-check off"}: change in Settings">${ico("clock")}${d && d.every && d.every !== "off" ? (d.every) : "Off"}</a>${G.connected ? html`<span class="schip on" title="ChatGPT${G.email ? ": " + (G.email) : ""}">${ico("ai")}ChatGPT<a id="cg-out" role="button" tabindex="0" aria-label="Disconnect ChatGPT" title="Disconnect">${ico("x")}</a></span>` : html`<a id="cg-in" class="schip" role="button" tabindex="0" title="Connect ChatGPT">${ico("ai")}ChatGPT</a>`}${(d.google || {}).connected ? html`<span class="schip on" title="Google connected">${ico("google")}Google<a id="gg-out" role="button" tabindex="0" aria-label="Disconnect Google" title="Disconnect">${ico("x")}</a></span>` : html`<a id="gg-in" class="schip" role="button" tabindex="0" title="Connect Google">${ico("google")}Google</a>`}</div></div><div class="src-hda">${list.length ? html`<button class="btn sm" id="src-go">${ico("refresh")} Gather all</button><button class="btn sm" id="src-new" aria-expanded="${String(addOn)}" aria-controls="src-addbox">${ico("plus")} Add</button>` : ""}<button class="ib" id="src-x" aria-label="Close sources" title="Close">${ico("close")}</button></div></header><div class="body">${addBox}${list.length ? html`<div class="src-list">${cards}</div>` : emptyState}</div></aside>`;
439
601
  // First visit: offer the ChatGPT plan for social sources, or keep the agent.
440
602
  const onb =
441
603
  G.use === "ask" && !G.connected
@@ -443,6 +605,7 @@ export async function openSources() {
443
605
  : "";
444
606
  // A rebuild replaces the drawer: keep where it was scrolled to.
445
607
  const at = $("src-sec")?.querySelector(".body")?.scrollTop ?? 0;
608
+ const capFocus = cap.ta && document.activeElement === cap.ta ? [cap.ta.selectionStart, cap.ta.selectionEnd] : null;
446
609
  $("pbody").innerHTML =
447
610
  d && d.error
448
611
  ? html`<p style="color:var(--dim)">${d.error}</p>`
@@ -450,10 +613,163 @@ export async function openSources() {
450
613
  ? html`<p style="color:var(--dim)">The icebox could not be read.</p>`
451
614
  : iceSwipe
452
615
  ? html`${swipe()}${sec}`
453
- : html`${onb}${bar}${bulk}${fails}${inbox}${sec}`;
616
+ : html`${capBox}${narrow ? "" : onb}${boardsBar}${bar}${bulk}${fails}${inbox}${sec}`;
454
617
  if (!d || d.error) return;
455
618
  const body = $("src-sec")?.querySelector(".body");
456
619
  if (body) body.scrollTop = at;
620
+ if ($("ice-cap")) {
621
+ if (!cap.ta) {
622
+ const ta = document.createElement("textarea");
623
+ ta.id = "ice-cap-t";
624
+ ta.className = "ice-cap-t";
625
+ ta.rows = 2;
626
+ ta.placeholder = "Drop anything: a note, a link, a picture — or dictate";
627
+ ta.setAttribute("aria-label", "Drop anything into the icebox");
628
+ cap.ta = ta;
629
+ cap.mic = mic([ta]);
630
+ }
631
+ // A phone has room for one short line.
632
+ cap.ta.placeholder = narrowQ.matches ? "Drop a note, link or picture…" : "Drop anything: a note, a link, a picture — or dictate";
633
+ $("ice-cap-slot").replaceWith(cap.ta);
634
+ if (cap.mic) $("ice-mic-slot").replaceWith(cap.mic);
635
+ else $("ice-mic-slot").remove();
636
+ if (capFocus) {
637
+ cap.ta.focus();
638
+ cap.ta.setSelectionRange(capFocus[0], capFocus[1]);
639
+ }
640
+ const addFile = (f) => {
641
+ cap.files.push(f);
642
+ openSources().then(() => cap.ta.focus());
643
+ };
644
+ $("ice-pick").onclick = () => $("ice-file").click();
645
+ $("ice-file").onchange = (e) => {
646
+ const fs = [...e.target.files];
647
+ e.target.value = "";
648
+ cap.files.push(...fs);
649
+ openSources().then(() => cap.ta.focus());
650
+ };
651
+ $("pbody")
652
+ .querySelectorAll("[data-rf]")
653
+ .forEach((b) => (b.onclick = () => {
654
+ cap.files.splice(+b.dataset.rf, 1);
655
+ openSources().then(() => cap.ta.focus());
656
+ }));
657
+ // A pasted picture is a file; pasted text stays text.
658
+ cap.ta.onpaste = (e) => {
659
+ for (const it of e.clipboardData.items)
660
+ if (it.kind === "file") {
661
+ const x = it.getAsFile();
662
+ e.preventDefault();
663
+ addFile(new File([x], x.name === "image.png" ? `paste-${Date.now()}.png` : x.name, { type: x.type }));
664
+ }
665
+ };
666
+ // Saved with the text it had: the field is read-only until the server answers.
667
+ const save = async () => {
668
+ const text = cap.ta.value.trim(),
669
+ to = dir || cap.dir;
670
+ if (cap.busy) return;
671
+ if (!text) {
672
+ if (cap.files.length) toast("Write a line about it first");
673
+ return cap.ta.focus();
674
+ }
675
+ if (!to) return toast("Pick a project first");
676
+ cap.busy = cap.ta.readOnly = true;
677
+ $("ice-save").disabled = true;
678
+ $("ice-save").textContent = "Saving…";
679
+ let j = { ok: false };
680
+ try {
681
+ j = await post("/icebox", { op: "add", dir: to, text, board: cap.board || undefined, files: await dataUrls(cap.files) });
682
+ } finally {
683
+ cap.busy = cap.ta.readOnly = false;
684
+ }
685
+ if (j.ok) {
686
+ cap.ta.value = "";
687
+ cap.files = [];
688
+ iceCur = null;
689
+ toast(`Added to the icebox${cap.board ? " · " + cap.board : ""}`);
690
+ load();
691
+ }
692
+ if (srcOpen()) await openSources();
693
+ cap.ta.focus();
694
+ };
695
+ cap.ta.onkeydown = (e) => {
696
+ if (e.key === "Enter" && !e.shiftKey && !e.isComposing) {
697
+ e.preventDefault();
698
+ save();
699
+ }
700
+ };
701
+ $("ice-save").onclick = save;
702
+ wirePick("ice-cp", (v) => {
703
+ cap.dir = v;
704
+ openSources().then(() => cap.ta.focus());
705
+ });
706
+ wirePick("ice-cb", async (v) => {
707
+ if (v === "\n") {
708
+ const a = await askCollection();
709
+ if (!a) return cap.ta.focus();
710
+ if (a.client) await post("/icebox", { op: "boards", act: "add", dir: dir || cap.dir, name: a.name, client: true });
711
+ v = a.name;
712
+ }
713
+ cap.board = v;
714
+ cap.boardDir = dir || cap.dir;
715
+ openSources().then(() => cap.ta.focus());
716
+ });
717
+ }
718
+ if (iceMenu !== iceMenuFor) {
719
+ iceMenuFor = iceMenu;
720
+ iceMenuAt = iceMenu ? Date.now() : 0;
721
+ }
722
+ $("pbody").onscroll = () => {
723
+ if (!iceMenu || Date.now() - iceMenuAt < 400) return;
724
+ iceMenu = "";
725
+ $("pbody").querySelector(".ice-mpop")?.remove();
726
+ $("pbody").querySelector('[data-m][aria-expanded="true"]')?.setAttribute("aria-expanded", "false");
727
+ };
728
+ // The boards bar and the kind filters; the view switch.
729
+ $("pbody")
730
+ .querySelectorAll("[data-bd]")
731
+ .forEach((b) => (b.onclick = () => {
732
+ iceBoard = b.dataset.bd;
733
+ // The box follows the chip: its board, and in All projects that board's project.
734
+ const fb = iceBoard && boards.find((x) => sameName(x.name, iceBoard));
735
+ if (fb) {
736
+ cap.board = fb.name;
737
+ cap.boardDir = fb.dir;
738
+ if (!dir) cap.dir = fb.dir;
739
+ }
740
+ openSources();
741
+ }));
742
+ $("pbody")
743
+ .querySelectorAll("[data-kf]")
744
+ .forEach((b) => (b.onclick = () => {
745
+ iceKinds.has(b.dataset.kf) ? iceKinds.delete(b.dataset.kf) : iceKinds.add(b.dataset.kf);
746
+ openSources();
747
+ }));
748
+ $("pbody")
749
+ .querySelectorAll("[data-view]")
750
+ .forEach((b) => (b.onclick = () => {
751
+ iceView = b.dataset.view;
752
+ try {
753
+ localStorage.setItem("kz-ice-view", iceView);
754
+ } catch (e) {}
755
+ openSources();
756
+ }));
757
+ // + Collection: a name, and whether it is a client's (its items then count as Client).
758
+ if ($("ice-nb"))
759
+ $("ice-nb").onclick = async () => {
760
+ const to = dir || cap.dir;
761
+ if (!to) return toast("Pick a project first");
762
+ const a = await askCollection(dir ? "" : capP?.label || "this project");
763
+ if (!a) return;
764
+ const { name, client } = a;
765
+ const j = await post("/icebox", { op: "boards", act: "add", dir: to, name, client });
766
+ if (j.ok) {
767
+ toast(`Collection ${name} made`);
768
+ load();
769
+ }
770
+ if (srcOpen()) openSources();
771
+ };
772
+ if (sdKeep && sdKeep[0] === iceMenu && $("ice-sd")) $("ice-sd").value = sdKeep[1];
457
773
  if (iceDraft && iceDraft[0] === iceForm && $("ice-title")) {
458
774
  $("ice-title").value = iceDraft[1];
459
775
  $("ice-details").value = iceDraft[2];
@@ -568,7 +884,8 @@ export async function openSources() {
568
884
  });
569
885
  if ($("ice-unf"))
570
886
  $("ice-unf").onclick = () => {
571
- iceCat = iceSrc = "";
887
+ iceCat = iceSrc = iceBoard = "";
888
+ iceKinds.clear();
572
889
  if (!dir) store.shown.clear();
573
890
  setShown();
574
891
  openSources();
@@ -661,7 +978,7 @@ export async function openSources() {
661
978
  // The acting button is disabled as it is pressed, which drops focus to the page; it goes back to the cursor row.
662
979
  const focusCur = () => {
663
980
  if (!document.activeElement || document.activeElement === document.body)
664
- $("pbody").querySelector(".ice-row.cur .ice-t")?.focus();
981
+ $("pbody").querySelector(".ice-row.cur .ice-t,.ice-card.cur .ice-ct")?.focus();
665
982
  };
666
983
  // Before rows go, the cursor steps to the next row that stays, else the one before.
667
984
  const stepPast = (gone) => {
@@ -682,6 +999,109 @@ export async function openSources() {
682
999
  }
683
1000
  if (srcOpen()) openSources().then(focusCur);
684
1001
  })();
1002
+ // Snooze: the items leave the page until their day, with Undo on the toast.
1003
+ const snoozeAll = async (its, until) => {
1004
+ if (!its.length) return;
1005
+ stepPast(new Set(its.map(iceKey)));
1006
+ iceMenu = "";
1007
+ iceBusy = true;
1008
+ const done = [];
1009
+ try {
1010
+ for (const dd of new Set(its.map((it) => it.dir))) {
1011
+ const xs = its.filter((it) => it.dir === dd);
1012
+ if ((await post("/icebox", { op: "snooze", dir: dd, ids: xs.map((it) => it.id), until })).ok) done.push(...xs);
1013
+ }
1014
+ } finally {
1015
+ iceBusy = false;
1016
+ }
1017
+ if (done.length) {
1018
+ done.forEach((it) => iceSel.delete(iceKey(it)));
1019
+ toast(`${done.length > 1 ? done.length + " snoozed" : "Snoozed"} until ${wakeDay(until).toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric" })}`);
1020
+ const t = $("toast"),
1021
+ u = document.createElement("button");
1022
+ u.type = "button";
1023
+ u.className = "ice-undo";
1024
+ u.textContent = "Undo";
1025
+ u.onclick = async () => {
1026
+ t.classList.remove("on");
1027
+ let back = 0;
1028
+ for (const dd of new Set(done.map((it) => it.dir)))
1029
+ if ((await post("/icebox", { op: "unsnooze", dir: dd, ids: done.filter((it) => it.dir === dd).map((it) => it.id) })).ok) back++;
1030
+ if (back) {
1031
+ iceCur = iceKey(done[0]);
1032
+ toast("Back in the icebox");
1033
+ }
1034
+ load();
1035
+ if (srcOpen()) openSources();
1036
+ };
1037
+ t.classList.add("rep");
1038
+ t.append(" · ", u);
1039
+ }
1040
+ load();
1041
+ if (srcOpen()) openSources().then(focusCur);
1042
+ };
1043
+ // Kind and board: the item stays, changed.
1044
+ const setOne = async (it, body, msg) => {
1045
+ iceMenu = "";
1046
+ const j = await post("/icebox", { dir: it.dir, ids: [it.id], ...body });
1047
+ if (j.ok) {
1048
+ toast(msg);
1049
+ load();
1050
+ }
1051
+ if (srcOpen()) openSources().then(() => $("pbody").querySelector(`[data-k="${CSS.escape(iceKey(it))}"] [data-m]`)?.focus());
1052
+ };
1053
+ $("pbody")
1054
+ .querySelectorAll("[data-m]")
1055
+ .forEach((b) => (b.onclick = (e) => {
1056
+ e.stopPropagation();
1057
+ const it = ice[+b.dataset.mi],
1058
+ m = iceKey(it) + " " + b.dataset.m;
1059
+ iceCur = iceKey(it);
1060
+ iceMenu = iceMenu === m ? "" : m;
1061
+ openSources().then(() => iceMenu && $("pbody").querySelector(".ice-mpop button")?.focus());
1062
+ }));
1063
+ // The open menu sits fixed under its button: inside the cards' columns an absolute one is split
1064
+ // between columns. Scrolling the page shuts it.
1065
+ $("pbody")
1066
+ .querySelectorAll(".ice-mpop")
1067
+ .forEach((pp) => {
1068
+ const it = ice[+pp.dataset.mi],
1069
+ btn = pp.parentElement.querySelector(`[data-m="${iceMenu.slice(iceKey(it).length + 1)}"]`) || pp.parentElement.querySelector(".ice-pf");
1070
+ if (btn) {
1071
+ const r = btn.getBoundingClientRect(),
1072
+ h = pp.offsetHeight,
1073
+ w = pp.offsetWidth;
1074
+ pp.style.left = Math.max(8, Math.min(r.left, innerWidth - w - 8)) + "px";
1075
+ pp.style.top = (r.bottom + 4 + h > innerHeight - 8 ? Math.max(8, r.top - 4 - h) : r.bottom + 4) + "px";
1076
+ }
1077
+ pp.onclick = (e) => e.stopPropagation();
1078
+ pp.onkeydown = (e) => {
1079
+ const bs = [...pp.querySelectorAll("button,input")],
1080
+ n = bs.indexOf(document.activeElement);
1081
+ if (e.key === "Escape") {
1082
+ e.stopPropagation();
1083
+ iceMenu = "";
1084
+ openSources().then(focusCur);
1085
+ } else if ((e.key === "ArrowDown" || e.key === "ArrowUp") && document.activeElement?.type !== "date") {
1086
+ e.preventDefault();
1087
+ bs[(n + (e.key === "ArrowDown" ? 1 : bs.length - 1)) % bs.length]?.focus();
1088
+ }
1089
+ };
1090
+ pp.querySelectorAll("[data-sz]").forEach((b) => (b.onclick = () => {
1091
+ const v = b.dataset.sz || $("ice-sd").value;
1092
+ if (!v) return $("ice-sd").focus();
1093
+ snoozeAll([it], v);
1094
+ }));
1095
+ pp.querySelectorAll("[data-kd]").forEach((b) => (b.onclick = () => setOne(it, { op: "kind", kind: b.dataset.kd }, `Kind: ${KIND[b.dataset.kd]}`)));
1096
+ pp.querySelectorAll("[data-bo]").forEach((b) => (b.onclick = () => setOne(it, { op: "board", board: b.dataset.bo }, b.dataset.bo ? `Moved to ${b.dataset.bo}` : "Moved to the Inbox")));
1097
+ pp.querySelectorAll("[data-bo-new]").forEach((b) => (b.onclick = async () => {
1098
+ iceMenu = "";
1099
+ const a = await askCollection();
1100
+ if (!a) return;
1101
+ if (a.client) await post("/icebox", { op: "boards", act: "add", dir: it.dir, name: a.name, client: true });
1102
+ setOne(it, { op: "board", board: a.name }, `Moved to ${a.name}`);
1103
+ }));
1104
+ });
685
1105
  // Bulk: one dismiss per project; promote one request at a time, each its own task
686
1106
  // titled as gathered (one promote call with several ids would merge them into one).
687
1107
  const bulkDo = async (op) => {
@@ -689,7 +1109,7 @@ export async function openSources() {
689
1109
  if (!its.length) return;
690
1110
  stepPast(new Set(its.map(iceKey)));
691
1111
  iceBusy = true;
692
- $("ice-bp").disabled = $("ice-bd").disabled = true;
1112
+ $("ice-bp").disabled = $("ice-bd").disabled = $("ice-bz").disabled = true;
693
1113
  let ok = 0;
694
1114
  try {
695
1115
  if (op === "dismiss")
@@ -710,6 +1130,7 @@ export async function openSources() {
710
1130
  if (srcOpen()) openSources().then(focusCur);
711
1131
  };
712
1132
  if (bulk) {
1133
+ $("ice-bz").onclick = () => snoozeAll(ice.filter((it) => iceSel.has(iceKey(it)) && live(it)), "1w");
713
1134
  $("ice-bp").onclick = () => bulkDo("promote");
714
1135
  $("ice-bd").onclick = () => bulkDo("dismiss");
715
1136
  $("ice-bc").onclick = () => {
@@ -738,10 +1159,12 @@ export async function openSources() {
738
1159
  }),
739
1160
  );
740
1161
  // A row opens on its title or anywhere not a control; open shows what was gathered and the promote form.
1162
+ // A card opens in the Sort list (for this visit; the saved view stays), where notes, reply and promote are.
741
1163
  const toggle = (i) => {
742
1164
  const k = iceKey(ice[i]);
743
1165
  iceCur = k;
744
- iceForm = iceForm === k ? null : k;
1166
+ iceForm = iceForm === k && !cardsOn ? null : k;
1167
+ iceView = "sort";
745
1168
  icePro = null;
746
1169
  openSources().then(() => $("ice-o-" + i)?.focus());
747
1170
  };
@@ -750,7 +1173,7 @@ export async function openSources() {
750
1173
  .forEach(
751
1174
  (r) =>
752
1175
  (r.onclick = (e) => {
753
- if (!e.target.closest("input,button")) toggle(+r.dataset.i);
1176
+ if (!e.target.closest("input,button,.ice-mpop")) toggle(+r.dataset.i);
754
1177
  }),
755
1178
  );
756
1179
  $("pbody")
@@ -765,8 +1188,11 @@ export async function openSources() {
765
1188
  .forEach(
766
1189
  (b) =>
767
1190
  (b.onclick = () => {
768
- const k = iceKey(ice[+b.dataset.pr]);
1191
+ const it = ice[+b.dataset.pr],
1192
+ k = iceKey(it);
769
1193
  iceCur = iceForm = icePro = k;
1194
+ iceView = "sort";
1195
+ if (G.connected && !(iceTask && iceTask.k === k)) taskDraft(it);
770
1196
  openSources().then(() => {
771
1197
  $("ice-title")?.focus();
772
1198
  $("ice-title")?.select();
@@ -858,6 +1284,32 @@ export async function openSources() {
858
1284
  };
859
1285
  }
860
1286
 
1287
+ // Ask for a draft; when it comes, fill the form only where the person has not typed.
1288
+ async function taskDraft(it) {
1289
+ const k = iceKey(it),
1290
+ before = { title: $("ice-title")?.dataset.k === k ? $("ice-title").value : it.text, details: $("ice-title")?.dataset.k === k ? $("ice-details").value : "" };
1291
+ iceTask = { k, wait: true, title: iceTask?.k === k ? iceTask.title : "", details: iceTask?.k === k ? iceTask.details : "" };
1292
+ const r = await fetch("/icebox", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ op: "task-draft", dir: it.dir, ids: [it.id] }) })
1293
+ .then((x) => x.json())
1294
+ .catch(() => ({ error: "kaizen did not answer" }));
1295
+ if (!iceTask || iceTask.k !== k) return;
1296
+ if (r.ok && r.title) {
1297
+ const ti = $("ice-title"), de = $("ice-details");
1298
+ const untouched = !ti || ti.dataset.k !== k || (ti.value === before.title && de.value === before.details);
1299
+ iceTask = { k, wait: false, title: r.title, details: r.details || "" };
1300
+ if (ti && ti.dataset.k === k && untouched) {
1301
+ ti.value = r.title;
1302
+ de.value = r.details || "";
1303
+ } else if (ti && ti.dataset.k === k) iceTask = { k, wait: false, title: ti.value, details: de.value, kept: true };
1304
+ } else iceTask = { k, wait: false, title: "", details: "", note: r.error || r.note || "ChatGPT did not answer" };
1305
+ if (srcOpen() && iceForm === k) openSources();
1306
+ }
1307
+ if ($("ice-td") && open1)
1308
+ $("ice-td").onclick = () => {
1309
+ iceTask = null;
1310
+ taskDraft(open1);
1311
+ openSources();
1312
+ };
861
1313
  if ($("ice-ok")) {
862
1314
  const ok = () => {
863
1315
  const title = $("ice-title").value.trim();
@@ -941,6 +1393,127 @@ export async function openSources() {
941
1393
  iceSwipe = null;
942
1394
  openSources().then(focusCur);
943
1395
  };
1396
+ // Phone rows: drag right to make a task, left to dismiss (Undo on the toast), hold to snooze.
1397
+ // The page keeps scrolling: a drag counts only once it is mostly sideways (touch-action: pan-y
1398
+ // hands every vertical move to the browser, which cancels the pointer).
1399
+ const undoDismiss = (it) => {
1400
+ const t = $("toast"),
1401
+ u = document.createElement("button");
1402
+ u.type = "button";
1403
+ u.className = "ice-undo";
1404
+ u.textContent = "Undo";
1405
+ u.onclick = async () => {
1406
+ t.classList.remove("on");
1407
+ if ((await post("/icebox", { op: "restore", dir: it.dir, ids: [it.id] })).ok) {
1408
+ iceCur = iceKey(it);
1409
+ toast("Back in the icebox");
1410
+ }
1411
+ load();
1412
+ if (srcOpen()) openSources();
1413
+ };
1414
+ t.classList.add("rep");
1415
+ t.append(" · ", u);
1416
+ };
1417
+ const rowGo = async (r, it, op) => {
1418
+ r.classList.add("gone");
1419
+ r.style.setProperty("--to", (op === "promote" ? 1 : -1) * r.offsetWidth + "px");
1420
+ if (motion()) await new Promise((ok) => setTimeout(ok, 180));
1421
+ if (soundPick() !== "off") playSound("pop");
1422
+ stepPast(new Set([iceKey(it)]));
1423
+ const j = await post("/icebox", { op, dir: it.dir, ids: [it.id] });
1424
+ if (j.ok) {
1425
+ toast(op === "promote" ? "Made a task" : "Dismissed");
1426
+ if (op === "dismiss") undoDismiss(it);
1427
+ }
1428
+ load();
1429
+ if (srcOpen()) openSources();
1430
+ };
1431
+ $("pbody")
1432
+ .querySelectorAll(".ice-prow[data-swipe]")
1433
+ .forEach((r) => {
1434
+ const f = r.querySelector(".ice-pf"),
1435
+ it = ice[+r.dataset.i];
1436
+ f.onpointerdown = (e) => {
1437
+ if (e.button || r.classList.contains("gone") || e.target.closest(".ice-ptask,.ice-kb,a,input,summary,.ice-mpop")) return;
1438
+ const x0 = e.clientX,
1439
+ y0 = e.clientY;
1440
+ let dx = 0,
1441
+ mode = "";
1442
+ // A tap after a drag or a hold must not also open the row.
1443
+ // A hold redraws the page under the finger, so the click that follows its release lands on
1444
+ // the new menu: it is eaten on the whole document until just after that release.
1445
+ const eat = () => {
1446
+ const k = (c) => {
1447
+ c.stopPropagation();
1448
+ c.preventDefault();
1449
+ };
1450
+ document.addEventListener("click", k, { capture: true, once: true });
1451
+ let gone = false;
1452
+ const off = () => {
1453
+ if (gone) return;
1454
+ gone = true;
1455
+ document.removeEventListener("pointerup", off, { capture: true });
1456
+ document.removeEventListener("pointercancel", off, { capture: true });
1457
+ setTimeout(() => document.removeEventListener("click", k, { capture: true }), 60);
1458
+ };
1459
+ if (mode === "hold") {
1460
+ // Released, cancelled by the browser, or left far too long: the blocker goes either way.
1461
+ document.addEventListener("pointerup", off, { capture: true });
1462
+ document.addEventListener("pointercancel", off, { capture: true });
1463
+ setTimeout(off, 5000);
1464
+ } else off();
1465
+ };
1466
+ const hold = setTimeout(() => {
1467
+ if (mode) return;
1468
+ mode = "hold";
1469
+ eat();
1470
+ iceCur = iceKey(it);
1471
+ iceMenu = iceKey(it) + " snooze";
1472
+ navigator.vibrate?.(10);
1473
+ openSources().then(() => $("pbody").querySelector(".ice-mpop button")?.focus());
1474
+ }, 500);
1475
+ const reset = () => {
1476
+ f.style.transform = "";
1477
+ r.style.removeProperty("--p");
1478
+ delete r.dataset.dir;
1479
+ };
1480
+ const end = (cancel) => {
1481
+ clearTimeout(hold);
1482
+ f.onpointermove = f.onpointerup = f.onpointercancel = null;
1483
+ if (mode !== "drag") return;
1484
+ r.classList.remove("drag");
1485
+ swHeld = false;
1486
+ const late = swLate;
1487
+ swLate = false;
1488
+ eat();
1489
+ if (!cancel && Math.abs(dx) > r.offsetWidth * 0.35) rowGo(r, it, dx > 0 ? "promote" : "dismiss");
1490
+ else {
1491
+ reset();
1492
+ if (late) openSources();
1493
+ }
1494
+ };
1495
+ f.onpointermove = (m) => {
1496
+ const mx = m.clientX - x0,
1497
+ my = m.clientY - y0;
1498
+ if (!mode) {
1499
+ if (Math.hypot(mx, my) > 8) clearTimeout(hold);
1500
+ if (Math.abs(mx) > 10 && Math.abs(mx) > Math.abs(my)) {
1501
+ mode = "drag";
1502
+ f.setPointerCapture(m.pointerId);
1503
+ r.classList.add("drag");
1504
+ swHeld = true;
1505
+ } else if (Math.abs(my) > 10) mode = "scroll";
1506
+ }
1507
+ if (mode !== "drag") return;
1508
+ dx = mx;
1509
+ f.style.transform = `translateX(${dx}px)`;
1510
+ r.dataset.dir = dx > 0 ? "pro" : "dis";
1511
+ r.style.setProperty("--p", String(Math.min(1, Math.abs(dx) / (r.offsetWidth * 0.35))));
1512
+ };
1513
+ f.onpointerup = () => end(false);
1514
+ f.onpointercancel = () => end(true);
1515
+ };
1516
+ });
944
1517
  if ($("ice-sw"))
945
1518
  $("ice-sw").onclick = () => {
946
1519
  iceSwipe = { n: 0, pro: 0, dis: 0, t0: Date.now(), last: null, skip: new Map(), busy: false, pop: false };
@@ -1025,6 +1598,11 @@ export async function openSources() {
1025
1598
  srcShut();
1026
1599
  return true;
1027
1600
  }
1601
+ if (iceMenu) {
1602
+ iceMenu = "";
1603
+ openSources().then(focusCur);
1604
+ return true;
1605
+ }
1028
1606
  if (iceForm) {
1029
1607
  if (icePro) icePro = null;
1030
1608
  else iceForm = null;
@@ -1044,9 +1622,17 @@ export async function openSources() {
1044
1622
  const n = order[Math.max(0, Math.min(order.length - 1, at + (k === "j" ? 1 : -1)))];
1045
1623
  iceCur = iceKey(ice[n]);
1046
1624
  $("pbody")
1047
- .querySelectorAll(".ice-row")
1625
+ .querySelectorAll(".ice-row,.ice-card")
1048
1626
  .forEach((r) => r.classList.toggle("cur", +r.dataset.i === n));
1049
- $("pbody").querySelector(`.ice-row[data-i="${n}"]`)?.scrollIntoView({ block: "nearest" });
1627
+ $("pbody").querySelector(`:is(.ice-row,.ice-card)[data-i="${n}"]`)?.scrollIntoView({ block: "nearest" });
1628
+ return true;
1629
+ }
1630
+ // h: snooze for a week, the selection when there is one.
1631
+ if (k === "h") {
1632
+ const its = iceSel.size ? ice.filter((it) => iceSel.has(iceKey(it)) && live(it)) : live(ice[i]) ? [ice[i]] : [];
1633
+ if (!its.length) return false;
1634
+ e.preventDefault();
1635
+ snoozeAll(its, "1w");
1050
1636
  return true;
1051
1637
  }
1052
1638
  const b =
@@ -1182,59 +1768,6 @@ export async function openSources() {
1182
1768
  if (e.key === "Enter") $("src-add").click();
1183
1769
  };
1184
1770
  }
1185
- if ($("ice-new"))
1186
- $("ice-new").onclick = () => {
1187
- const all = !dir;
1188
- if (!dir && !showable().length) return toast("Pick a project first");
1189
- // The new-task form, cut down: the request, files, dictation and, in All projects, the project.
1190
- const dl = modal(
1191
- `${all ? `<div class="combo" id="ndc"><button type="button" class="sel" id="newdir" aria-label="Project for this request" aria-haspopup="listbox" aria-expanded="false"></button><div class="menu-pop" hidden><input class="sel" aria-label="Search projects" placeholder="Search projects…" spellcheck="false" autocomplete="off"><div id="nds" role="listbox"></div></div></div>` : ""}<textarea id="newidea" placeholder="What did someone ask for?" aria-label="Request"></textarea><div class="att"></div><input type="file" multiple hidden><div class="row"><button type="button" class="ib" id="newpick" aria-label="Attach files" title="Attach files">${ico("clip")}</button><button type="button" class="btn ghost" value="">Cancel</button><button class="btn pri">Add</button></div>`,
1192
- );
1193
- const f = dl.querySelector("form"),
1194
- inp = f.querySelector("textarea"),
1195
- files = [];
1196
- const add = (x) => {
1197
- files.push(x);
1198
- f.querySelector(".att").textContent = files.map((y) => y.name).join(" · ");
1199
- };
1200
- f.querySelector("#newpick").onclick = () => f.querySelector("input[type=file]").click();
1201
- f.querySelector("input[type=file]").onchange = (e) => {
1202
- [...e.target.files].forEach(add);
1203
- e.target.value = "";
1204
- };
1205
- inp.onpaste = (e) => {
1206
- for (const it of e.clipboardData.items)
1207
- if (it.kind === "file") {
1208
- const x = it.getAsFile();
1209
- add(new File([x], x.name === "image.png" ? `paste-${Date.now()}.png` : x.name, { type: x.type }));
1210
- e.preventDefault();
1211
- }
1212
- };
1213
- f.querySelector(".btn.ghost").onclick = () => dl.close();
1214
- if (all) taskCombo(f);
1215
- const m = mic([inp]);
1216
- if (m) f.querySelector(".row").prepend(m);
1217
- dl.addEventListener("close", () => stopDictation(false));
1218
- inp.onkeydown = (e) => {
1219
- if (e.key === "Enter" && !e.shiftKey) {
1220
- e.preventDefault();
1221
- f.requestSubmit();
1222
- }
1223
- };
1224
- f.onsubmit = async (e) => {
1225
- e.preventDefault();
1226
- const text = inp.value.trim(),
1227
- to = dir || newDir;
1228
- if (!text) return inp.focus();
1229
- if (!to) return toast("Pick a project first");
1230
- const j = await post("/icebox", { op: "add", dir: to, text, files: await dataUrls(files) });
1231
- if (j.ok) {
1232
- toast("Added to the icebox");
1233
- dl.close();
1234
- }
1235
- };
1236
- inp.focus();
1237
- };
1238
1771
  if ($("src-go"))
1239
1772
  $("src-go").onclick = () => {
1240
1773
  $("src-go").disabled = true;