Files
RuneStone/src/lib/formulas/index.ts
T
Knotty Wyvern 5e1533c371 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.
2026-10-28 01:05:43 -07:00

37 lines
1.9 KiB
TypeScript

// Table formulas are a built-in feature. The `tableFormulas` general setting turns them on or off.
// When they are off, the editor and the renderer show formulas as their source text.
import { get, writable } from "svelte/store";
import { onSettingsChange } from "../settings/store.ts";
import { DEFAULT_SETTINGS, readSettings } from "../workspace/settings.ts";
import { cellAddress, evaluateTableFormulas, formulaErrors, isTableFormula } from "./engine.ts";
import { formulaErrorText, renderTableFormulas, tableFormulaHtml } from "./render.ts";
import { createFormulaTools } from "./tools.ts";
export { cellAddress, evaluateTableFormulas, formulaErrors, isTableFormula, type FormulaErrorCode, type FormulaResult } from "./engine.ts";
export { formulaErrorText, renderTableFormulas, tableFormulaHtml } from "./render.ts";
export { createFormulaTools } from "./tools.ts";
export const tableFormulas = { formulaErrors, formulaErrorText, isTableFormula, cellAddress, evaluateTableFormulas, tableFormulaHtml, renderTableFormulas, createFormulaTools };
export type TableFormulas = typeof tableFormulas;
const enabled = writable(DEFAULT_SETTINGS.tableFormulas);
/** A store with the current state of the setting. Views subscribe to it to render again after a change. */
export const tableFormulasEnabled = { subscribe: enabled.subscribe };
export function setTableFormulasEnabled(value: boolean) { enabled.set(value); }
/** The formula functions when the setting is on, otherwise undefined. */
export function activeTableFormulas(): TableFormulas | undefined {
return get(enabled) ? tableFormulas : undefined;
}
/** Apply the saved setting now and after each change in any window. Returns a function that stops it. */
export function syncTableFormulas() {
const read = () => {
try { setTableFormulasEnabled(readSettings().tableFormulas); }
catch { setTableFormulasEnabled(DEFAULT_SETTINGS.tableFormulas); }
};
read();
return onSettingsChange("general", read);
}