Files
RuneStone/src/lib/features/pm/storage/description-draft.ts
T
Knotty Wyvern 956ead818b 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.
2026-10-29 21:53:09 -07:00

35 lines
1.5 KiB
TypeScript

import type { Workspace } from "../model/model.ts";
import { readOptional, saveDocument } from "./persistence.ts";
import { message } from "./message.ts";
/** A draft is separate from the saved card and uses compare-and-write protection. */
export class DescriptionDraft {
private source: string | null = null;
private queue: Promise<unknown> = Promise.resolve();
readonly path: string;
private workspace: Workspace;
constructor(workspace: Workspace, id: string) {
this.workspace = workspace;
const key = Array.from(new TextEncoder().encode(id), byte => byte.toString(16).padStart(2, "0")).join("");
this.path = `.runestone/pm/drafts/${key}.json`;
}
async load(): Promise<string | null> {
this.source = await readOptional(this.workspace, this.path);
if (this.source === null) return null;
const value = JSON.parse(this.source);
if (value?.schema !== 1 || (value.body !== null && typeof value.body !== "string"))
throw new Error(message("The description draft is invalid. Preserve it before recovery."));
return value.body;
}
save(body: string | null): Promise<void> {
const write = this.queue.then(async () => {
const source = JSON.stringify({ schema: 1, body }) + "\n";
if (source === this.source || (body === null && this.source === null)) return;
await saveDocument(this.workspace, this.path, source, this.source);
this.source = source;
});
this.queue = write.catch(() => {});
return write;
}
}