Make Table Formulas a built-in feature

The formula engine, the rendered results, and the formula help now
come from src/lib/formulas/. The editor and the renderer call this
module directly. The tableFormulas contribution type is removed.

- Add the tableFormulas general setting (default on) and a switch in
  Settings > General. When it is off, formulas show as source text.
- Do not load an installed runestone.table-formulas package. Settings
  > Plug-ins marks it as included with RuneStone and tells the user
  that it can be removed. The user's files stay in place.
- Translate the formula help and the error descriptions into French,
  Japanese, and Simplified Chinese.
- Port the plugin unit tests. Test the setting and use a test-only
  contribution for the generic plugin lifecycle tests.
- Smoke tests load only Terminal. The formula and lifecycle tests use
  the built-in feature and its setting.
- Remove scripts/buildPlugins.mjs, the build:plugins script, and the
  plugin-packages requirement of the smoke runner.
- Remove RuneStone_Table_Formulas from the menu audit scope. It had no
  menu surfaces.
- Update the README, the user guides, and the developer references.
This commit is contained in:
Knotty Wyvern
2026-10-28 01:05:43 -07:00
parent 72671e5d01
commit 5e1533c371
43 changed files with 580 additions and 198 deletions
+25 -17
View File
@@ -2,22 +2,27 @@ import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";
/** Load the actual compiled packages through the production Blob module loader. */
export async function mockFeaturePlugins(surface) {
const packages = await Promise.all(["terminal", "table-formulas"].map(async name => {
const root = name === "terminal"
? (process.env.RUNESTONE_TERMINAL_DIST ? pathToFileURL(resolve(process.env.RUNESTONE_TERMINAL_DIST) + "/") : new URL("../../../../RuneStone_Terminal/dist/", import.meta.url))
: new URL(`../../../plugin-packages/${name}/`, import.meta.url);
return {
manifest: JSON.parse(await readFile(new URL("plugin.json", root), "utf8")),
code: await readFile(new URL("main.js", root), "utf8"),
css: name === "terminal" ? await readFile(new URL("style.css", root), "base64") : "",
};
}));
await surface.addInitScript(packages => {
/** An installed package of the old Table Formulas plugin. RuneStone now includes the feature and must not load this code. */
export const oldTableFormulasRow = {
manifest: { schemaVersion: 1, id: "runestone.table-formulas", name: "Table Formulas", author: "RuneStone Team", description: "Calculate formulas in Markdown tables.", version: "0.1.3", apiVersion: 1, entry: "main.js", access: "full-app" },
hash: "old-hash", enabled: true, path: "C:\\AppData\\RuneStone\\plugins\\runestone.table-formulas", error: null, removal: false,
};
/**
* Load the compiled Terminal package through the production Blob module loader.
* `extraRows` adds installed rows without code, for example `oldTableFormulasRow`.
*/
export async function mockFeaturePlugins(surface, extraRows = []) {
const root = process.env.RUNESTONE_TERMINAL_DIST ? pathToFileURL(resolve(process.env.RUNESTONE_TERMINAL_DIST) + "/") : new URL("../../../../RuneStone_Terminal/dist/", import.meta.url);
const packages = [{
manifest: JSON.parse(await readFile(new URL("plugin.json", root), "utf8")),
code: await readFile(new URL("main.js", root), "utf8"),
css: await readFile(new URL("style.css", root), "base64"),
}];
await surface.addInitScript(({ packages, extraRows }) => {
const key = "test.installed-plugins";
const root = "C:\\AppData\\RuneStone\\plugins";
const defaults = packages.map(item => ({ manifest: item.manifest, hash: "test-hash", enabled: true, path: root + "\\" + item.manifest.id, error: null, removal: false }));
const defaults = [...packages.map(item => ({ manifest: item.manifest, hash: "test-hash", enabled: true, path: root + "\\" + item.manifest.id, error: null, removal: false })), ...extraRows];
const read = () => JSON.parse(localStorage.getItem(key) || JSON.stringify(defaults));
const write = rows => { localStorage.setItem(key, JSON.stringify(rows)); window.__TEST__?.emit("plugins-changed", {}); };
if (!localStorage.getItem(key)) localStorage.setItem(key, JSON.stringify(defaults));
@@ -27,8 +32,11 @@ export async function mockFeaturePlugins(surface) {
if (!command.startsWith("plugins_")) return original(command, args);
window.__TEST__?.calls.push({ command, args });
if (command === "plugins_snapshot") return { root, plugins: read() };
if (command === "plugins_load") return packages.find(item => item.manifest.id === args.id).code;
if (command === "plugins_asset") return packages.find(item => item.manifest.id === args.id).css;
if (command === "plugins_load" || command === "plugins_asset") {
const item = packages.find(item => item.manifest.id === args.id);
if (!item) throw new Error(`No code for ${args.id}`);
return command === "plugins_load" ? item.code : item.css;
}
if (command === "plugins_set_enabled") { write(read().map(item => item.manifest.id === args.id ? { ...item, enabled: args.enabled } : item)); return; }
if (command === "plugins_prepare_remove") return { token: args.id, plugin: read().find(item => item.manifest.id === args.id) };
if (command === "plugins_remove") { write(read().filter(item => item.manifest.id !== args.token)); return; }
@@ -36,5 +44,5 @@ export async function mockFeaturePlugins(surface) {
if (["plugins_release", "plugins_cancel", "plugins_reveal"].includes(command)) return;
throw new Error(`Unhandled plugin IPC: ${command}`);
};
}, packages);
}, { packages, extraRows });
}
+1 -1
View File
@@ -1,5 +1,5 @@
// Custom window controls: maximize, restore, minimize, the terminal close guard, the keyboard tooltip, and the header at 1400 and 880 px.
// @requires plugin:terminal plugin:table-formulas
// @requires plugin:terminal
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import path from "node:path";
+1 -1
View File
@@ -1,5 +1,5 @@
// Core workbench: source edits and history, agent refresh and conflicts, persistent terminals, Reading and Mermaid previews, the live Writer, tables and their menus, and narrow layouts.
// @requires plugin:terminal plugin:table-formulas
// @requires plugin:terminal
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import path from "node:path";
+2 -1
View File
@@ -89,7 +89,8 @@ await runSmoke("links/linkEditing", async ({ page }) => {
await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({theme:'default',mode}),mode);
await page.locator('.writer-table td').nth(1).hover();
await page.locator('.rs-tooltip:popover-open').waitFor();
assert.match(await page.locator('.rs-tooltip:popover-open').innerText(),/Row 2, column 2/);
// Table formulas are on by default, so the cell tooltip shows the cell address.
assert.equal(await page.locator('.rs-tooltip:popover-open').innerText(),'B2');
await page.screenshot({path:path.join(output, 'editor-cell-tooltip-narrow-'+mode+'.png')});
await page.keyboard.press('Escape');
await page.mouse.move(5,90);
+25 -16
View File
@@ -1,9 +1,10 @@
// Feature plug-in lifecycle: Table formulas and Terminal turn off, persist, reopen across windows, and uninstall without restoration.
// @requires plugin:terminal plugin:table-formulas
// Feature lifecycle: the built-in Table formulas setting and the Terminal plug-in turn off, persist, reopen across windows, and uninstall without restoration.
// An old Table Formulas package stays inactive and shows that the feature is built in.
// @requires plugin:terminal
import assert from 'node:assert/strict';
import path from 'node:path';
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
import { mockFeaturePlugins } from '../_harness/pluginMocks.mjs';
import { mockFeaturePlugins, oldTableFormulasRow } from '../_harness/pluginMocks.mjs';
await runSmoke('plugins/lifecycle', async ({ browser }) => {
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
@@ -44,7 +45,7 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
};
},
});
await mockFeaturePlugins(context);
await mockFeaturePlugins(context, [oldTableFormulasRow]);
const output = await outputDir('plugins/lifecycle');
const source = '# Formulas\n\n| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n\nAfter.\n';
const table = page.locator('.live-writer table');
@@ -58,13 +59,15 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
await page.getByRole('dialog').getByRole('button').filter({ hasText: name }).first().click();
await page.locator('.live-writer').waitFor();
}
async function settings() {
async function settings(category = 'Plug-ins') {
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
await settingsPage.goto(smokeUrl + '/?settingsWindow=true');
await dialog.getByRole('button', { name: 'Plug-ins', exact: true }).click();
await dialog.getByRole('button', { name: category, exact: true }).click();
}
// The switch of an old package of a built-in feature stays disabled.
const idle = () => settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled || input.id === 'external-runestone.table-formulas'));
async function closeSettings() {
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
await idle();
await settingsPage.goto(smokeUrl + '/__settings-closed');
await page.bringToFront();
}
@@ -76,28 +79,30 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
await quickOpen('formulas.md');
await table.waitFor();
assert.equal(await table.locator('.md-table-formula').innerText(), '6');
await settings();
assert(!await page.evaluate(() => window.__TEST__.calls.some(call => call.command === 'plugins_load' && call.args.id === 'runestone.table-formulas')), 'The old Table Formulas package does not load');
await settings('General');
await switchFor('Table formulas').uncheck();
await closeSettings();
await page.waitForFunction(() => !document.querySelector('.md-table-formula'));
assert.equal(await page.evaluate(() => window.__TEST__.settings('general').tableFormulas), false, 'The settings file stores the choice');
assert.match(await table.innerText(), /=A2\*3/);
assert.equal(await page.locator('.table-formula-tools').count(), 0);
await table.locator('td').last().click();
await page.locator('.writer-cell-editor').fill('=A2*4');
await page.keyboard.press('Enter');
await settings();
await settings('General');
await switchFor('Table formulas').check();
await closeSettings();
await page.waitForFunction(() => document.querySelector('.md-table-formula')?.textContent === '8');
await page.getByRole('group', { name: 'Document view', exact: true }).getByRole('button', { pressed: true }).press('ArrowRight');
const preview = page.locator('.md-page table').first();
await preview.locator('.md-table-formula').waitFor();
await settings();
await settings('General');
await switchFor('Table formulas').uncheck();
await closeSettings();
await page.waitForFunction(() => !document.querySelector('.md-page .md-table-formula'));
assert.match(await preview.innerText(), /=A2\*4/);
await settings();
await settings('General');
await switchFor('Table formulas').check();
await closeSettings();
await preview.locator('.md-table-formula').waitFor();
@@ -109,6 +114,10 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
await page.getByRole('button', { name: 'Terminal', exact: true }).click();
await page.waitForFunction(ptyCalled, 'pty_open');
await settings();
const oldPackage = dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name: 'Table Formulas', exact: true }) });
await oldPackage.getByText('Included with RuneStone', { exact: true }).waitFor();
await oldPackage.getByText(/Table Formulas is now built in\. You can remove this old package\./).waitFor();
assert(await oldPackage.getByRole('switch').isDisabled(), 'The old package cannot be enabled');
await switchFor('Terminal').uncheck();
await page.waitForFunction(ptyCalled, 'pty_close');
await settingsPage.screenshot({ path: path.join(output, 'plugins-settings.png') });
@@ -143,8 +152,8 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
await quickOpen('formulas.md');
await settings();
assert.equal(await dialog.getByRole('heading', { name: 'Bundled plugins' }).count(), 0);
for (const name of ['Terminal', 'Table formulas']) {
await settingsPage.waitForFunction(() => [...document.querySelectorAll('input[role="switch"]')].every(input => !input.disabled));
for (const name of ['Terminal', 'Table Formulas']) {
await idle();
await dialog.locator('.card').filter({ has: settingsPage.getByRole('switch', { name, exact: true }) }).getByRole('button', { name: 'Uninstall', exact: true }).click();
const confirmation = settingsPage.getByRole('dialog', { name: `Uninstall ${name}?`, exact: true });
await confirmation.getByRole('button', { name: 'Uninstall and delete files', exact: true }).click();
@@ -152,9 +161,9 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
await switchFor(name).waitFor({ state: 'detached' });
}
await closeSettings();
await page.waitForFunction(() => !document.querySelector('.md-table-formula') && !document.querySelector('.xterm'));
await page.waitForFunction(() => !document.querySelector('.xterm'));
assert.equal(await page.getByRole('button', { name: 'Terminal', exact: true }).count(), 0);
assert.match(await table.innerText(), /=A2\*4/);
assert.equal(await table.locator('.md-table-formula').innerText(), '8', 'Removing the old package keeps the built-in formulas');
await page.reload();
await page.getByText('smoke-workspace', { exact: true }).waitFor();
await settings();
@@ -168,5 +177,5 @@ await runSmoke('plugins/lifecycle', async ({ browser }) => {
console.log([...page.errors, ...settingsPage.errors]);
throw error;
}
console.log('Plugin smoke passed: formulas, source preservation, terminal shutdown, persistence, shortcuts, cross-window enable controls, removal, and no automatic restoration.');
console.log('Plugin smoke passed: formula setting, source preservation, inactive old package, terminal shutdown, persistence, shortcuts, cross-window enable controls, removal, and no automatic restoration.');
});
+22 -4
View File
@@ -1,9 +1,8 @@
// Table formulas: live recalculation, raw formula editing, Enter and Tab, undo, cycles, saving, the footer layout, and the Read and Split views.
// @requires plugin:terminal plugin:table-formulas
// Built-in table formulas: live recalculation, raw formula editing, Enter and Tab, undo, cycles, saving, the footer layout, the Read and Split views,
// and the general setting that turns formulas off and on.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
const source = '# Table formulas\n\n| Name | Appearance | Charisma | Combined |\n| --- | ---: | ---: | ---: |\n| First | 9 | 10 | =AVERAGE(B2:C2) |\n| Second | 7 | 9 | =SUM(B3+C3)/2 |\n| Total | | | =SUM(D2:D3) |\n\nAfter.\n';
@@ -17,7 +16,6 @@ await runSmoke("tables/formulas", async ({ page }) => {
return workspace;
},
});
await mockFeaturePlugins(page);
async function quickOpen(name) {
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
@@ -137,4 +135,24 @@ await runSmoke("tables/formulas", async ({ page }) => {
const total = preview.locator('tbody tr').filter({ hasText: 'Total' });
assert.equal(await total.locator('.md-table-formula').last().innerText(), '58', `${mode} view`);
}
// The general setting turns formulas off in all views. The source text shows and the file stays the same.
const file = await page.evaluate(() => window.__TEST__.files.get('formulas.md'));
const general = await page.evaluate(() => window.__TEST__.settings('general') ?? {});
await page.evaluate(value => window.__TEST__.writeSettings('general', value), { ...general, tableFormulas: false });
await page.waitForFunction(() => !document.querySelector('.md-table-formula'));
const total = page.locator('.md-page table').first().locator('tbody tr').filter({ hasText: 'Total' });
assert.match(await total.innerText(), /=SUM\(D2:D3\)/);
assert.match(await total.innerText(), /=SUM\(B2:B3\)/);
await shot('formulas-off-split');
await page.getByRole('group', { name: 'Document view', exact: true }).getByRole('button', { name: 'Edit', exact: true }).click();
await table.waitFor();
assert.equal(await table.locator('.md-table-formula').count(), 0);
assert.match(await cell(3, 3).innerText(), /=SUM\(D2:D3\)/);
assert.equal(await page.locator('.table-formula-tools').count(), 0, 'Writer shows no formula help');
await shot('formulas-off-writer');
await page.evaluate(value => window.__TEST__.writeSettings('general', value), { ...general, tableFormulas: true });
await result(3, 3).waitFor();
assert.equal(await result(3, 3).innerText(), '58');
await page.locator('.table-formula-tools').first().waitFor();
assert.equal(await page.evaluate(() => window.__TEST__.files.get('formulas.md')), file);
});
+4 -4
View File
@@ -62,7 +62,7 @@ await runSmoke("tables/linkCaret", async ({ page }) => {
await page.getByRole('button', { name:'Files', exact:true }).click();
await page.getByRole('button', { name:'Hide outline', exact:true }).click();
}
const cell = page.getByRole('cell', { name:'Row 6, column 2', exact:true });
const cell = page.getByRole('cell', { name:'B6 · Row 6, column 2', exact:true });
await clickTextAt(cell.locator('a'), 5);
await sourceCell().waitFor();
assert.equal(await cell.locator('.writer-link-target').innerText(), 'docs/roadmap.md', 'Ordinary click reveals the URL');
@@ -89,7 +89,7 @@ await runSmoke("tables/linkCaret", async ({ page }) => {
await page.keyboard.press('Control+s');
assert.match(await page.evaluate(() => window.__TEST__.files.get('a.md')), /\[Roadmap\]\(docs\/changed.md\)/);
const keyboard = page.getByRole('cell', { name:'Row 7, column 2', exact:true });
const keyboard = page.getByRole('cell', { name:'B7 · Row 7, column 2', exact:true });
await clickTextAt(keyboard, 7);
assert.equal(await sourceCell().count(), 0, 'Plain cell text remains rendered');
await page.keyboard.press('ArrowRight');
@@ -99,7 +99,7 @@ await runSmoke("tables/linkCaret", async ({ page }) => {
await shot(`keyboard-${theme}-${width}`);
await page.keyboard.press('Escape');
const wiki = page.getByRole('cell', { name:'Row 8, column 2', exact:true });
const wiki = page.getByRole('cell', { name:'B8 · Row 8, column 2', exact:true });
await clickTextAt(wiki.locator('a'), 3);
await sourceCell().waitFor();
assert.equal(await caretPrefix(), '[[guide\\|Gui');
@@ -110,7 +110,7 @@ await runSmoke("tables/linkCaret", async ({ page }) => {
await page.keyboard.press('Enter');
assert.equal(await wiki.locator('a').getAttribute('href'), 'new-guide');
const repeated = page.getByRole('cell', { name:'Row 9, column 2', exact:true });
const repeated = page.getByRole('cell', { name:'B9 · Row 9, column 2', exact:true });
await clickTextAt(repeated.locator('a').nth(1), 4);
await sourceCell().waitFor();
assert.equal(await caretPrefix(), '**Prefix** [One](same.md) + [Sec**o');
+1 -1
View File
@@ -1,5 +1,5 @@
// Table keyboard navigation: arrows, caret positions, entry and exit in all directions, goal columns, line breaks, stable cell sizes, saving, and undo.
// @requires plugin:terminal plugin:table-formulas
// @requires plugin:terminal
import assert from "node:assert/strict";
import { mockTauri, runSmoke, settle, smokeUrl } from "../_harness/index.mjs";
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";