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.
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<!--
|
||||
Settings → Project Management, and the Project Management settings of the board menu. It is in the main bundle and
|
||||
loads no feature code: the priority levels are in the `projectManagement` settings section (`pmSettings.ts`), and
|
||||
the default board is in `.runestone/pm/workspace.json` of the workspace (`pmBoards.ts`). It shows only while
|
||||
Project Management is on. Each change saves at once.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import { t } from "$lib/i18n";
|
||||
import Icon from "$lib/ui/Icon.svelte";
|
||||
import { showActionMenu } from "$lib/ui/managedActionMenu";
|
||||
import { PRIORITY_LEVELS, onProjectManagementChange, readProjectManagement, writeProjectManagement, type PriorityLevels, type ProjectManagementSettings } from "./pmSettings";
|
||||
import { readBoardCatalog, writeDefaultBoard, type BoardSummary } from "./pmBoards";
|
||||
|
||||
let { compact = false }: { compact?: boolean } = $props();
|
||||
|
||||
const levelNames: Record<PriorityLevels, string> = { 2: "2 — High and Low", 3: "3 — High, Medium, and Low", 5: "5 — Highest through Lowest" };
|
||||
let settings = $state<ProjectManagementSettings>(readProjectManagement());
|
||||
let boards = $state<BoardSummary[]>([]);
|
||||
let defaultBoard = $state("");
|
||||
let boardsReady = $state(false);
|
||||
let boardNote = $state("");
|
||||
let saving = $state(false);
|
||||
let message = $state("");
|
||||
let error = $state("");
|
||||
let closeMenu = () => {};
|
||||
let disposed = false;
|
||||
const active = $derived(boards.filter(board => !board.archived));
|
||||
const boardName = $derived(defaultBoard ? active.find(board => board.id === defaultBoard)?.name ?? "Unavailable board (opens All tasks)" : "All tasks");
|
||||
|
||||
function picker(event: MouseEvent, label: string, choices: { label: string; checked: boolean; run: () => void }[]) {
|
||||
closeMenu();
|
||||
const anchor = event.currentTarget as HTMLButtonElement;
|
||||
const bounds = anchor.getBoundingClientRect();
|
||||
closeMenu = showActionMenu({ x: bounds.left, y: bounds.bottom + 4, label, parent: anchor.closest("dialog") ?? undefined,
|
||||
items: choices.map(choice => ({ label: choice.label, radio: true, checked: choice.checked, run: choice.run })) }).close;
|
||||
}
|
||||
|
||||
function saveLevels(priorityLevels: PriorityLevels) {
|
||||
error = "";
|
||||
settings = { ...settings, priorityLevels };
|
||||
writeProjectManagement(settings).then(() => { message = $t("Changes saved."); })
|
||||
.catch(() => { error = $t("Could not save these settings. Your previous settings still apply. Try again."); message = ""; settings = readProjectManagement(); });
|
||||
}
|
||||
|
||||
async function saveDefault(id: string) {
|
||||
const previous = defaultBoard;
|
||||
error = ""; saving = true; defaultBoard = id;
|
||||
try { await writeDefaultBoard(id || null); if (!disposed) message = $t("Changes saved."); }
|
||||
catch (reason) { if (!disposed) { defaultBoard = previous; message = ""; error = reason instanceof Error ? reason.message : String(reason); } }
|
||||
finally { saving = false; }
|
||||
}
|
||||
|
||||
async function readBoards() {
|
||||
try {
|
||||
const catalog = await readBoardCatalog();
|
||||
if (disposed) return;
|
||||
boards = catalog.boards;
|
||||
defaultBoard = catalog.defaultBoardId ?? "";
|
||||
boardsReady = true;
|
||||
boardNote = "";
|
||||
} catch (reason) {
|
||||
if (!disposed) boardNote = /no workspace/i.test(String(reason)) ? "Open a workspace to choose its default board." : reason instanceof Error ? reason.message : String(reason);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
void readBoards();
|
||||
return onProjectManagementChange(() => { settings = readProjectManagement(); });
|
||||
});
|
||||
onDestroy(() => { disposed = true; closeMenu(); });
|
||||
</script>
|
||||
|
||||
<div class="pm-settings">
|
||||
{#if !compact}
|
||||
<h2>{$t("Project Management")}</h2>
|
||||
<p class="intro">The boards of each workspace stay in .runestone/pm in the workspace.</p>
|
||||
{/if}
|
||||
<div class="card">
|
||||
<div class="setting-row">
|
||||
<div><span class="name" id="pm-priority-label">Priority levels</span><p id="pm-priority-description">Existing card priorities stay unchanged when you change this setting.</p></div>
|
||||
<button class="picker" type="button" aria-label="Priority levels" aria-describedby="pm-priority-description" aria-haspopup="menu"
|
||||
onclick={event => picker(event, "Priority levels", PRIORITY_LEVELS.map(levels => ({ label: levelNames[levels], checked: settings.priorityLevels === levels, run: () => saveLevels(levels) })))}>
|
||||
{levelNames[settings.priorityLevels]}<Icon icon="chevron-down" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div><span class="name" id="pm-default-label">Default board</span><p id="pm-default-description">{boardNote || "Choose the board that opens in this workspace. Restored tabs keep their board."}</p></div>
|
||||
<button class="picker" type="button" aria-label="Default board" aria-describedby="pm-default-description" aria-haspopup="menu" disabled={!boardsReady || saving}
|
||||
onclick={event => picker(event, "Default board", [
|
||||
{ label: "All tasks", checked: !defaultBoard, run: () => void saveDefault("") },
|
||||
...active.map(board => ({ label: board.name, checked: defaultBoard === board.id, run: () => void saveDefault(board.id) })),
|
||||
])}>
|
||||
{boardName}<Icon icon="chevron-down" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{#if error}<p class="error" role="alert">{error}</p>{/if}
|
||||
<p class="saved" role="status">{message}</p>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.pm-settings { min-width: 0; }
|
||||
h2 { margin: 0; font-size: var(--rs-settings-heading-size); font-weight: 600; color: var(--rs-text-strong); }
|
||||
p { margin: 0; color: var(--rs-text-dim); line-height: 1.45; overflow-wrap: anywhere; }
|
||||
.intro { margin: 6px 0 var(--rs-settings-section-gap); }
|
||||
.card { padding: 0 12px; background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
|
||||
.setting-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; padding: var(--rs-settings-row-padding) 0; }
|
||||
.setting-row > div:first-child { flex: 1 1 200px; min-width: 0; }
|
||||
.setting-row + .setting-row { border-top: 1px solid var(--rs-border); }
|
||||
.name { font-weight: 500; color: var(--rs-text); }
|
||||
.setting-row p { margin-top: 3px; font-size: var(--rs-settings-description-size); }
|
||||
.picker { display: inline-flex; align-items: center; justify-content: space-between; gap: var(--rs-settings-gap); min-height: var(--rs-settings-control-height); box-sizing: border-box; max-width: 100%; min-width: 160px; padding: 4px 8px; border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg); color: var(--rs-text); font: inherit; text-align: left; cursor: pointer; }
|
||||
.picker:not(:disabled):hover { background: var(--rs-bg-active); }
|
||||
.picker:disabled { color: var(--rs-text-dim); cursor: default; }
|
||||
.picker :global(svg) { width: 14px; height: 14px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; }
|
||||
.picker:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: 2px; }
|
||||
.saved { font-size: 12px; color: var(--rs-ok); min-height: 20px; margin-top: 10px; }
|
||||
.error { color: var(--rs-error); margin-top: 10px; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user