Skip to content

Commit

Permalink
fix: update math cell config logic to work with svelte 5
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreminger committed Dec 13, 2024
1 parent 46800ec commit b8df999
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
9 changes: 4 additions & 5 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
mathCellChanged, nonMathCellChanged, addCell, prefersReducedMotion, modifierKey,
inCellInsertMode, config, unsavedChange, incrementActiveCell,
decrementActiveCell, deleteCell, activeMathField, autosaveNeeded, mathJaxLoaded } from "./stores";
import { isDefaultConfig, type Config, normalizeConfig } from "./sheet/Sheet";
import { isDefaultConfig, type Config, normalizeConfig, type MathCellConfig, type Sheet, getDefaultConfig} from "./sheet/Sheet";
import type { Statement, SubQueryStatement } from "./parser/types";
import type { SystemDefinition } from "./cells/SystemCell";
import type { FluidFunction } from "./cells/FluidCell";
Expand All @@ -23,7 +23,6 @@
import type { Results } from "./resultTypes";
import { getHash, API_GET_PATH, API_SAVE_PATH } from "./database/utility";
import type { SheetPostBody, History } from "./database/types";
import { type Sheet, getDefaultConfig } from "./sheet/Sheet";
import CellList from "./CellList.svelte";
import type { MathField } from "./cells/MathField";
import DocumentTitle from "./DocumentTitle.svelte";
Expand Down Expand Up @@ -1553,7 +1552,7 @@ Please include a link to this sheet in the email to assist in debugging the prob
state: "sheetSettings",
heading: "Math Cell Number Format Settings",
mathCell: e.detail.mathCell as MathCell,
mathCellElement: e.detail.target as MathCellElement
setCellNumberConfig: e.detail.setNumberConfig as (input: MathCellConfig) => void
};
}
Expand Down Expand Up @@ -2044,7 +2043,7 @@ Please include a link to this sheet in the email to assist in debugging the prob
state: "sheetSettings",
heading: "Sheet Settings",
mathCell: null,
mathCellElement: null
setCellNumberConfig: null
};
}
Expand Down Expand Up @@ -2821,7 +2820,7 @@ Please include a link to this sheet in the email to assist in debugging the prob
<MathCellConfigDialog
bind:this={mathCellConfigDialog}
mathCellConfig={modalInfo.mathCell.config}
mathCellElement={modalInfo.mathCellElement}
setCellNumberConfig={modalInfo.setCellNumberConfig}
cellLevelConfig={true}
/>
{:else}
Expand Down
7 changes: 2 additions & 5 deletions src/MathCell.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { onMount, createEventDispatcher, SvelteComponent } from "svelte";
import { get_current_component } from "svelte/internal";
import { bignumber, format, unaryMinus, type BigNumber, type FormatOptions } from "mathjs";
import { cells, results, sub_results, resultsInvalid, activeCell, mathCellChanged, config } from "./stores";
import { isFiniteImagResult, type Result, type FiniteImagResult,
Expand Down Expand Up @@ -51,14 +50,12 @@
}
const dispatch = createEventDispatcher<{
updateNumberFormat: {mathCell: MathCell, target: SvelteComponent};
updateNumberFormat: {mathCell: MathCell, setNumberConfig: (input: MathCellConfig) => void};
generateCode: {index: number};
insertMathCellAfter: {index: number};
insertInsertCellAfter: {index: number};
}>();
const self = get_current_component();
export function setNumberConfig(mathCellConfig: MathCellConfig) {
mathCell.config = mathCellConfig;
}
Expand All @@ -68,7 +65,7 @@
}
function handleUpdateNumberFormat() {
dispatch("updateNumberFormat", { mathCell: mathCell, target: self });
dispatch("updateNumberFormat", { mathCell: mathCell, setNumberConfig: setNumberConfig });
}
function handleGenerateCode() {
Expand Down
7 changes: 3 additions & 4 deletions src/MathCellConfigDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import { defaultConfig, copyMathConfig, isDefaultMathConfig,
type MathCellConfig, getSafeMathConfig, mathConfigLimits } from "./sheet/Sheet";
import { unsavedChange, autosaveNeeded, mathCellChanged } from "./stores";
import type MathCellElement from "./MathCell.svelte";
export let mathCellConfig: MathCellConfig | null;
export let cellLevelConfig = false;
export let mathCellElement: MathCellElement | null = null;
export let setCellNumberConfig: (input: MathCellConfig) => void | null = null;
let defaultMathConfig = defaultConfig.mathCellConfig;
let currentMathCellConfig = copyMathConfig(mathCellConfig) ?? copyMathConfig(defaultMathConfig);
Expand All @@ -34,8 +33,8 @@
mathCellConfig = newConfig;
if (cellLevelConfig && mathCellElement) {
mathCellElement.setNumberConfig(mathCellConfig);
if (cellLevelConfig && setCellNumberConfig) {
setCellNumberConfig(mathCellConfig);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type MathCell from "./cells/MathCell";
import type MathCellElement from "./MathCell.svelte";
import type { SystemDefinition } from "./cells/SystemCell";
import type { FluidFunction } from "./cells/FluidCell";
import type { Statement, SubQueryStatement } from "./parser/types";
import type { MathField } from "./cells/MathField";
import type { CustomBaseUnits } from "./sheet/Sheet";
import type { CustomBaseUnits, MathCellConfig } from "./sheet/Sheet";
import type { InterpolationFunction } from "./cells/DataTableCell";

export type ModalInfo = {
Expand All @@ -19,7 +18,7 @@ export type ModalInfo = {
error?: string;
insertionLocation?: number;
mathCell?: MathCell;
mathCellElement?: MathCellElement;
setCellNumberConfig?: (input: MathCellConfig) => void;
codeGenerationIndex?: number;
targetMathField?: MathField;
}
Expand Down

0 comments on commit b8df999

Please sign in to comment.