Files
RuneStone/src/lib/features/pm/ui/host.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

57 lines
2.4 KiB
TypeScript

// The host layer of the Project Management interface: the shared action menu, the shared tooltip, and the shared action
// icons of RuneStone. The interface builds plain DOM. A Svelte version is a later card.
import { showActionMenu, type MenuOptions } from "../../../ui/managedActionMenu.ts";
import { attachTooltip } from "../../../ui/tooltip.ts";
export { actionIcons, type ActionIcon } from "../../../ui/actionIcons.ts";
export type { ActionMenuItem } from "../../../ui/actionMenu.ts";
/** The menus that the interface opens. Tests can give their own. */
export interface MenuHost {
showActionMenu(options: MenuOptions): { close(): void };
}
export const hostMenus: MenuHost = { showActionMenu: options => showActionMenu(options) };
/** The attribute that gives a control its tooltip text. */
export const TOOLTIP = "data-pm-tooltip";
/** Give a control the shared tooltip. The text can change later through the attribute. */
export function tooltip<T extends HTMLElement>(control: T, text: string): T {
control.setAttribute(TOOLTIP, text);
return control;
}
/**
* Attach the shared tooltip to each control in `root` with `data-pm-tooltip`, also to controls that a render adds later.
* A removed control loses its tooltip. Returns the function that removes all tooltips.
*/
export function mountTooltips(root: HTMLElement): () => void {
const attached = new Map<HTMLElement, () => void>();
const attach = (node: Node) => {
if (!(node instanceof HTMLElement)) return;
const controls = node.matches(`[${TOOLTIP}]`) ? [node, ...node.querySelectorAll<HTMLElement>(`[${TOOLTIP}]`)] : node.querySelectorAll<HTMLElement>(`[${TOOLTIP}]`);
for (const control of controls) {
if (attached.has(control)) continue;
attached.set(control, attachTooltip(control, () => control.getAttribute(TOOLTIP) ?? ""));
}
};
const sweep = () => {
for (const [control, detach] of attached) {
if (control.isConnected && root.contains(control)) continue;
detach();
attached.delete(control);
}
};
const observer = new MutationObserver(records => {
sweep();
for (const record of records) for (const node of record.addedNodes) attach(node);
});
observer.observe(root, { childList: true, subtree: true });
attach(root);
return () => {
observer.disconnect();
for (const detach of attached.values()) detach();
attached.clear();
};
}