Open any picture thumbnail in the shared picview

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 03:24:39 -08:00
1 parent 1eef797dc0
commit c26759fd88
10 files changed
+495 -254

No files matched your search

+49 -21
View File
@@ -6,8 +6,9 @@ import { finish, activity, agentAdrift, isDashboard, selSpec, byId, isOpen, loop
import { el, md, isMac, lightDismiss, shortTime } from "../render.js";
import { startersFor } from "../starters.js";
import { looks } from "../looks.js";
import { thumbs, uploadUrl, docChip, attachTray, CHAT_IMAGES, attachFiles, incomingFiles, deleteUrl, sentAttachments, noteImages, attachRow } from "../uploads.js";
import { thumbs, uploadUrl, docChip, attachTray, CHAT_IMAGES, attachFiles, incomingFiles, deleteUrl, sentAttachments, noteImages, attachRow, openPicview, refocusThumb } from "../uploads.js";
import { attachMentions } from "../mention-box.js";
import { makeMdField } from "../md-field.js";
import { pickerAccept, attachmentKind, noteAwaiting, threadWho, threadText } from "../answers.js";
import { postJson } from "../net.js";
import { CHECKIN_LINE, helperRows, showSwitch, switchLabel, defaultInstruction, PATHFINDER_RESEARCH_LINE, STRENGTHS, DEFAULT_STRENGTH, STRENGTH_HELP } from "../subagents.js";
@@ -26,6 +27,10 @@ export const declineOpen = new Map();
const deciding = new Set();
// The Subagents dialog's instruction box, a Markdown field made once in
// wireAsk into its #subagents-instruction mount.
let instrField = null;
// The frame's chat block, with `offline` worked out now rather than when the
// frame was sent: the agent comes and goes between frames, and /ping keeps
// agentLastSeen current. The frame's own verdict stands when there is no clock.
@@ -125,7 +130,11 @@ function askStarters(ss) {
function askRow(r, ss, notes) {
if (r.kind === "decision") {
const row = el("div", "ask-row decision");
row.appendChild(el("p", "ask-decision", r.decision !== "approve" ? "You declined the edit." : r.done ? "You approved the edit." : "You approved the edit, please wait..."));
const working = r.decision === "approve" && !r.done;
const line = el("p", working ? "ask-decision working" : "ask-decision");
if (working) line.appendChild(el("span", "spinner tiny"));
line.appendChild(document.createTextNode(r.decision !== "approve" ? "You declined the edit." : r.done ? "You approved the edit." : "You approved the edit, please wait..."));
row.appendChild(line);
if (r.text) row.appendChild(el("p", "ask-text", r.text));
return row;
}
@@ -153,14 +162,26 @@ function askRow(r, ss, notes) {
const hasFiles = r.files && r.files.length;
if (hasImages || hasFiles) {
const tray = el("div", "attach-tray");
for (const img of r.images || []) {
// A message echoed by the server has no key (it keeps path and name), so
// the thumbnail's refocus token is the picture's own URL, which is unique
// and the same for a pending send and its echo: the token survives a
// redraw while the picview is open.
(r.images || []).forEach((img, i) => {
const fig = el("figure", "attach-thumb is-ready");
fig.dataset.key = uploadUrl(img);
const pic = el("img");
pic.src = thumbs.get(img.key) || uploadUrl(img);
pic.alt = img.name || "image";
fig.appendChild(pic);
const open = el("button", "attach-open");
open.type = "button";
open.appendChild(pic);
open.addEventListener("click", () => {
const slides = (r.images || []).map((x) => ({ url: uploadUrl(x), alt: x.name || "image" }));
openPicview(slides, i, () => refocusThumb(fig.dataset.key));
});
fig.appendChild(open);
tray.appendChild(fig);
}
});
for (const file of r.files || []) tray.appendChild(docChip(file, "ready"));
row.appendChild(tray);
}
@@ -271,14 +292,15 @@ function askComposer(ss) {
}
if (page.local.chat.images.length) comp.appendChild(attachTray(CHAT_IMAGES, page.local.chat.images));
const ta = el("textarea");
ta.id = "ask-input";
ta.placeholder = "Ask anything about this project";
ta.value = page.local.chat.draft || "";
ta.disabled = !ss.canType;
ta.setAttribute("aria-label", "Your question");
const ta = makeMdField({
id: "ask-input",
placeholder: "Ask anything about this project",
label: "Your question",
value: page.local.chat.draft || "",
disabled: !ss.canType,
});
attachMentions(ta);
comp.appendChild(ta);
comp.appendChild(ta.el);
const row = el("div", "ask-actions");
const add = el("button", "btn small ghost", "+ Attach file");
@@ -680,10 +702,12 @@ export function renderAside() {
if (attached.length) wrap.appendChild(attachTray(item.id, attached));
const ta = el("textarea");
ta.id = id;
ta.placeholder = "Goes with your next send. It does not answer the question.";
ta.value = page.local.drafts[id] || "";
const ta = makeMdField({
id,
placeholder: "Goes with your next send. It does not answer the question.",
label: "Add a note, attach a file, or ask something",
value: page.local.drafts[id] || "",
});
attachMentions(ta);
ta.addEventListener("input", () => {
setDraft(id, ta.value);
@@ -697,7 +721,8 @@ export function renderAside() {
if (!e.clipboardData.getData("text/plain")) e.preventDefault();
attachFiles(item.id, files);
});
wrap.appendChild(ta);
label.addEventListener("click", () => ta.focus());
wrap.appendChild(ta.el);
aside.appendChild(wrap);
aside.scrollTop = place;
}
@@ -779,7 +804,7 @@ export function openSubagents() {
for (const radio of document.querySelectorAll('input[name="subagents-on"]')) {
radio.checked = radio.value === (on ? "on" : "off");
}
$("subagents-instruction").value = page.subagentsFrame.instruction ?? defaultInstruction(page.S.workflow);
instrField.value = page.subagentsFrame.instruction ?? defaultInstruction(page.S.workflow);
$("subagents-max").value = String(page.subagentsFrame.max);
const strength = STRENGTHS.includes(page.subagentsFrame.strength) ? page.subagentsFrame.strength : DEFAULT_STRENGTH;
for (const radio of document.querySelectorAll('input[name="subagents-strength"]')) radio.checked = radio.value === strength;
@@ -801,7 +826,8 @@ export function openSubagents() {
export function syncSubagentsFields() {
const picked = document.querySelector('input[name="subagents-on"]:checked');
const off = !picked || picked.value !== "on";
for (const id of ["subagents-instruction", "subagents-max", "subagents-default"]) $(id).disabled = off;
instrField.disabled = off;
for (const id of ["subagents-max", "subagents-default"]) $(id).disabled = off;
for (const radio of document.querySelectorAll('input[name="subagents-strength"]')) radio.disabled = off;
}
@@ -825,7 +851,7 @@ export async function saveSubagents() {
const save = $("subagents-save");
const status = $("subagents-status");
const picked = document.querySelector('input[name="subagents-on"]:checked');
const text = $("subagents-instruction").value.trim();
const text = instrField.value.trim();
// The shipped default is stored as null, so a later release's wording
// reaches everyone who never changed it.
const instruction = text === defaultInstruction(page.S.workflow) ? null : text;
@@ -853,12 +879,14 @@ export const askOfflineFlipped = () => (askState().send.state === "offline") !==
// The Subagents dialog's buttons, and dropping files onto the notes panel.
export function wireAsk() {
instrField = makeMdField({ className: "subagents-instruction", label: "Instruction", maxLength: 2000 });
$("subagents-instruction").appendChild(instrField.el);
for (const radio of document.querySelectorAll('input[name="subagents-on"]')) radio.addEventListener("change", syncSubagentsFields);
for (const radio of document.querySelectorAll('input[name="subagents-strength"]')) radio.addEventListener("change", syncStrengthHelp);
lightDismiss($("subagents-modal"));
$("btn-subagents").addEventListener("click", openSubagents);
$("subagents-default").addEventListener("click", () => {
$("subagents-instruction").value = defaultInstruction(page.S.workflow);
instrField.value = defaultInstruction(page.S.workflow);
});
$("subagents-save").addEventListener("click", saveSubagents);
$("subagents-cancel").addEventListener("click", () => $("subagents-modal").close());
+12 -57
View File
@@ -26,14 +26,13 @@ import {
nextSave,
noteBytes,
saveStatus,
step,
tabNameProblem,
tabSwitch,
unsaved,
} from "../notepad.js";
import { el, lightDismiss } from "../render.js";
import { postJson } from "../net.js";
import { reencode } from "../uploads.js";
import { reencode, openPicview } from "../uploads.js";
import { createTabs } from "../notepad-tabs.js";
import { skillFor } from "../skills.js";
@@ -629,7 +628,7 @@ export async function addNotepadImages(files) {
function thumbItem(entry, n) {
const item = el("li", `attach-thumb notepad-thumb is-${entry.status}`);
item.dataset.key = entry.key;
const open = el("button", "notepad-thumb-open");
const open = el("button", "attach-open");
open.type = "button";
const src = entry.thumb || entry.url;
if (src) {
@@ -690,7 +689,7 @@ function thumbItem(entry, n) {
}
// The controls a thumbnail can hold the focus on, by class.
const THUMB_CONTROLS = ["notepad-thumb-open", "notepad-thumb-delete", "notepad-ask-keep", "notepad-ask-delete", "notepad-retry"];
const THUMB_CONTROLS = ["attach-open", "notepad-thumb-delete", "notepad-ask-keep", "notepad-ask-delete", "notepad-retry"];
// Every redraw rebuilds the thumbnails, which would drop a focused button
// out of the page: the focus goes back to the same control, or to that
@@ -703,7 +702,7 @@ function drawStrip() {
const control = was && THUMB_CONTROLS.find((cls) => active.classList.contains(cls));
strip.replaceChildren(...images.map((entry, i) => thumbItem(entry, i + 1)));
if (!was) return;
if (!(control && focusIn(was.dataset.key, "." + control)) && !focusIn(was.dataset.key, ".notepad-thumb-open")) {
if (!(control && focusIn(was.dataset.key, "." + control)) && !focusIn(was.dataset.key, ".attach-open")) {
$("notepad-add").focus();
}
}
@@ -748,7 +747,7 @@ async function remove(entry) {
drop(entry.key);
drawStrip();
const next = images[at] || images[at - 1];
if (next) focusIn(next.key, ".notepad-thumb-open");
if (next) focusIn(next.key, ".attach-open");
else $("notepad-add").focus();
}
@@ -768,58 +767,15 @@ function takeStored(list, tabId) {
/* ------------------------------------------------------------ preview */
// What the preview steps through (the pictures with a stored copy, as they
// stood when it opened), which one shows, and the thumbnail it opened from.
let viewing = { list: [], index: -1, from: null };
function showAt(index) {
const { list } = viewing;
const entry = list[index];
viewing.index = index;
const pic = $("notepad-preview-img");
pic.src = entry.url;
pic.alt = `Notebook image ${images.indexOf(entry) + 1}`;
$("notepad-preview-count").textContent = `${index + 1} of ${list.length}`;
$("notepad-preview-prev").hidden = $("notepad-preview-next").hidden = list.length < 2;
}
// The shared picview over the strip's pictures (those with a stored copy, as
// they stand now); closing it puts the focus back on the opening thumbnail.
function openPreview(entry) {
const list = images.filter((img) => img.url);
const index = list.indexOf(entry);
if (index < 0) return;
viewing = { list, index, from: entry.key };
showAt(index);
const dlg = $("notepad-preview");
if (!dlg.open) dlg.showModal();
$("notepad-preview-close").focus();
}
function move(delta) {
const index = step(viewing.index, delta, viewing.list.length);
if (index >= 0) showAt(index);
}
// Esc is taken here and closes the preview alone: left to the browser, it
// could reach the Notebook underneath too.
function wirePreview() {
const dlg = $("notepad-preview");
$("notepad-preview-prev").addEventListener("click", () => move(-1));
$("notepad-preview-next").addEventListener("click", () => move(1));
$("notepad-preview-close").addEventListener("click", () => dlg.close());
dlg.addEventListener("keydown", (e) => {
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
e.preventDefault();
move(e.key === "ArrowLeft" ? -1 : 1);
} else if (e.key === "Escape") {
e.preventDefault();
e.stopPropagation();
dlg.close();
}
});
dlg.addEventListener("close", () => {
$("notepad-preview-img").removeAttribute("src");
focusIn(viewing.from, ".notepad-thumb-open");
});
openPicview(
list.map((img) => ({ url: img.url, alt: `Notebook image ${images.indexOf(img) + 1}` })),
list.indexOf(entry),
() => focusIn(entry.key, ".attach-open"),
);
}
// A paste is a picture paste when it carries image files and no plain text:
@@ -948,7 +904,6 @@ export function wireNotepad() {
});
lightDismiss(dlg);
wireImages(dlg);
wirePreview();
$("btn-notepad").addEventListener("click", openNotepad);
$("notepad-close").addEventListener("click", () => dlg.close());
$("notepad-tab-new").addEventListener("click", () => openNameForm("new"));