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
+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);
});