Files
RuneStone/src/lib/features/pm/storage/order.ts
T
Knotty Wyvern e66f089176 Make Project Management a native feature
- Move the storage and model of the plugin into src/lib/features/pm/ as pure TypeScript, so the skill can still bundle them.
- Move the DOM interface onto the host menus, the shared tooltip, and the host icons.
- A ribbon button opens Project Management. Board tabs keep the owner runestone.pm and the board-<hex> view IDs through view patterns.
- Read only .runestone/pm/. Offer the plugin migration, with backups, for legacy notes.
- A save, move, or delete reads only that card again. Watcher paths reach the feature.
- Add Settings → Project Management and the projectManagement section. View states move to localStorage.
- Background reads the boards from workspace.json. Remove api.backgrounds and the boards service.
- Add yaml 2.9.1. Use the host markdown-it.
- Move 18 plugin test files to tests/unit/features/pm/ and add native tests.
2026-10-29 20:54:29 -07:00

42 lines
1.5 KiB
TypeScript

import type { Task } from "../model/model.ts";
const digits = "0123456789abcdefghijklmnopqrstuvwxyz";
const encode = (text: string) =>
text
.split("")
.map((char) => char.charCodeAt(0).toString(16).padStart(4, "0"))
.join("");
export function cardOrder(task: Task, boardId?: string): string {
const saved = boardId ? task.placements?.[boardId]?.order : task.order;
// Old notes keep filename order. Title edits do not change their positions.
const position = saved ?? legacyPosition(task.path);
// The ID breaks ties when separate windows choose the same position.
return position + "i" + encode(task.id) + "8";
}
export function legacyPosition(path: string): string {
return encode(path.split("/").at(-1)!.toLowerCase()) + "0000" + encode(path);
}
export function compareCards(a: Task, b: Task, boardId?: string): number {
const left = cardOrder(a, boardId),
right = cardOrder(b, boardId);
return left < right ? -1 : left > right ? 1 : 0;
}
export function orderBetween(lower?: string, upper?: string): string {
if (lower !== undefined && upper !== undefined && lower >= upper)
throw new Error("The card order changed. Refresh the board.");
let result = "";
for (let index = 0; ; index++) {
const low =
index < (lower?.length ?? 0) ? digits.indexOf(lower![index]) : 0;
const high =
upper === undefined ? digits.length : digits.indexOf(upper[index]);
if (high - low > 1) return result + digits[Math.floor((low + high) / 2)];
result += digits[low];
if (low < high) upper = undefined;
}
}