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
+35 -29
View File
@@ -1,3 +1,5 @@
import { message } from "../storage/message.ts";
export const statuses = ["todo", "doing", "done"] as const;
export type Status = (typeof statuses)[number];
export const priorities = ["highest", "high", "medium", "low", "lowest"] as const;
@@ -6,11 +8,17 @@ export function availablePriorities(levels: PriorityLevels): readonly Priority[]
return levels === 2 ? ["high", "low"] : levels === 3 ? ["high", "medium", "low"] : priorities;
}
export type Priority = (typeof priorities)[number];
export const priorityNames: Record<Priority, string> = { highest: "Highest", high: "High", medium: "Medium", low: "Low", lowest: "Lowest" };
export const priorityNames: Record<Priority, string> = {
highest: message("Highest"),
high: message("High"),
medium: message("Medium"),
low: message("Low"),
lowest: message("Lowest"),
};
export const statusNames: Record<Status, string> = {
todo: "To do",
doing: "In progress",
done: "Done",
todo: message("To do"),
doing: message("In progress"),
done: message("Done"),
};
export const cardColors = {
red: "#df7373",
@@ -91,7 +99,7 @@ export function validDate(value: unknown): value is string {
return !isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value;
}
export function addDays(value: string, days: number): string {
if (!validDate(value)) throw new Error("Enter a valid calendar date.");
if (!validDate(value)) throw new Error(message("Enter a valid calendar date."));
const date = new Date(`${value}T12:00:00Z`);
date.setUTCDate(date.getUTCDate() + days);
return date.toISOString().slice(0, 10);
@@ -112,24 +120,24 @@ export function localTime(instant: string): string {
export function localInstant(value: string): string {
const date = new Date(value);
if (isNaN(date.getTime()) || localTime(date.toISOString()) !== value)
throw new Error("Enter an existing local date and time.");
throw new Error(message("Enter an existing local date and time."));
return date.toISOString();
}
export function validateFields(fields: TaskFields): void {
if (fields.createdAt !== undefined && (typeof fields.createdAt !== "string" ||
!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(fields.createdAt) ||
!validDate(fields.createdAt.slice(0, 10)) || !Number.isFinite(Date.parse(fields.createdAt))))
throw new Error("The card creation timestamp is invalid.");
throw new Error(message("The card creation timestamp is invalid."));
if (fields.attachments !== undefined && (!Array.isArray(fields.attachments) || fields.attachments.some(item => !item || typeof item.id !== "string" || !/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(item.id) || typeof item.name !== "string" || !item.name.trim() || item.name.length > 255) || new Set(fields.attachments.map(item => item.id)).size !== fields.attachments.length))
throw new Error("Each image attachment needs a unique image ID and a name of 1 to 255 characters.");
throw new Error(message("Each image attachment needs a unique image ID and a name of 1 to 255 characters."));
if (fields.priority !== undefined && fields.priority !== null && !priorities.includes(fields.priority))
throw new Error("Choose a supported priority or No priority.");
throw new Error(message("Choose a supported priority or No priority."));
if (fields.coverImage != null && !/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(fields.coverImage))
throw new Error("Choose an image from this card.");
throw new Error(message("Choose an image from this card."));
if (fields.subtasks !== undefined && (!Array.isArray(fields.subtasks) || fields.subtasks.some(item => !item || typeof item.id !== "string" || !item.id || typeof item.title !== "string" || !item.title.trim() || item.title.length > 200 || typeof item.done !== "boolean" || (item.taskId !== undefined && (typeof item.taskId !== "string" || !item.taskId))) || new Set(fields.subtasks.map(item => item.id)).size !== fields.subtasks.length))
throw new Error("Each subtask needs a unique ID, a title, and a completion state.");
throw new Error(message("Each subtask needs a unique ID, a title, and a completion state."));
if (fields.links !== undefined && (!Array.isArray(fields.links) || fields.links.some(item => !item || typeof item.taskId !== "string" || !item.taskId || !["relates", "blocks", "blocked-by"].includes(item.relation)) || new Set(fields.links.map(item => item.taskId)).size !== fields.links.length))
throw new Error("Choose each linked card once and select its relationship.");
throw new Error(message("Choose each linked card once and select its relationship."));
if (
fields.title !== undefined &&
(typeof fields.title !== "string" ||
@@ -137,19 +145,19 @@ export function validateFields(fields: TaskFields): void {
fields.title.length > 100 ||
/[\x00-\x1f]/.test(fields.title))
)
throw new Error("Enter a card title of 1 to 100 characters.");
throw new Error(message("Enter a card title of 1 to 100 characters."));
const validOrder = (value: unknown) =>
value === undefined ||
(typeof value === "string" && /^[0-9a-z]*[1-9a-z]$/.test(value));
if (!validOrder(fields.order))
throw new Error("The card order is invalid. Refresh the board.");
throw new Error(message("The card order is invalid. Refresh the board."));
if (fields.placements !== undefined) {
if (
!fields.placements ||
typeof fields.placements !== "object" ||
Array.isArray(fields.placements)
)
throw new Error("Board placements must be a mapping.");
throw new Error(message("Board placements must be a mapping."));
for (const [id, placement] of Object.entries(fields.placements)) {
if (
!id.trim() ||
@@ -160,9 +168,7 @@ export function validateFields(fields: TaskFields): void {
(typeof placement.listId !== "string" || !placement.listId)) ||
!validOrder(placement.order)
)
throw new Error(
"Each board placement needs a board ID and a valid list ID.",
);
throw new Error(message("Each board placement needs a board ID and a valid list ID."));
}
}
if (
@@ -170,13 +176,13 @@ export function validateFields(fields: TaskFields): void {
(typeof fields.color !== "string" ||
!Object.hasOwn(cardColors, fields.color))
)
throw new Error("Choose a supported card color.");
throw new Error(message("Choose a supported card color."));
if (
fields.assignees !== undefined &&
(!Array.isArray(fields.assignees) ||
fields.assignees.some((name) => typeof name !== "string" || !name.trim()))
)
throw new Error("Assignments must contain names.");
throw new Error(message("Assignments must contain names."));
if (fields.customFields !== undefined) {
if (
!Array.isArray(fields.customFields) ||
@@ -188,26 +194,26 @@ export function validateFields(fields: TaskFields): void {
typeof field.value !== "string",
)
)
throw new Error("Each custom field needs a name and a text value.");
throw new Error(message("Each custom field needs a name and a text value."));
const names = fields.customFields.map((field) =>
field.name.trim().toLocaleLowerCase(),
);
if (new Set(names).size !== names.length)
throw new Error("Use a different name for each custom field.");
throw new Error(message("Use a different name for each custom field."));
}
if (
fields.listId !== undefined &&
fields.listId !== null &&
(typeof fields.listId !== "string" || !fields.listId)
)
throw new Error("The task has an invalid list ID.");
throw new Error(message("The task has an invalid list ID."));
if (!statuses.includes(fields.status))
throw new Error("Choose a supported task status.");
throw new Error(message("Choose a supported task status."));
if (
!Array.isArray(fields.tags) ||
fields.tags.some((tag) => typeof tag !== "string")
)
throw new Error("Tags must be text.");
throw new Error(message("Tags must be text."));
if (
fields.labels !== undefined &&
(!Array.isArray(fields.labels) ||
@@ -216,16 +222,16 @@ export function validateFields(fields: TaskFields): void {
) ||
new Set(fields.labels).size !== fields.labels.length)
)
throw new Error("Labels must contain unique saved label IDs.");
throw new Error(message("Labels must contain unique saved label IDs."));
if (fields.due && !validDate(fields.due.date))
throw new Error("Enter a valid deadline date.");
throw new Error(message("Enter a valid deadline date."));
if (
fields.plan &&
(!validDate(fields.plan.start) ||
!validDate(fields.plan.end) ||
fields.plan.end <= fields.plan.start)
) {
throw new Error("The planned end must follow the start.");
throw new Error(message("The planned end must follow the start."));
}
const ids = new Set<string>();
for (const session of fields.sessions) {
@@ -242,7 +248,7 @@ export function validateFields(fields: TaskFields): void {
!Number.isFinite(Date.parse(session.end)) ||
Date.parse(session.end) <= Date.parse(session.start)
)
throw new Error("Each session needs a unique ID and a valid time range.");
throw new Error(message("Each session needs a unique ID and a valid time range."));
new Intl.DateTimeFormat("en", { timeZone: session.timeZone }).format();
ids.add(session.id);
}