Translate Project Management and add its tests and guide

- Every interface string of Project Management goes through the catalog: 539 new rows with fr, ja, and zh-CN.
- Storage and model messages use a local message() marker and stay free of host imports. The interface translates them.
- A board renders again when the language changes. Dates use the interface language.
- Fix: the ribbon button waits for the feature switches at startup, and the settings code loads no feature module.
- Add six smoke tests: board state, cards, menus, drag and drop, views, and language.
- Add docs/guides/project-management.md and UI-060. Update the user, plugin, SDK, host, development, and interface docs and CLAUDE.md.
- Name the fake board view of tree/renameUndo "Board fixture", because the native Project Management button is now in the ribbon.
This commit is contained in:
Knotty Wyvern
2026-10-29 21:53:09 -07:00
parent e66f089176
commit 956ead818b
53 changed files with 2510 additions and 867 deletions
+27 -28
View File
@@ -1,4 +1,6 @@
import { tooltip } from "./host.ts";
import { message, tr } from "../../../i18n/index.ts";
import { errorText } from "./text.ts";
import type { Workspace, TaskFields } from "../model/model.ts";
import {
imageMarkdown,
@@ -10,10 +12,11 @@ import {
saveImages,
} from "../storage/images.ts";
/** Image data stays outside card Markdown and loads only in the open editor. */
/** The image data stays outside the card Markdown and loads only in the open editor. */
export function createCardImages(
workspace: Workspace,
description: HTMLTextAreaElement,
/** Make a control. `name` is a catalog key in English. The control shows its translation. */
control: (name: string, action: () => void) => HTMLButtonElement,
removeControl: (name: string, action: () => void) => HTMLButtonElement,
changed: (loading: boolean) => void,
@@ -25,8 +28,7 @@ export function createCardImages(
const hint = document.createElement("p");
hint.className = "pm-muted";
hint.id = `pm-image-hint-${crypto.randomUUID()}`;
hint.textContent =
"Paste or drop an image into Details, or choose Add image. PNG, JPEG, GIF, or WebP. Up to 50 MiB each.";
hint.textContent = tr("Paste or drop an image into Details, or choose Add image. PNG, JPEG, GIF, or WebP. Up to 50 MiB each.");
description.setAttribute("aria-describedby", hint.id);
const error = document.createElement("p");
error.className = "pm-error";
@@ -34,24 +36,24 @@ export function createCardImages(
const gallery = document.createElement("div");
gallery.className = "pm-image-gallery";
gallery.setAttribute("role", "group");
gallery.setAttribute("aria-label", "Images in card details");
gallery.setAttribute("aria-label", tr("Images in card details"));
const input = document.createElement("input");
input.type = "file";
input.accept = imageTypes.join(",");
input.multiple = true;
input.hidden = true;
input.setAttribute("aria-label", "Insert images in description");
const add = control("Add image", () => input.click());
input.setAttribute("aria-label", tr("Insert images in description"));
const add = control(message("Add image"), () => input.click());
const attachmentInput = input.cloneNode() as HTMLInputElement;
attachmentInput.setAttribute("aria-label", "Attach images to card");
const attach = control("Attach image", () => attachmentInput.click());
const heading = document.createElement("h3"); heading.textContent = "Attachments";
attachmentInput.setAttribute("aria-label", tr("Attach images to card"));
const attach = control(message("Attach image"), () => attachmentInput.click());
const heading = document.createElement("h3"); heading.textContent = tr("Attachments");
const header = document.createElement("div"); header.className = "pm-attachment-heading";
header.append(heading, attach);
const attachmentGallery = document.createElement("div"); attachmentGallery.className = "pm-image-gallery";
attachmentGallery.setAttribute("role", "group"); attachmentGallery.setAttribute("aria-label", "Image attachments");
attachmentGallery.setAttribute("role", "group"); attachmentGallery.setAttribute("aria-label", tr("Image attachments"));
const attachmentsElement = document.createElement("section"); attachmentsElement.className = "pm-attachments pm-wide";
attachmentsElement.setAttribute("aria-label", "Attachments");
attachmentsElement.setAttribute("aria-label", tr("Attachments"));
const attachmentError = document.createElement("p"); attachmentError.className = "pm-error"; attachmentError.setAttribute("role", "alert");
attachmentsElement.append(header, attachmentInput, attachmentError, attachmentGallery);
element.append(input, hint, error, gallery);
@@ -87,13 +89,13 @@ export function createCardImages(
full.src = source.src;
full.alt = source.alt;
frame.append(full);
const size = control("Actual size", () => {
const size = control(message("Actual size"), () => {
const actual = frame.classList.toggle("pm-image-actual");
size.setAttribute("aria-pressed", String(actual));
placeControls();
});
size.setAttribute("aria-pressed", "false");
const close = removeControl("Close image", () => dialog.close());
const close = removeControl(tr("Close image"), () => dialog.close());
header.append(title, size, close);
dialog.append(header, frame);
const placeControls = () => {
@@ -119,7 +121,7 @@ export function createCardImages(
viewer = undefined;
if (!disposed && trigger.isConnected) trigger.focus({ preventScroll: true });
};
// Keep the viewer outside the gallery, which is hidden in description previews.
// Keep the viewer outside the gallery, because the description preview hides the gallery.
(description.closest(".pm-editor") ?? element.parentElement ?? element).append(dialog);
const outside = (target: EventTarget | null) => target === dialog || target === frame;
let outsidePointer = false;
@@ -147,7 +149,7 @@ export function createCardImages(
});
dialog.showModal();
placeControls();
// Focus the surface first so pointer users can see an unobstructed image.
// Focus the surface first, so that a pointer user can see all of the image.
dialog.tabIndex = -1;
dialog.focus();
idleTimer = setTimeout(() => dialog.classList.add("pm-image-controls-idle"), 2000);
@@ -165,7 +167,7 @@ export function createCardImages(
name.title = ref.name;
caption.append(
name,
removeControl(`Remove image ${ref.name}`, () => {
removeControl(tr("Remove image {name}", { name: ref.name }), () => {
if (attached) {
attachments.splice(attachments.findIndex(item => item.id === ref.id), 1);
description.dispatchEvent(new Event("input", { bubbles: true }));
@@ -192,8 +194,8 @@ export function createCardImages(
const thumbnail = document.createElement("button");
thumbnail.type = "button";
thumbnail.className = "pm-image-thumbnail";
thumbnail.setAttribute("aria-label", `View image ${ref.name}`);
tooltip(thumbnail, `View image ${ref.name}`);
thumbnail.setAttribute("aria-label", tr("View image {name}", { name: ref.name }));
tooltip(thumbnail, tr("View image {name}", { name: ref.name }));
thumbnail.onclick = () => showImage(image, thumbnail);
thumbnail.append(image);
const failure = document.createElement("p");
@@ -201,7 +203,7 @@ export function createCardImages(
failure.setAttribute("role", "alert");
const fail = () => {
thumbnail.remove();
failure.textContent = `Cannot display ${ref.name}. Restore the image file or remove its reference.`;
failure.textContent = tr("Cannot display {name}. Restore the image file or remove its reference.", { name: ref.name });
};
image.onerror = fail;
figure.append(thumbnail, caption, failure);
@@ -237,9 +239,9 @@ export function createCardImages(
const staged: { id: string; name: string; data: string }[] = [];
for (const file of files) {
if (!imageTypes.includes(file.type))
throw new Error("Use a PNG, JPEG, GIF, or WebP image.");
throw new Error(message("Use a PNG, JPEG, GIF, or WebP image."));
if (!file.size || file.size > maxImageBytes)
throw new Error("Use an image between 1 byte and 50 MiB.");
throw new Error(message("Use an image between 1 byte and 50 MiB."));
const bytes = new Uint8Array(await file.arrayBuffer());
let binary = "";
for (let offset = 0; offset < bytes.length; offset += 8192)
@@ -247,17 +249,15 @@ export function createCardImages(
...bytes.subarray(offset, offset + 8192),
);
const data = `data:${file.type};base64,${btoa(binary)}`;
// Decode before inserting a reference, so invalid clipboard files preserve the draft.
// Decode the image before the reference goes in, so that an invalid clipboard file keeps the draft.
const image = new Image();
image.src = data;
await image.decode().catch(() => {
throw new Error(
"The image cannot be read. Copy it again or choose another file.",
);
throw new Error(message("The image cannot be read. Copy it again or choose another file."));
});
staged.push({
id: crypto.randomUUID(),
name: (file.name || "Pasted image").slice(0, 255),
name: (file.name || tr("Pasted image")).slice(0, 255),
data,
});
}
@@ -271,8 +271,7 @@ export function createCardImages(
description.dispatchEvent(new Event("input", { bubbles: true }));
} catch (reason) {
if (!disposed)
(attachOnly ? attachmentError : error).textContent =
reason instanceof Error ? reason.message : String(reason);
(attachOnly ? attachmentError : error).textContent = errorText(reason);
} finally {
loading = false;
if (!disposed) {