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:
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { pluginHost } from "$lib/plugins/registry";
|
||||
import { tableFormulasEnabled } from "$lib/formulas";
|
||||
import { isSpellingTarget } from "./spellingMenu";
|
||||
import { untrack } from "svelte";
|
||||
import { Compartment, EditorState, EditorSelection, Transaction } from "@codemirror/state";
|
||||
@@ -369,7 +369,7 @@
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
void $pluginHost;
|
||||
void $tableFormulasEnabled;
|
||||
editor?.dispatch({ effects: refreshImages.of() });
|
||||
});
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { actionIcon } from "../ui/actionIcons";
|
||||
import { attachTooltip } from "../ui/tooltip";
|
||||
import { documentLinks } from "./documentLinks";
|
||||
|
||||
import { pluginHost } from "../plugins/registry.ts";
|
||||
import { activeTableFormulas } from "../formulas/index.ts";
|
||||
|
||||
const previewFormulas = new WeakMap<HTMLElement, unknown>();
|
||||
export const refreshImages = StateEffect.define<void>();
|
||||
@@ -103,7 +103,7 @@ class Checkbox extends WidgetType {
|
||||
}
|
||||
|
||||
class Preview extends WidgetType {
|
||||
readonly formulas = pluginHost.get("tableFormulas");
|
||||
readonly formulas = activeTableFormulas();
|
||||
constructor(readonly html: string, readonly source: string, readonly actions: TableContextActions, readonly sourceVisible = false, readonly height = { value: -1 }) { super(); }
|
||||
get estimatedHeight() { return this.height.value; }
|
||||
eq(other: Preview) { return other.formulas === this.formulas && other.html === this.html && other.source === this.source && other.sourceVisible === this.sourceVisible; }
|
||||
|
||||
@@ -15,7 +15,7 @@ import { tableSelectionControls } from "./tableSelectionControls";
|
||||
import { tableDragControls } from "./tableDragControls";
|
||||
import type { TableContextActions } from "./tableCellActions";
|
||||
import { actionIcon } from "../ui/actionIcons";
|
||||
import { pluginHost } from "../plugins/registry.ts";
|
||||
import { activeTableFormulas } from "../formulas/index.ts";
|
||||
import { attachTooltip } from "../ui/tooltip";
|
||||
import { documentLinks } from "./documentLinks";
|
||||
import { tableLinkLabelPosition } from "./tableLinkSource";
|
||||
@@ -43,7 +43,7 @@ const CellImage = Image.extend({
|
||||
export const tableEditors = new WeakMap<HTMLElement, { source: string; enter: (forward: boolean, x?: number) => void; destroy: () => void }>();
|
||||
|
||||
export function tableControls(root: HTMLElement, view: EditorView, initialSource: string, actions: TableContextActions = {}) {
|
||||
const formulas = pluginHost.get("tableFormulas");
|
||||
const formulas = activeTableFormulas();
|
||||
const scroll = root.querySelector<HTMLElement>(".md-table-scroll");
|
||||
const table = scroll?.querySelector("table");
|
||||
if (!scroll || !table || !parseMarkdownTable(initialSource)) return;
|
||||
@@ -98,7 +98,7 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
|
||||
if (result && cell !== active) cell.innerHTML = formulas.tableFormulaHtml(result);
|
||||
if (cell === active) {
|
||||
formulaStatus.textContent = `${address}${result ? ` = ${result.text}` : tr(" · Type = to calculate")}`;
|
||||
formulaHint.textContent = result?.error ? formulas.formulaErrors[result.error] : "";
|
||||
formulaHint.textContent = result?.error ? formulas.formulaErrorText(result.error) : "";
|
||||
formulaHint.hidden = !formulaHint.textContent;
|
||||
}
|
||||
}
|
||||
@@ -176,7 +176,7 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
|
||||
let contentFrom = originalCell?.from, contentTo = originalCell?.to;
|
||||
const formula = originalCell && (/^=(?!=)/.test(originalCell.text.trim()) || /^\\=(?!=)/.test(originalCell.text)) ? originalCell.text : undefined;
|
||||
const html = cell.innerHTML;
|
||||
formulaStatus.textContent = formulas ? `${formulas.cellAddress(row, column)} · Type = to calculate` : "";
|
||||
formulaStatus.textContent = formulas ? `${formulas.cellAddress(row, column)}${tr(" · Type = to calculate")}` : "";
|
||||
cell.innerHTML = "";
|
||||
cell.classList.add("is-editing");
|
||||
editor = new Editor({
|
||||
|
||||
Reference in New Issue
Block a user