kaizen-agent 1.77.1 → 1.78.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/cli/chatgpt.ts +62 -2
- package/cli/settings.ts +2 -2
- package/cli/sources.ts +16 -0
- package/cli/web.ts +30 -2
- package/package.json +1 -1
- package/skills/kaizen/discover.md +15 -6
- package/skills/kaizen-explore/SKILL.md +8 -0
- package/web/board/icebox.ts +598 -89
- package/web/board/search.ts +1 -1
- package/web/board/views.ts +3 -3
- package/web/board.html +99 -5
- package/web/board.js +154 -152
- package/web/notebook.js +130 -128
- package/web/notes.html +1 -1
- package/web/term.js +1 -1
- package/web/video.html +1 -1
- package/web/video.js +184 -182
package/web/board/icebox.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { termStop } from "./agent-term.ts";
|
|
|
3
3
|
import { load, post } from "./api.ts";
|
|
4
4
|
import { via } from "./cards.ts";
|
|
5
5
|
import { mic, stopDictation } from "./dictation.ts";
|
|
6
|
-
import { $, dataUrls, html, ico,
|
|
7
|
-
import {
|
|
6
|
+
import { $, dataUrls, html, ico, motion, pageOf, pager, pagerHtml, raw, SKEL, wirePager } from "./dom.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,52 @@ 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 person mark for a client's board.
|
|
92
|
+
const PERSON = raw(
|
|
93
|
+
'<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>',
|
|
94
|
+
);
|
|
95
|
+
const sameName = (a, b) => String(a || "").toLowerCase() === String(b || "").toLowerCase();
|
|
96
|
+
// The day a snooze lands on, said as the server works it out (1d, 1w, 1m or a date).
|
|
97
|
+
const wakeDay = (until) => {
|
|
98
|
+
const d = new Date();
|
|
99
|
+
if (until === "1d") d.setDate(d.getDate() + 1);
|
|
100
|
+
else if (until === "1w") d.setDate(d.getDate() + 7);
|
|
101
|
+
else if (until === "1m") d.setMonth(d.getMonth() + 1);
|
|
102
|
+
else return new Date(until + "T00:00:00");
|
|
103
|
+
return d;
|
|
104
|
+
};
|
|
105
|
+
const ymd = (d) => d.toLocaleDateString("sv");
|
|
57
106
|
export const srcOpen = () => $("panel").classList.contains("open") && $("ptitle").textContent === SRC;
|
|
58
107
|
const ago = (at) => {
|
|
59
108
|
const m = Math.round((Date.now() - Date.parse(at)) / 60000);
|
|
@@ -125,8 +174,10 @@ export async function openSources() {
|
|
|
125
174
|
return;
|
|
126
175
|
}
|
|
127
176
|
if (view !== "sources") return;
|
|
177
|
+
wireOnce();
|
|
128
178
|
const gen = ++store.pageGen;
|
|
129
|
-
|
|
179
|
+
// A dictation into the capture box keeps going: its field is carried over, not rebuilt.
|
|
180
|
+
stopDictation(!$("ice-cap"));
|
|
130
181
|
// What is half typed survives a refresh from the server.
|
|
131
182
|
const typed = srcOpen()
|
|
132
183
|
? [
|
|
@@ -145,8 +196,10 @@ export async function openSources() {
|
|
|
145
196
|
);
|
|
146
197
|
// And a promote form half filled, for the item it was typed on.
|
|
147
198
|
// 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"),
|
|
199
|
+
const fRow = srcOpen() && document.activeElement?.closest?.(".ice-row,.ice-card"),
|
|
149
200
|
fPick = fRow ? [fRow.dataset.k, document.activeElement.id.replace(/-\d+$/, "")] : null;
|
|
201
|
+
// And a Snooze date half picked in an open menu.
|
|
202
|
+
const sdKeep = srcOpen() && $("ice-sd")?.value ? [iceMenu, $("ice-sd").value] : null;
|
|
150
203
|
const iceDraft =
|
|
151
204
|
srcOpen() && $("ice-title") ? [$("ice-title").dataset.k, $("ice-title").value, $("ice-details").value] : null;
|
|
152
205
|
// And a category typed on a row but not yet saved.
|
|
@@ -279,27 +332,31 @@ export async function openSources() {
|
|
|
279
332
|
}
|
|
280
333
|
const inProj = (it) => dir || !store.shown.size || store.shown.has(it.dir),
|
|
281
334
|
pv = ice.filter(inProj);
|
|
282
|
-
const
|
|
335
|
+
const isWaiting = (it) => !["promoted", "dismissed", "done"].includes(it.status);
|
|
336
|
+
// Boards, then kinds, narrow before category and source. A board is its name: two projects'
|
|
337
|
+
// boards of one name are one chip in All projects.
|
|
338
|
+
const boards = [...new Map(((d && d.boards) || []).filter(inProj).map((b) => [b.name.toLowerCase(), b])).values()];
|
|
339
|
+
if (iceBoard && !boards.some((b) => sameName(b.name, iceBoard))) iceBoard = "";
|
|
340
|
+
const onBoard = (it) => !iceBoard || sameName(it.board, iceBoard),
|
|
341
|
+
ofKind = (it) => !iceKinds.size || iceKinds.has(it.kind);
|
|
342
|
+
const byCat = count(pv.filter((it) => onBoard(it) && ofKind(it)), catOf);
|
|
283
343
|
if (iceCat && !byCat.has(iceCat)) iceCat = "";
|
|
284
|
-
const cv = pv.filter((it) => !iceCat || catOf(it) === iceCat);
|
|
344
|
+
const cv = pv.filter((it) => onBoard(it) && ofKind(it) && (!iceCat || catOf(it) === iceCat));
|
|
285
345
|
const bySrc = count(cv, srcKey);
|
|
286
346
|
if (iceSrc && !bySrc.has(iceSrc)) iceSrc = "";
|
|
287
347
|
const keys = new Set(ice.map(iceKey));
|
|
288
348
|
if (iceForm && !keys.has(iceForm)) iceForm = null;
|
|
289
349
|
if (icePro !== iceForm) icePro = null;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const filtered = [...groups.values()].flat();
|
|
350
|
+
// Newest first, in the order they are drawn, which is the order j and k walk. Category is a filter.
|
|
351
|
+
const filtered = ice
|
|
352
|
+
.map((_, i) => i)
|
|
353
|
+
.filter((i) => {
|
|
354
|
+
const it = ice[i];
|
|
355
|
+
return inProj(it) && onBoard(it) && ofKind(it) && (iceCat ? catOf(it) === iceCat : it.status !== "dismissed" && it.status !== "done") && (!iceSrc || srcKey(it) === iceSrc);
|
|
356
|
+
})
|
|
357
|
+
.sort((a, b) => (Date.parse(ice[b].at) || 0) - (Date.parse(ice[a].at) || 0));
|
|
299
358
|
// Only the page: j and k, select-all and bulk actions stay on what shows.
|
|
300
359
|
const order = pageOf(icePg, filtered);
|
|
301
|
-
const onPage = new Set(order);
|
|
302
|
-
const isWaiting = (it) => !["promoted", "dismissed", "done"].includes(it.status);
|
|
303
360
|
// A checked request a filter hides is unchecked: a bulk action only ever acts on what shows.
|
|
304
361
|
{
|
|
305
362
|
const vis = new Set(order.map((i) => iceKey(ice[i])));
|
|
@@ -345,14 +402,35 @@ export async function openSources() {
|
|
|
345
402
|
)}`,
|
|
346
403
|
)
|
|
347
404
|
: ""}`;
|
|
348
|
-
|
|
405
|
+
// Under 640 px there are no cards: the list shows, and the switch goes.
|
|
406
|
+
const narrow = narrowQ.matches,
|
|
407
|
+
cardsOn = iceView === "cards" && !narrow;
|
|
408
|
+
// The boards bar: All, each board with what waits on it, + Board; the kind filters on the right.
|
|
409
|
+
const nOn = (b) => pv.filter((it) => isWaiting(it) && sameName(it.board, b.name)).length;
|
|
410
|
+
const boardsBar = html`<div class="ice-boards"><div class="ice-chips" role="group" aria-label="Boards"><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 board: 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 board for a client or a topic">${ico("plus")}Board</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>`;
|
|
411
|
+
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" ? `${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>`;
|
|
412
|
+
// The capture box: what is typed, pasted, attached or dictated lands in the icebox on the picked
|
|
413
|
+
// board. In All projects it names the project, as the Add pop-up did. Field and mic are slotted in.
|
|
414
|
+
const capPs = dir ? [] : showable();
|
|
415
|
+
if (!dir && !capPs.some((p) => p.dir === cap.dir))
|
|
416
|
+
cap.dir = (store.shown.size === 1 ? [...store.shown][0] : null) || capPs[0]?.dir || null;
|
|
417
|
+
const capTo0 = dir || cap.dir;
|
|
418
|
+
// A board picked for another project never goes along when the box's project changes.
|
|
419
|
+
if (cap.board && cap.boardDir && cap.boardDir !== capTo0) cap.board = "";
|
|
420
|
+
const capTo = capTo0,
|
|
421
|
+
capP = capPs.find((p) => p.dir === cap.dir);
|
|
422
|
+
const capBoards = ((d && d.boards) || []).filter((b) => b.dir === capTo);
|
|
423
|
+
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", "Board", html`<span>Board: ${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 board…</span>`, "new board")}`)}<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
424
|
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>`
|
|
425
|
+
? 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
426
|
: "";
|
|
352
427
|
// The open item's form: a clean title for the task's card and the person's own details;
|
|
353
428
|
// what was gathered is added to the task's notes by the server.
|
|
354
|
-
const form = (it) =>
|
|
355
|
-
|
|
429
|
+
const form = (it) => {
|
|
430
|
+
const t = iceTask && iceTask.k === iceKey(it) ? iceTask : null,
|
|
431
|
+
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." : "";
|
|
432
|
+
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>`;
|
|
433
|
+
};
|
|
356
434
|
// A gathered post can be answered: Reply drafts, the box is the approval, Send reply posts that text.
|
|
357
435
|
const replyBox = (it) => {
|
|
358
436
|
if (!it.post) return "";
|
|
@@ -368,24 +446,87 @@ export async function openSources() {
|
|
|
368
446
|
if (r.wait) return html`<div class="ice-form-acts"><span class="hint">Drafting…</span></div>`;
|
|
369
447
|
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
448
|
};
|
|
371
|
-
const imgs = (it) =>
|
|
372
|
-
(it.images || []).filter((u) => /^https:\/\//.test(u)).length ? html`<details class="ice-imgs"><summary
|
|
449
|
+
const imgs = (it, card = false) =>
|
|
450
|
+
(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>` : "";
|
|
451
|
+
// The pieces rows and cards share. Only a waiting item has menus; Snooze needs one too.
|
|
452
|
+
const live = (it) => it.status === "new";
|
|
453
|
+
const kindOf = (it) => html`<span class="ice-k k-${it.kind || "none"}">${KIND[it.kind] || "Unsorted"}</span>`;
|
|
454
|
+
const menuBtn = (i, it, m, inner, cls, label) =>
|
|
455
|
+
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>`;
|
|
456
|
+
// The open item menu, drawn inside its row or card: Snooze, Kind or Board.
|
|
457
|
+
const menu = (i, it) => {
|
|
458
|
+
const k = iceKey(it),
|
|
459
|
+
m = iceMenu.startsWith(k + " ") ? iceMenu.slice(k.length + 1) : "";
|
|
460
|
+
if (!m) return "";
|
|
461
|
+
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>`;
|
|
462
|
+
const day = (n) => ymd(new Date(Date.now() + n * 864e5));
|
|
463
|
+
const inner =
|
|
464
|
+
m === "snooze"
|
|
465
|
+
? 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>`
|
|
466
|
+
: m === "kind"
|
|
467
|
+
? html`${Object.entries(KIND).map(([v, l]) => b("data-kd", v, l, it.kind === v && it.sorted !== "rules"))}`
|
|
468
|
+
: 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 board…</button>`;
|
|
469
|
+
return html`<div class="menu-pop ice-mpop" role="menu" data-mi="${i}" aria-label="${m === "snooze" ? "Snooze until" : m === "kind" ? "Kind" : "Board"}">${inner}</div>`;
|
|
470
|
+
};
|
|
471
|
+
const badges = (it) =>
|
|
472
|
+
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>` : ""}`;
|
|
473
|
+
const proj = (it) => (many ? html`<span class="nm" title="${it.project || ""}">${plogo(it.dir, it.project || "")}${short(it.project || "")}</span>` : "");
|
|
373
474
|
const row = (i) => {
|
|
374
475
|
const it = ice[i],
|
|
375
476
|
k = iceKey(it),
|
|
376
477
|
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}"
|
|
478
|
+
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"), "Board") : 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
479
|
const more = open
|
|
379
480
|
? 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
481
|
: "";
|
|
381
482
|
return html`${head}${more}`;
|
|
382
483
|
};
|
|
484
|
+
const hue = (t) => [...t].reduce((a, c) => (a * 31 + c.charCodeAt(0)) % 360, 7);
|
|
485
|
+
// A phone row (under 640 px): kind, two lines, board and age, a thumbnail for a link (its
|
|
486
|
+
// site's hue and letter) or pictures (an icon and the count: nothing is fetched from their
|
|
487
|
+
// site), → Task. A swipe decides it: right a task, left dismissed; a long press snoozes.
|
|
488
|
+
const thumb = (it) => {
|
|
489
|
+
const lk = it.link && /^https?:\/\//i.test(it.link.url) ? it.link : null,
|
|
490
|
+
n = (it.images || []).filter((u) => /^https:\/\//.test(u)).length;
|
|
491
|
+
if (lk) {
|
|
492
|
+
const site = host(lk.url).replace(/^www\./, "");
|
|
493
|
+
return html`<span class="ice-th" style="--h:${hue(site)}" title="${lk.title || site}" aria-hidden="true">${(site[0] || "").toUpperCase()}</span>`;
|
|
494
|
+
}
|
|
495
|
+
return n ? html`<span class="ice-th pic" title="${n} pictures" aria-hidden="true">${ico("img")}<i>${n}</i></span>` : "";
|
|
496
|
+
};
|
|
497
|
+
const prow = (i) => {
|
|
498
|
+
const it = ice[i],
|
|
499
|
+
k = iceKey(it),
|
|
500
|
+
open = iceForm === k,
|
|
501
|
+
done = it.status === "promoted" || it.status === "done";
|
|
502
|
+
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>`;
|
|
503
|
+
// Opened, a phone row also offers what its gestures do, for anyone who cannot swipe or hold.
|
|
504
|
+
const acts = live(it)
|
|
505
|
+
? 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`Board: ${it.board || "Inbox"}`, "btn ghost sm", "Board")}<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>`
|
|
506
|
+
: "";
|
|
507
|
+
const more = open
|
|
508
|
+
? 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>`
|
|
509
|
+
: "";
|
|
510
|
+
return html`${head}${more}`;
|
|
511
|
+
};
|
|
512
|
+
// A card: what it is, the words, where it sits, how old. A link leads with its title and summary,
|
|
513
|
+
// coloured from the site's name; nothing is fetched from the site to draw it.
|
|
514
|
+
const cardOf = (i) => {
|
|
515
|
+
const it = ice[i],
|
|
516
|
+
k = iceKey(it),
|
|
517
|
+
lk = it.link && /^https?:\/\//i.test(it.link.url) ? it.link : null,
|
|
518
|
+
site = lk ? host(lk.url).replace(/^www\./, "") : "";
|
|
519
|
+
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", "Board", "btn ghost sm", "Board")}` : ""}<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>`}`;
|
|
520
|
+
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>`;
|
|
521
|
+
};
|
|
383
522
|
const inbox =
|
|
384
523
|
waiting && !order.length
|
|
385
524
|
? 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
525
|
: order.length
|
|
387
|
-
?
|
|
388
|
-
|
|
526
|
+
? cardsOn
|
|
527
|
+
? html`<div class="ice-cards">${order.map(cardOf)}</div><div class="ice-cpg">${pagerHtml(icePg)}</div>`
|
|
528
|
+
: html`<div class="tk-list ice-list${narrow ? " ice-plist" : ""}">${order.map(narrow ? prow : row)}${pagerHtml(icePg)}</div>`
|
|
529
|
+
: 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
530
|
// Swipe: the waiting requests the filters show, least skipped first; a restored one
|
|
390
531
|
// comes back on top. Nothing is written by a skip.
|
|
391
532
|
const deck = iceSwipe
|
|
@@ -435,7 +576,7 @@ export async function openSources() {
|
|
|
435
576
|
// a rebuild while open shows it in place.
|
|
436
577
|
const drawer = !!srcShow,
|
|
437
578
|
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>`;
|
|
579
|
+
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
580
|
// First visit: offer the ChatGPT plan for social sources, or keep the agent.
|
|
440
581
|
const onb =
|
|
441
582
|
G.use === "ask" && !G.connected
|
|
@@ -443,6 +584,7 @@ export async function openSources() {
|
|
|
443
584
|
: "";
|
|
444
585
|
// A rebuild replaces the drawer: keep where it was scrolled to.
|
|
445
586
|
const at = $("src-sec")?.querySelector(".body")?.scrollTop ?? 0;
|
|
587
|
+
const capFocus = cap.ta && document.activeElement === cap.ta ? [cap.ta.selectionStart, cap.ta.selectionEnd] : null;
|
|
446
588
|
$("pbody").innerHTML =
|
|
447
589
|
d && d.error
|
|
448
590
|
? html`<p style="color:var(--dim)">${d.error}</p>`
|
|
@@ -450,10 +592,163 @@ export async function openSources() {
|
|
|
450
592
|
? html`<p style="color:var(--dim)">The icebox could not be read.</p>`
|
|
451
593
|
: iceSwipe
|
|
452
594
|
? html`${swipe()}${sec}`
|
|
453
|
-
: html`${onb}${bar}${bulk}${fails}${inbox}${sec}`;
|
|
595
|
+
: html`${capBox}${narrow ? "" : onb}${boardsBar}${bar}${bulk}${fails}${inbox}${sec}`;
|
|
454
596
|
if (!d || d.error) return;
|
|
455
597
|
const body = $("src-sec")?.querySelector(".body");
|
|
456
598
|
if (body) body.scrollTop = at;
|
|
599
|
+
if ($("ice-cap")) {
|
|
600
|
+
if (!cap.ta) {
|
|
601
|
+
const ta = document.createElement("textarea");
|
|
602
|
+
ta.id = "ice-cap-t";
|
|
603
|
+
ta.className = "ice-cap-t";
|
|
604
|
+
ta.rows = 2;
|
|
605
|
+
ta.placeholder = "Drop anything: a note, a link, a picture — or dictate";
|
|
606
|
+
ta.setAttribute("aria-label", "Drop anything into the icebox");
|
|
607
|
+
cap.ta = ta;
|
|
608
|
+
cap.mic = mic([ta]);
|
|
609
|
+
}
|
|
610
|
+
// A phone has room for one short line.
|
|
611
|
+
cap.ta.placeholder = narrowQ.matches ? "Drop a note, link or picture…" : "Drop anything: a note, a link, a picture — or dictate";
|
|
612
|
+
$("ice-cap-slot").replaceWith(cap.ta);
|
|
613
|
+
if (cap.mic) $("ice-mic-slot").replaceWith(cap.mic);
|
|
614
|
+
else $("ice-mic-slot").remove();
|
|
615
|
+
if (capFocus) {
|
|
616
|
+
cap.ta.focus();
|
|
617
|
+
cap.ta.setSelectionRange(capFocus[0], capFocus[1]);
|
|
618
|
+
}
|
|
619
|
+
const addFile = (f) => {
|
|
620
|
+
cap.files.push(f);
|
|
621
|
+
openSources().then(() => cap.ta.focus());
|
|
622
|
+
};
|
|
623
|
+
$("ice-pick").onclick = () => $("ice-file").click();
|
|
624
|
+
$("ice-file").onchange = (e) => {
|
|
625
|
+
const fs = [...e.target.files];
|
|
626
|
+
e.target.value = "";
|
|
627
|
+
cap.files.push(...fs);
|
|
628
|
+
openSources().then(() => cap.ta.focus());
|
|
629
|
+
};
|
|
630
|
+
$("pbody")
|
|
631
|
+
.querySelectorAll("[data-rf]")
|
|
632
|
+
.forEach((b) => (b.onclick = () => {
|
|
633
|
+
cap.files.splice(+b.dataset.rf, 1);
|
|
634
|
+
openSources().then(() => cap.ta.focus());
|
|
635
|
+
}));
|
|
636
|
+
// A pasted picture is a file; pasted text stays text.
|
|
637
|
+
cap.ta.onpaste = (e) => {
|
|
638
|
+
for (const it of e.clipboardData.items)
|
|
639
|
+
if (it.kind === "file") {
|
|
640
|
+
const x = it.getAsFile();
|
|
641
|
+
e.preventDefault();
|
|
642
|
+
addFile(new File([x], x.name === "image.png" ? `paste-${Date.now()}.png` : x.name, { type: x.type }));
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
// Saved with the text it had: the field is read-only until the server answers.
|
|
646
|
+
const save = async () => {
|
|
647
|
+
const text = cap.ta.value.trim(),
|
|
648
|
+
to = dir || cap.dir;
|
|
649
|
+
if (cap.busy) return;
|
|
650
|
+
if (!text) {
|
|
651
|
+
if (cap.files.length) toast("Write a line about it first");
|
|
652
|
+
return cap.ta.focus();
|
|
653
|
+
}
|
|
654
|
+
if (!to) return toast("Pick a project first");
|
|
655
|
+
cap.busy = cap.ta.readOnly = true;
|
|
656
|
+
$("ice-save").disabled = true;
|
|
657
|
+
$("ice-save").textContent = "Saving…";
|
|
658
|
+
let j = { ok: false };
|
|
659
|
+
try {
|
|
660
|
+
j = await post("/icebox", { op: "add", dir: to, text, board: cap.board || undefined, files: await dataUrls(cap.files) });
|
|
661
|
+
} finally {
|
|
662
|
+
cap.busy = cap.ta.readOnly = false;
|
|
663
|
+
}
|
|
664
|
+
if (j.ok) {
|
|
665
|
+
cap.ta.value = "";
|
|
666
|
+
cap.files = [];
|
|
667
|
+
iceCur = null;
|
|
668
|
+
toast(`Added to the icebox${cap.board ? " · " + cap.board : ""}`);
|
|
669
|
+
load();
|
|
670
|
+
}
|
|
671
|
+
if (srcOpen()) await openSources();
|
|
672
|
+
cap.ta.focus();
|
|
673
|
+
};
|
|
674
|
+
cap.ta.onkeydown = (e) => {
|
|
675
|
+
if (e.key === "Enter" && !e.shiftKey && !e.isComposing) {
|
|
676
|
+
e.preventDefault();
|
|
677
|
+
save();
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
$("ice-save").onclick = save;
|
|
681
|
+
wirePick("ice-cp", (v) => {
|
|
682
|
+
cap.dir = v;
|
|
683
|
+
openSources().then(() => cap.ta.focus());
|
|
684
|
+
});
|
|
685
|
+
wirePick("ice-cb", (v) => {
|
|
686
|
+
if (v === "\n") {
|
|
687
|
+
const n = (prompt("New board: a client or a topic") || "").trim();
|
|
688
|
+
if (!n) return cap.ta.focus();
|
|
689
|
+
if (n.length > 40) return toast("A board name is 1 to 40 characters");
|
|
690
|
+
v = n;
|
|
691
|
+
}
|
|
692
|
+
cap.board = v;
|
|
693
|
+
cap.boardDir = dir || cap.dir;
|
|
694
|
+
openSources().then(() => cap.ta.focus());
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
if (iceMenu !== iceMenuFor) {
|
|
698
|
+
iceMenuFor = iceMenu;
|
|
699
|
+
iceMenuAt = iceMenu ? Date.now() : 0;
|
|
700
|
+
}
|
|
701
|
+
$("pbody").onscroll = () => {
|
|
702
|
+
if (!iceMenu || Date.now() - iceMenuAt < 400) return;
|
|
703
|
+
iceMenu = "";
|
|
704
|
+
$("pbody").querySelector(".ice-mpop")?.remove();
|
|
705
|
+
$("pbody").querySelector('[data-m][aria-expanded="true"]')?.setAttribute("aria-expanded", "false");
|
|
706
|
+
};
|
|
707
|
+
// The boards bar and the kind filters; the view switch.
|
|
708
|
+
$("pbody")
|
|
709
|
+
.querySelectorAll("[data-bd]")
|
|
710
|
+
.forEach((b) => (b.onclick = () => {
|
|
711
|
+
iceBoard = b.dataset.bd;
|
|
712
|
+
// The box follows the chip: its board, and in All projects that board's project.
|
|
713
|
+
const fb = iceBoard && boards.find((x) => sameName(x.name, iceBoard));
|
|
714
|
+
if (fb) {
|
|
715
|
+
cap.board = fb.name;
|
|
716
|
+
cap.boardDir = fb.dir;
|
|
717
|
+
if (!dir) cap.dir = fb.dir;
|
|
718
|
+
}
|
|
719
|
+
openSources();
|
|
720
|
+
}));
|
|
721
|
+
$("pbody")
|
|
722
|
+
.querySelectorAll("[data-kf]")
|
|
723
|
+
.forEach((b) => (b.onclick = () => {
|
|
724
|
+
iceKinds.has(b.dataset.kf) ? iceKinds.delete(b.dataset.kf) : iceKinds.add(b.dataset.kf);
|
|
725
|
+
openSources();
|
|
726
|
+
}));
|
|
727
|
+
$("pbody")
|
|
728
|
+
.querySelectorAll("[data-view]")
|
|
729
|
+
.forEach((b) => (b.onclick = () => {
|
|
730
|
+
iceView = b.dataset.view;
|
|
731
|
+
try {
|
|
732
|
+
localStorage.setItem("kz-ice-view", iceView);
|
|
733
|
+
} catch (e) {}
|
|
734
|
+
openSources();
|
|
735
|
+
}));
|
|
736
|
+
// + Board: a name, and whether it is a client's (its items then count as Client).
|
|
737
|
+
if ($("ice-nb"))
|
|
738
|
+
$("ice-nb").onclick = async () => {
|
|
739
|
+
const to = dir || cap.dir;
|
|
740
|
+
if (!to) return toast("Pick a project first");
|
|
741
|
+
const name = (prompt(dir ? "New board: a client or a topic" : `New board in ${capP?.label || "this project"}: a client or a topic`) || "").trim();
|
|
742
|
+
if (!name) return;
|
|
743
|
+
const client = confirm(`Is ${name} a client? Its items then count as Client.`);
|
|
744
|
+
const j = await post("/icebox", { op: "boards", act: "add", dir: to, name, client });
|
|
745
|
+
if (j.ok) {
|
|
746
|
+
toast(`Board ${name} made`);
|
|
747
|
+
load();
|
|
748
|
+
}
|
|
749
|
+
if (srcOpen()) openSources();
|
|
750
|
+
};
|
|
751
|
+
if (sdKeep && sdKeep[0] === iceMenu && $("ice-sd")) $("ice-sd").value = sdKeep[1];
|
|
457
752
|
if (iceDraft && iceDraft[0] === iceForm && $("ice-title")) {
|
|
458
753
|
$("ice-title").value = iceDraft[1];
|
|
459
754
|
$("ice-details").value = iceDraft[2];
|
|
@@ -568,7 +863,8 @@ export async function openSources() {
|
|
|
568
863
|
});
|
|
569
864
|
if ($("ice-unf"))
|
|
570
865
|
$("ice-unf").onclick = () => {
|
|
571
|
-
iceCat = iceSrc = "";
|
|
866
|
+
iceCat = iceSrc = iceBoard = "";
|
|
867
|
+
iceKinds.clear();
|
|
572
868
|
if (!dir) store.shown.clear();
|
|
573
869
|
setShown();
|
|
574
870
|
openSources();
|
|
@@ -661,7 +957,7 @@ export async function openSources() {
|
|
|
661
957
|
// The acting button is disabled as it is pressed, which drops focus to the page; it goes back to the cursor row.
|
|
662
958
|
const focusCur = () => {
|
|
663
959
|
if (!document.activeElement || document.activeElement === document.body)
|
|
664
|
-
$("pbody").querySelector(".ice-row.cur .ice-t")?.focus();
|
|
960
|
+
$("pbody").querySelector(".ice-row.cur .ice-t,.ice-card.cur .ice-ct")?.focus();
|
|
665
961
|
};
|
|
666
962
|
// Before rows go, the cursor steps to the next row that stays, else the one before.
|
|
667
963
|
const stepPast = (gone) => {
|
|
@@ -682,6 +978,106 @@ export async function openSources() {
|
|
|
682
978
|
}
|
|
683
979
|
if (srcOpen()) openSources().then(focusCur);
|
|
684
980
|
})();
|
|
981
|
+
// Snooze: the items leave the page until their day, with Undo on the toast.
|
|
982
|
+
const snoozeAll = async (its, until) => {
|
|
983
|
+
if (!its.length) return;
|
|
984
|
+
stepPast(new Set(its.map(iceKey)));
|
|
985
|
+
iceMenu = "";
|
|
986
|
+
iceBusy = true;
|
|
987
|
+
const done = [];
|
|
988
|
+
try {
|
|
989
|
+
for (const dd of new Set(its.map((it) => it.dir))) {
|
|
990
|
+
const xs = its.filter((it) => it.dir === dd);
|
|
991
|
+
if ((await post("/icebox", { op: "snooze", dir: dd, ids: xs.map((it) => it.id), until })).ok) done.push(...xs);
|
|
992
|
+
}
|
|
993
|
+
} finally {
|
|
994
|
+
iceBusy = false;
|
|
995
|
+
}
|
|
996
|
+
if (done.length) {
|
|
997
|
+
done.forEach((it) => iceSel.delete(iceKey(it)));
|
|
998
|
+
toast(`${done.length > 1 ? done.length + " snoozed" : "Snoozed"} until ${wakeDay(until).toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric" })}`);
|
|
999
|
+
const t = $("toast"),
|
|
1000
|
+
u = document.createElement("button");
|
|
1001
|
+
u.type = "button";
|
|
1002
|
+
u.className = "ice-undo";
|
|
1003
|
+
u.textContent = "Undo";
|
|
1004
|
+
u.onclick = async () => {
|
|
1005
|
+
t.classList.remove("on");
|
|
1006
|
+
let back = 0;
|
|
1007
|
+
for (const dd of new Set(done.map((it) => it.dir)))
|
|
1008
|
+
if ((await post("/icebox", { op: "unsnooze", dir: dd, ids: done.filter((it) => it.dir === dd).map((it) => it.id) })).ok) back++;
|
|
1009
|
+
if (back) {
|
|
1010
|
+
iceCur = iceKey(done[0]);
|
|
1011
|
+
toast("Back in the icebox");
|
|
1012
|
+
}
|
|
1013
|
+
load();
|
|
1014
|
+
if (srcOpen()) openSources();
|
|
1015
|
+
};
|
|
1016
|
+
t.classList.add("rep");
|
|
1017
|
+
t.append(" · ", u);
|
|
1018
|
+
}
|
|
1019
|
+
load();
|
|
1020
|
+
if (srcOpen()) openSources().then(focusCur);
|
|
1021
|
+
};
|
|
1022
|
+
// Kind and board: the item stays, changed.
|
|
1023
|
+
const setOne = async (it, body, msg) => {
|
|
1024
|
+
iceMenu = "";
|
|
1025
|
+
const j = await post("/icebox", { dir: it.dir, ids: [it.id], ...body });
|
|
1026
|
+
if (j.ok) {
|
|
1027
|
+
toast(msg);
|
|
1028
|
+
load();
|
|
1029
|
+
}
|
|
1030
|
+
if (srcOpen()) openSources().then(() => $("pbody").querySelector(`[data-k="${CSS.escape(iceKey(it))}"] [data-m]`)?.focus());
|
|
1031
|
+
};
|
|
1032
|
+
$("pbody")
|
|
1033
|
+
.querySelectorAll("[data-m]")
|
|
1034
|
+
.forEach((b) => (b.onclick = (e) => {
|
|
1035
|
+
e.stopPropagation();
|
|
1036
|
+
const it = ice[+b.dataset.mi],
|
|
1037
|
+
m = iceKey(it) + " " + b.dataset.m;
|
|
1038
|
+
iceCur = iceKey(it);
|
|
1039
|
+
iceMenu = iceMenu === m ? "" : m;
|
|
1040
|
+
openSources().then(() => iceMenu && $("pbody").querySelector(".ice-mpop button")?.focus());
|
|
1041
|
+
}));
|
|
1042
|
+
// The open menu sits fixed under its button: inside the cards' columns an absolute one is split
|
|
1043
|
+
// between columns. Scrolling the page shuts it.
|
|
1044
|
+
$("pbody")
|
|
1045
|
+
.querySelectorAll(".ice-mpop")
|
|
1046
|
+
.forEach((pp) => {
|
|
1047
|
+
const it = ice[+pp.dataset.mi],
|
|
1048
|
+
btn = pp.parentElement.querySelector(`[data-m="${iceMenu.slice(iceKey(it).length + 1)}"]`) || pp.parentElement.querySelector(".ice-pf");
|
|
1049
|
+
if (btn) {
|
|
1050
|
+
const r = btn.getBoundingClientRect(),
|
|
1051
|
+
h = pp.offsetHeight,
|
|
1052
|
+
w = pp.offsetWidth;
|
|
1053
|
+
pp.style.left = Math.max(8, Math.min(r.left, innerWidth - w - 8)) + "px";
|
|
1054
|
+
pp.style.top = (r.bottom + 4 + h > innerHeight - 8 ? Math.max(8, r.top - 4 - h) : r.bottom + 4) + "px";
|
|
1055
|
+
}
|
|
1056
|
+
pp.onclick = (e) => e.stopPropagation();
|
|
1057
|
+
pp.onkeydown = (e) => {
|
|
1058
|
+
const bs = [...pp.querySelectorAll("button,input")],
|
|
1059
|
+
n = bs.indexOf(document.activeElement);
|
|
1060
|
+
if (e.key === "Escape") {
|
|
1061
|
+
e.stopPropagation();
|
|
1062
|
+
iceMenu = "";
|
|
1063
|
+
openSources().then(focusCur);
|
|
1064
|
+
} else if ((e.key === "ArrowDown" || e.key === "ArrowUp") && document.activeElement?.type !== "date") {
|
|
1065
|
+
e.preventDefault();
|
|
1066
|
+
bs[(n + (e.key === "ArrowDown" ? 1 : bs.length - 1)) % bs.length]?.focus();
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
pp.querySelectorAll("[data-sz]").forEach((b) => (b.onclick = () => {
|
|
1070
|
+
const v = b.dataset.sz || $("ice-sd").value;
|
|
1071
|
+
if (!v) return $("ice-sd").focus();
|
|
1072
|
+
snoozeAll([it], v);
|
|
1073
|
+
}));
|
|
1074
|
+
pp.querySelectorAll("[data-kd]").forEach((b) => (b.onclick = () => setOne(it, { op: "kind", kind: b.dataset.kd }, `Kind: ${KIND[b.dataset.kd]}`)));
|
|
1075
|
+
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")));
|
|
1076
|
+
pp.querySelectorAll("[data-bo-new]").forEach((b) => (b.onclick = () => {
|
|
1077
|
+
const n = (prompt("New board: a client or a topic") || "").trim();
|
|
1078
|
+
if (n) setOne(it, { op: "board", board: n }, `Moved to ${n}`);
|
|
1079
|
+
}));
|
|
1080
|
+
});
|
|
685
1081
|
// Bulk: one dismiss per project; promote one request at a time, each its own task
|
|
686
1082
|
// titled as gathered (one promote call with several ids would merge them into one).
|
|
687
1083
|
const bulkDo = async (op) => {
|
|
@@ -689,7 +1085,7 @@ export async function openSources() {
|
|
|
689
1085
|
if (!its.length) return;
|
|
690
1086
|
stepPast(new Set(its.map(iceKey)));
|
|
691
1087
|
iceBusy = true;
|
|
692
|
-
$("ice-bp").disabled = $("ice-bd").disabled = true;
|
|
1088
|
+
$("ice-bp").disabled = $("ice-bd").disabled = $("ice-bz").disabled = true;
|
|
693
1089
|
let ok = 0;
|
|
694
1090
|
try {
|
|
695
1091
|
if (op === "dismiss")
|
|
@@ -710,6 +1106,7 @@ export async function openSources() {
|
|
|
710
1106
|
if (srcOpen()) openSources().then(focusCur);
|
|
711
1107
|
};
|
|
712
1108
|
if (bulk) {
|
|
1109
|
+
$("ice-bz").onclick = () => snoozeAll(ice.filter((it) => iceSel.has(iceKey(it)) && live(it)), "1w");
|
|
713
1110
|
$("ice-bp").onclick = () => bulkDo("promote");
|
|
714
1111
|
$("ice-bd").onclick = () => bulkDo("dismiss");
|
|
715
1112
|
$("ice-bc").onclick = () => {
|
|
@@ -738,10 +1135,12 @@ export async function openSources() {
|
|
|
738
1135
|
}),
|
|
739
1136
|
);
|
|
740
1137
|
// A row opens on its title or anywhere not a control; open shows what was gathered and the promote form.
|
|
1138
|
+
// A card opens in the Sort list (for this visit; the saved view stays), where notes, reply and promote are.
|
|
741
1139
|
const toggle = (i) => {
|
|
742
1140
|
const k = iceKey(ice[i]);
|
|
743
1141
|
iceCur = k;
|
|
744
|
-
iceForm = iceForm === k ? null : k;
|
|
1142
|
+
iceForm = iceForm === k && !cardsOn ? null : k;
|
|
1143
|
+
iceView = "sort";
|
|
745
1144
|
icePro = null;
|
|
746
1145
|
openSources().then(() => $("ice-o-" + i)?.focus());
|
|
747
1146
|
};
|
|
@@ -750,7 +1149,7 @@ export async function openSources() {
|
|
|
750
1149
|
.forEach(
|
|
751
1150
|
(r) =>
|
|
752
1151
|
(r.onclick = (e) => {
|
|
753
|
-
if (!e.target.closest("input,button")) toggle(+r.dataset.i);
|
|
1152
|
+
if (!e.target.closest("input,button,.ice-mpop")) toggle(+r.dataset.i);
|
|
754
1153
|
}),
|
|
755
1154
|
);
|
|
756
1155
|
$("pbody")
|
|
@@ -765,8 +1164,11 @@ export async function openSources() {
|
|
|
765
1164
|
.forEach(
|
|
766
1165
|
(b) =>
|
|
767
1166
|
(b.onclick = () => {
|
|
768
|
-
const
|
|
1167
|
+
const it = ice[+b.dataset.pr],
|
|
1168
|
+
k = iceKey(it);
|
|
769
1169
|
iceCur = iceForm = icePro = k;
|
|
1170
|
+
iceView = "sort";
|
|
1171
|
+
if (G.connected && !(iceTask && iceTask.k === k)) taskDraft(it);
|
|
770
1172
|
openSources().then(() => {
|
|
771
1173
|
$("ice-title")?.focus();
|
|
772
1174
|
$("ice-title")?.select();
|
|
@@ -858,6 +1260,32 @@ export async function openSources() {
|
|
|
858
1260
|
};
|
|
859
1261
|
}
|
|
860
1262
|
|
|
1263
|
+
// Ask for a draft; when it comes, fill the form only where the person has not typed.
|
|
1264
|
+
async function taskDraft(it) {
|
|
1265
|
+
const k = iceKey(it),
|
|
1266
|
+
before = { title: $("ice-title")?.dataset.k === k ? $("ice-title").value : it.text, details: $("ice-title")?.dataset.k === k ? $("ice-details").value : "" };
|
|
1267
|
+
iceTask = { k, wait: true, title: iceTask?.k === k ? iceTask.title : "", details: iceTask?.k === k ? iceTask.details : "" };
|
|
1268
|
+
const r = await fetch("/icebox", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ op: "task-draft", dir: it.dir, ids: [it.id] }) })
|
|
1269
|
+
.then((x) => x.json())
|
|
1270
|
+
.catch(() => ({ error: "kaizen did not answer" }));
|
|
1271
|
+
if (!iceTask || iceTask.k !== k) return;
|
|
1272
|
+
if (r.ok && r.title) {
|
|
1273
|
+
const ti = $("ice-title"), de = $("ice-details");
|
|
1274
|
+
const untouched = !ti || ti.dataset.k !== k || (ti.value === before.title && de.value === before.details);
|
|
1275
|
+
iceTask = { k, wait: false, title: r.title, details: r.details || "" };
|
|
1276
|
+
if (ti && ti.dataset.k === k && untouched) {
|
|
1277
|
+
ti.value = r.title;
|
|
1278
|
+
de.value = r.details || "";
|
|
1279
|
+
} else if (ti && ti.dataset.k === k) iceTask = { k, wait: false, title: ti.value, details: de.value, kept: true };
|
|
1280
|
+
} else iceTask = { k, wait: false, title: "", details: "", note: r.error || r.note || "ChatGPT did not answer" };
|
|
1281
|
+
if (srcOpen() && iceForm === k) openSources();
|
|
1282
|
+
}
|
|
1283
|
+
if ($("ice-td") && open1)
|
|
1284
|
+
$("ice-td").onclick = () => {
|
|
1285
|
+
iceTask = null;
|
|
1286
|
+
taskDraft(open1);
|
|
1287
|
+
openSources();
|
|
1288
|
+
};
|
|
861
1289
|
if ($("ice-ok")) {
|
|
862
1290
|
const ok = () => {
|
|
863
1291
|
const title = $("ice-title").value.trim();
|
|
@@ -941,6 +1369,127 @@ export async function openSources() {
|
|
|
941
1369
|
iceSwipe = null;
|
|
942
1370
|
openSources().then(focusCur);
|
|
943
1371
|
};
|
|
1372
|
+
// Phone rows: drag right to make a task, left to dismiss (Undo on the toast), hold to snooze.
|
|
1373
|
+
// The page keeps scrolling: a drag counts only once it is mostly sideways (touch-action: pan-y
|
|
1374
|
+
// hands every vertical move to the browser, which cancels the pointer).
|
|
1375
|
+
const undoDismiss = (it) => {
|
|
1376
|
+
const t = $("toast"),
|
|
1377
|
+
u = document.createElement("button");
|
|
1378
|
+
u.type = "button";
|
|
1379
|
+
u.className = "ice-undo";
|
|
1380
|
+
u.textContent = "Undo";
|
|
1381
|
+
u.onclick = async () => {
|
|
1382
|
+
t.classList.remove("on");
|
|
1383
|
+
if ((await post("/icebox", { op: "restore", dir: it.dir, ids: [it.id] })).ok) {
|
|
1384
|
+
iceCur = iceKey(it);
|
|
1385
|
+
toast("Back in the icebox");
|
|
1386
|
+
}
|
|
1387
|
+
load();
|
|
1388
|
+
if (srcOpen()) openSources();
|
|
1389
|
+
};
|
|
1390
|
+
t.classList.add("rep");
|
|
1391
|
+
t.append(" · ", u);
|
|
1392
|
+
};
|
|
1393
|
+
const rowGo = async (r, it, op) => {
|
|
1394
|
+
r.classList.add("gone");
|
|
1395
|
+
r.style.setProperty("--to", (op === "promote" ? 1 : -1) * r.offsetWidth + "px");
|
|
1396
|
+
if (motion()) await new Promise((ok) => setTimeout(ok, 180));
|
|
1397
|
+
if (soundPick() !== "off") playSound("pop");
|
|
1398
|
+
stepPast(new Set([iceKey(it)]));
|
|
1399
|
+
const j = await post("/icebox", { op, dir: it.dir, ids: [it.id] });
|
|
1400
|
+
if (j.ok) {
|
|
1401
|
+
toast(op === "promote" ? "Made a task" : "Dismissed");
|
|
1402
|
+
if (op === "dismiss") undoDismiss(it);
|
|
1403
|
+
}
|
|
1404
|
+
load();
|
|
1405
|
+
if (srcOpen()) openSources();
|
|
1406
|
+
};
|
|
1407
|
+
$("pbody")
|
|
1408
|
+
.querySelectorAll(".ice-prow[data-swipe]")
|
|
1409
|
+
.forEach((r) => {
|
|
1410
|
+
const f = r.querySelector(".ice-pf"),
|
|
1411
|
+
it = ice[+r.dataset.i];
|
|
1412
|
+
f.onpointerdown = (e) => {
|
|
1413
|
+
if (e.button || r.classList.contains("gone") || e.target.closest(".ice-ptask,.ice-kb,a,input,summary,.ice-mpop")) return;
|
|
1414
|
+
const x0 = e.clientX,
|
|
1415
|
+
y0 = e.clientY;
|
|
1416
|
+
let dx = 0,
|
|
1417
|
+
mode = "";
|
|
1418
|
+
// A tap after a drag or a hold must not also open the row.
|
|
1419
|
+
// A hold redraws the page under the finger, so the click that follows its release lands on
|
|
1420
|
+
// the new menu: it is eaten on the whole document until just after that release.
|
|
1421
|
+
const eat = () => {
|
|
1422
|
+
const k = (c) => {
|
|
1423
|
+
c.stopPropagation();
|
|
1424
|
+
c.preventDefault();
|
|
1425
|
+
};
|
|
1426
|
+
document.addEventListener("click", k, { capture: true, once: true });
|
|
1427
|
+
let gone = false;
|
|
1428
|
+
const off = () => {
|
|
1429
|
+
if (gone) return;
|
|
1430
|
+
gone = true;
|
|
1431
|
+
document.removeEventListener("pointerup", off, { capture: true });
|
|
1432
|
+
document.removeEventListener("pointercancel", off, { capture: true });
|
|
1433
|
+
setTimeout(() => document.removeEventListener("click", k, { capture: true }), 60);
|
|
1434
|
+
};
|
|
1435
|
+
if (mode === "hold") {
|
|
1436
|
+
// Released, cancelled by the browser, or left far too long: the blocker goes either way.
|
|
1437
|
+
document.addEventListener("pointerup", off, { capture: true });
|
|
1438
|
+
document.addEventListener("pointercancel", off, { capture: true });
|
|
1439
|
+
setTimeout(off, 5000);
|
|
1440
|
+
} else off();
|
|
1441
|
+
};
|
|
1442
|
+
const hold = setTimeout(() => {
|
|
1443
|
+
if (mode) return;
|
|
1444
|
+
mode = "hold";
|
|
1445
|
+
eat();
|
|
1446
|
+
iceCur = iceKey(it);
|
|
1447
|
+
iceMenu = iceKey(it) + " snooze";
|
|
1448
|
+
navigator.vibrate?.(10);
|
|
1449
|
+
openSources().then(() => $("pbody").querySelector(".ice-mpop button")?.focus());
|
|
1450
|
+
}, 500);
|
|
1451
|
+
const reset = () => {
|
|
1452
|
+
f.style.transform = "";
|
|
1453
|
+
r.style.removeProperty("--p");
|
|
1454
|
+
delete r.dataset.dir;
|
|
1455
|
+
};
|
|
1456
|
+
const end = (cancel) => {
|
|
1457
|
+
clearTimeout(hold);
|
|
1458
|
+
f.onpointermove = f.onpointerup = f.onpointercancel = null;
|
|
1459
|
+
if (mode !== "drag") return;
|
|
1460
|
+
r.classList.remove("drag");
|
|
1461
|
+
swHeld = false;
|
|
1462
|
+
const late = swLate;
|
|
1463
|
+
swLate = false;
|
|
1464
|
+
eat();
|
|
1465
|
+
if (!cancel && Math.abs(dx) > r.offsetWidth * 0.35) rowGo(r, it, dx > 0 ? "promote" : "dismiss");
|
|
1466
|
+
else {
|
|
1467
|
+
reset();
|
|
1468
|
+
if (late) openSources();
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
f.onpointermove = (m) => {
|
|
1472
|
+
const mx = m.clientX - x0,
|
|
1473
|
+
my = m.clientY - y0;
|
|
1474
|
+
if (!mode) {
|
|
1475
|
+
if (Math.hypot(mx, my) > 8) clearTimeout(hold);
|
|
1476
|
+
if (Math.abs(mx) > 10 && Math.abs(mx) > Math.abs(my)) {
|
|
1477
|
+
mode = "drag";
|
|
1478
|
+
f.setPointerCapture(m.pointerId);
|
|
1479
|
+
r.classList.add("drag");
|
|
1480
|
+
swHeld = true;
|
|
1481
|
+
} else if (Math.abs(my) > 10) mode = "scroll";
|
|
1482
|
+
}
|
|
1483
|
+
if (mode !== "drag") return;
|
|
1484
|
+
dx = mx;
|
|
1485
|
+
f.style.transform = `translateX(${dx}px)`;
|
|
1486
|
+
r.dataset.dir = dx > 0 ? "pro" : "dis";
|
|
1487
|
+
r.style.setProperty("--p", String(Math.min(1, Math.abs(dx) / (r.offsetWidth * 0.35))));
|
|
1488
|
+
};
|
|
1489
|
+
f.onpointerup = () => end(false);
|
|
1490
|
+
f.onpointercancel = () => end(true);
|
|
1491
|
+
};
|
|
1492
|
+
});
|
|
944
1493
|
if ($("ice-sw"))
|
|
945
1494
|
$("ice-sw").onclick = () => {
|
|
946
1495
|
iceSwipe = { n: 0, pro: 0, dis: 0, t0: Date.now(), last: null, skip: new Map(), busy: false, pop: false };
|
|
@@ -1025,6 +1574,11 @@ export async function openSources() {
|
|
|
1025
1574
|
srcShut();
|
|
1026
1575
|
return true;
|
|
1027
1576
|
}
|
|
1577
|
+
if (iceMenu) {
|
|
1578
|
+
iceMenu = "";
|
|
1579
|
+
openSources().then(focusCur);
|
|
1580
|
+
return true;
|
|
1581
|
+
}
|
|
1028
1582
|
if (iceForm) {
|
|
1029
1583
|
if (icePro) icePro = null;
|
|
1030
1584
|
else iceForm = null;
|
|
@@ -1044,9 +1598,17 @@ export async function openSources() {
|
|
|
1044
1598
|
const n = order[Math.max(0, Math.min(order.length - 1, at + (k === "j" ? 1 : -1)))];
|
|
1045
1599
|
iceCur = iceKey(ice[n]);
|
|
1046
1600
|
$("pbody")
|
|
1047
|
-
.querySelectorAll(".ice-row")
|
|
1601
|
+
.querySelectorAll(".ice-row,.ice-card")
|
|
1048
1602
|
.forEach((r) => r.classList.toggle("cur", +r.dataset.i === n));
|
|
1049
|
-
$("pbody").querySelector(
|
|
1603
|
+
$("pbody").querySelector(`:is(.ice-row,.ice-card)[data-i="${n}"]`)?.scrollIntoView({ block: "nearest" });
|
|
1604
|
+
return true;
|
|
1605
|
+
}
|
|
1606
|
+
// h: snooze for a week, the selection when there is one.
|
|
1607
|
+
if (k === "h") {
|
|
1608
|
+
const its = iceSel.size ? ice.filter((it) => iceSel.has(iceKey(it)) && live(it)) : live(ice[i]) ? [ice[i]] : [];
|
|
1609
|
+
if (!its.length) return false;
|
|
1610
|
+
e.preventDefault();
|
|
1611
|
+
snoozeAll(its, "1w");
|
|
1050
1612
|
return true;
|
|
1051
1613
|
}
|
|
1052
1614
|
const b =
|
|
@@ -1182,59 +1744,6 @@ export async function openSources() {
|
|
|
1182
1744
|
if (e.key === "Enter") $("src-add").click();
|
|
1183
1745
|
};
|
|
1184
1746
|
}
|
|
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
1747
|
if ($("src-go"))
|
|
1239
1748
|
$("src-go").onclick = () => {
|
|
1240
1749
|
$("src-go").disabled = true;
|