From 7af4efe26dd135a948a555fc26a52b1d8c20f0be Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sat, 16 Nov 2024 14:52:08 -0600 Subject: [PATCH 1/8] refactor: split out config normalization code Will allow the same logic to be used for loading config from a sheet and loading config from indexDB --- src/App.svelte | 14 +++++--------- src/sheet/Sheet.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 9224189b..28a877b3 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -15,7 +15,8 @@ inCellInsertMode, config, unsavedChange, incrementActiveCell, decrementActiveCell, deleteCell, activeMathField, autosaveNeeded, mathJaxLoaded } from "./stores"; - import { getDefaultBaseUnits, getDefaultFluidConfig, isDefaultConfig } from "./sheet/Sheet"; + import { getDefaultBaseUnits, getDefaultFluidConfig, isDefaultConfig, + normalizeConfig } from "./sheet/Sheet"; import type { Statement, SubQueryStatement } from "./parser/types"; import type { SystemDefinition } from "./cells/SystemCell"; import type { FluidFunction } from "./cells/FluidCell"; @@ -1216,15 +1217,10 @@ Please include a link to this sheet in the email to assist in debugging the prob $title = sheet.title; BaseCell.nextId = sheet.nextId; $sheetId = sheet.sheetId; - // old documents in database will not have the insertedSheets property or a config property + // old documents in database will not have the insertedSheets property $insertedSheets = sheet.insertedSheets ?? []; - $config = sheet.config ?? getDefaultConfig(); - $config.customBaseUnits = $config.customBaseUnits ?? getDefaultBaseUnits(); // customBaseUnits may not exist - $config.simplifySymbolicExpressions = $config.simplifySymbolicExpressions ?? true; // simplifySymboicExpressions may not exist - $config.convertFloatsToFractions = $config.convertFloatsToFractions ?? true; // convertFloatsToFractions may not exist - $config.fluidConfig = $config.fluidConfig ?? getDefaultFluidConfig(); // fluidConfig may not exist - $config.mathCellConfig.showIntermediateResults = $config.mathCellConfig.showIntermediateResults ?? false; // may not exist - + $config = normalizeConfig(sheet.config); + $cells = await Promise.all(sheet.cells.map((value) => cellFactory(value, $config))); if (!$history.map(item => item.hash !== "file" ? getSheetHash(new URL(item.url)) : "").includes(getSheetHash(window.location))) { diff --git a/src/sheet/Sheet.ts b/src/sheet/Sheet.ts index 261e19f3..97189f28 100644 --- a/src/sheet/Sheet.ts +++ b/src/sheet/Sheet.ts @@ -302,4 +302,16 @@ export function getDefaultBaseUnits(system: BaseUnitSystemNames = "SI"): CustomB export function isDefaultBaseUnits(baseUnits: CustomBaseUnits, system: BaseUnitSystemNames = "SI"): boolean { const defaultBaseUnits = baseUnitSystems.get(system); return Object.entries(defaultBaseUnits).reduce((acum, [key, value]) => acum && value === baseUnits[key], true); +} + +export function normalizeConfig(inputConfig: Config | undefined): Config { + const outputConfig = inputConfig ?? getDefaultConfig(); + + outputConfig.customBaseUnits = outputConfig.customBaseUnits ?? getDefaultBaseUnits(); // customBaseUnits may not exist + outputConfig.simplifySymbolicExpressions = outputConfig.simplifySymbolicExpressions ?? true; // simplifySymboicExpressions may not exist + outputConfig.convertFloatsToFractions = outputConfig.convertFloatsToFractions ?? true; // convertFloatsToFractions may not exist + outputConfig.fluidConfig = outputConfig.fluidConfig ?? getDefaultFluidConfig(); // fluidConfig may not exist + outputConfig.mathCellConfig.showIntermediateResults = outputConfig.mathCellConfig.showIntermediateResults ?? false; // may not exist + + return outputConfig; } \ No newline at end of file From bfc8bd6cb83adf6be98aec32d29ce6557691e1ab Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sat, 16 Nov 2024 22:01:31 -0600 Subject: [PATCH 2/8] feat: implement option to save a user default config Need to add tests and a button to apply user config to current sheet --- src/App.svelte | 21 +++++++++++-- src/MathCellConfigDialog.svelte | 3 +- src/SetDefaultConfigDialog.svelte | 38 +++++++++++++++++++++++ src/sheet/Sheet.ts | 50 +++++++++++++++++++++---------- src/stores.ts | 3 +- 5 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 src/SetDefaultConfigDialog.svelte diff --git a/src/App.svelte b/src/App.svelte index 28a877b3..24b8ade0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -13,10 +13,10 @@ history, insertedSheets, activeCell, getSheetJson, getSheetObject, resetSheet, sheetId, mathCellChanged, nonMathCellChanged, addCell, prefersReducedMotion, modifierKey, inCellInsertMode, config, unsavedChange, incrementActiveCell, - decrementActiveCell, deleteCell, activeMathField, autosaveNeeded, mathJaxLoaded + decrementActiveCell, deleteCell, activeMathField, autosaveNeeded, mathJaxLoaded, + userDefaultConfig } from "./stores"; - import { getDefaultBaseUnits, getDefaultFluidConfig, isDefaultConfig, - normalizeConfig } from "./sheet/Sheet"; + import { isDefaultConfig, type Config, normalizeConfig } from "./sheet/Sheet"; import type { Statement, SubQueryStatement } from "./parser/types"; import type { SystemDefinition } from "./cells/SystemCell"; import type { FluidFunction } from "./cells/FluidCell"; @@ -92,6 +92,7 @@ import BaseUnitsConfigDialog from "./BaseUnitsConfigDialog.svelte"; import DownloadDocumentModal from "./DownloadDocumentModal.svelte"; import { getBlankStatement } from "./parser/LatexToSympy"; + import SetDefaultConfigDialog from "./SetDefaultConfigDialog.svelte"; createCustomUnits(); @@ -357,6 +358,16 @@ $prefersReducedMotion = mediaQueryList.matches mediaQueryList.addEventListener('change', handleMotionPreferenceChange); + let tempUserDefaultConfig: Config | undefined = undefined; + try { + tempUserDefaultConfig = await get('defaultConfig'); + } catch(e) { + console.log('Error retrieving user default config'); + tempUserDefaultConfig = undefined; + } + + $userDefaultConfig = tempUserDefaultConfig ?? getDefaultConfig(); + $unsavedChange = false; $autosaveNeeded = false; await refreshSheet(true); @@ -2821,6 +2832,7 @@ Please include a link to this sheet in the email to assist in debugging the prob + + + + {/if} diff --git a/src/MathCellConfigDialog.svelte b/src/MathCellConfigDialog.svelte index 9ef86eee..47705e05 100644 --- a/src/MathCellConfigDialog.svelte +++ b/src/MathCellConfigDialog.svelte @@ -1,7 +1,7 @@ + + + + \ No newline at end of file diff --git a/src/sheet/Sheet.ts b/src/sheet/Sheet.ts index 97189f28..7f105a53 100644 --- a/src/sheet/Sheet.ts +++ b/src/sheet/Sheet.ts @@ -80,8 +80,6 @@ function getDefaultMathCellConfig(): MathCellConfig { }; } -export const defaultMathConfig = getDefaultMathCellConfig(); - export const mathConfigLimits = { precisionUpper: 64, lowerExpLower: -12, @@ -91,21 +89,29 @@ export const mathConfigLimits = { }; export function isDefaultMathConfig(config: MathCellConfig): boolean { + return mathConfigsEqual(config, defaultConfig.mathCellConfig); +} + +export function mathConfigsEqual(config1: MathCellConfig, config2: MathCellConfig): boolean { return ( - config.symbolicOutput === defaultMathConfig.symbolicOutput && - config.showIntermediateResults === defaultMathConfig.showIntermediateResults && - config.formatOptions.notation === defaultMathConfig.formatOptions.notation && - config.formatOptions.precision === defaultMathConfig.formatOptions.precision && - config.formatOptions.lowerExp === defaultMathConfig.formatOptions.lowerExp && - config.formatOptions.upperExp === defaultMathConfig.formatOptions.upperExp + config1.symbolicOutput === config2.symbolicOutput && + config1.showIntermediateResults === config2.showIntermediateResults && + config1.formatOptions.notation === config2.formatOptions.notation && + config1.formatOptions.precision === config2.formatOptions.precision && + config1.formatOptions.lowerExp === config2.formatOptions.lowerExp && + config1.formatOptions.upperExp === config2.formatOptions.upperExp ) -} +} export function isDefaultConfig(config: Config): boolean { - return isDefaultMathConfig(config.mathCellConfig) && - isDefaultBaseUnits(config.customBaseUnits) && - config.simplifySymbolicExpressions === true && - config.convertFloatsToFractions === true; + return configsEqual(config, defaultConfig); +} + +export function configsEqual(config1: Config, config2: Config): boolean { + return mathConfigsEqual(config1.mathCellConfig, config2.mathCellConfig) && + baseUnitsEqual(config1.customBaseUnits, config2.customBaseUnits) && + config1.simplifySymbolicExpressions === config2.simplifySymbolicExpressions && + config1.convertFloatsToFractions === config2.convertFloatsToFractions; } export function copyMathConfig(input: MathCellConfig): MathCellConfig { @@ -125,7 +131,7 @@ export function getSafeMathConfig(config: MathCellConfig): MathCellConfig { // clamp precision if (config.formatOptions.precision === null) { - safeConfig.formatOptions.precision = defaultMathConfig.formatOptions.precision; + safeConfig.formatOptions.precision = defaultConfig.mathCellConfig.formatOptions.precision; } else if(config.formatOptions.precision > mathConfigLimits.precisionUpper) { safeConfig.formatOptions.precision = mathConfigLimits.precisionUpper; } else if(config.formatOptions.precision < (config.formatOptions.notation === "fixed" ? 0 : 1)) { @@ -134,7 +140,7 @@ export function getSafeMathConfig(config: MathCellConfig): MathCellConfig { // clamp lowerExp if (config.formatOptions.lowerExp === null) { - safeConfig.formatOptions.lowerExp = defaultMathConfig.formatOptions.lowerExp; + safeConfig.formatOptions.lowerExp = defaultConfig.mathCellConfig.formatOptions.lowerExp; } else if(config.formatOptions.lowerExp > mathConfigLimits.lowerExpUpper) { safeConfig.formatOptions.lowerExp = mathConfigLimits.lowerExpUpper; } else if(config.formatOptions.lowerExp < mathConfigLimits.lowerExpLower) { @@ -143,7 +149,7 @@ export function getSafeMathConfig(config: MathCellConfig): MathCellConfig { // clamp upperExp if (config.formatOptions.upperExp === null) { - safeConfig.formatOptions.upperExp = defaultMathConfig.formatOptions.upperExp; + safeConfig.formatOptions.upperExp = defaultConfig.mathCellConfig.formatOptions.upperExp; } else if(config.formatOptions.upperExp > mathConfigLimits.upperExpUpper) { safeConfig.formatOptions.upperExp = mathConfigLimits.upperExpUpper; } else if(config.formatOptions.upperExp < mathConfigLimits.upperExpLower) { @@ -295,6 +301,8 @@ export const baseUnitSystems = new Map([ ], ]); +export const defaultConfig = getDefaultConfig(); + export function getDefaultBaseUnits(system: BaseUnitSystemNames = "SI"): CustomBaseUnits { return {...baseUnitSystems.get(system)}; } @@ -304,6 +312,16 @@ export function isDefaultBaseUnits(baseUnits: CustomBaseUnits, system: BaseUnitS return Object.entries(defaultBaseUnits).reduce((acum, [key, value]) => acum && value === baseUnits[key], true); } +export function baseUnitsEqual(baseUnits1: CustomBaseUnits, baseUnits2: CustomBaseUnits): boolean { + let result = true; + + for (const key in baseUnits1) { + result = result && baseUnits1[key] === baseUnits2[key]; + } + + return result; +} + export function normalizeConfig(inputConfig: Config | undefined): Config { const outputConfig = inputConfig ?? getDefaultConfig(); diff --git a/src/stores.ts b/src/stores.ts index f07d3760..e0404cf6 100644 --- a/src/stores.ts +++ b/src/stores.ts @@ -54,6 +54,7 @@ export const inCellInsertMode = writable(false); export const mathJaxLoaded = writable(false); +export const userDefaultConfig = writable(getDefaultConfig()); export async function addCell(type: CellTypes, index?: number) { const currentCells = get(cells); @@ -135,7 +136,7 @@ export function getSheetJson() { } export function resetSheet() { - config.set(getDefaultConfig()); + config.set({...get(userDefaultConfig)}); cells.set([]); title.set(defaultTitle); results.set([]); From b1b9967c393457733ca00faa0e32d6659fd159f6 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sun, 17 Nov 2024 13:48:52 -0600 Subject: [PATCH 3/8] fix: get user default config from idb each time a new sheet is created Covers case where user sets default config on one tab and uses it on another --- src/App.svelte | 16 ++-------------- src/SetDefaultConfigDialog.svelte | 24 +++++++++++++++++++----- src/stores.ts | 19 ++++++++++++++----- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 24b8ade0..4ef1220b 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -13,9 +13,7 @@ history, insertedSheets, activeCell, getSheetJson, getSheetObject, resetSheet, sheetId, mathCellChanged, nonMathCellChanged, addCell, prefersReducedMotion, modifierKey, inCellInsertMode, config, unsavedChange, incrementActiveCell, - decrementActiveCell, deleteCell, activeMathField, autosaveNeeded, mathJaxLoaded, - userDefaultConfig - } from "./stores"; + decrementActiveCell, deleteCell, activeMathField, autosaveNeeded, mathJaxLoaded } from "./stores"; import { isDefaultConfig, type Config, normalizeConfig } from "./sheet/Sheet"; import type { Statement, SubQueryStatement } from "./parser/types"; import type { SystemDefinition } from "./cells/SystemCell"; @@ -358,16 +356,6 @@ $prefersReducedMotion = mediaQueryList.matches mediaQueryList.addEventListener('change', handleMotionPreferenceChange); - let tempUserDefaultConfig: Config | undefined = undefined; - try { - tempUserDefaultConfig = await get('defaultConfig'); - } catch(e) { - console.log('Error retrieving user default config'); - tempUserDefaultConfig = undefined; - } - - $userDefaultConfig = tempUserDefaultConfig ?? getDefaultConfig(); - $unsavedChange = false; $autosaveNeeded = false; await refreshSheet(true); @@ -732,7 +720,7 @@ async function initializeBlankSheet() { currentStateObject = null; - resetSheet(); + await resetSheet(); await tick(); addCell('math'); await tick(); diff --git a/src/SetDefaultConfigDialog.svelte b/src/SetDefaultConfigDialog.svelte index 464bd7cc..6cfdd9a9 100644 --- a/src/SetDefaultConfigDialog.svelte +++ b/src/SetDefaultConfigDialog.svelte @@ -1,9 +1,22 @@ diff --git a/src/stores.ts b/src/stores.ts index e0404cf6..304a29b4 100644 --- a/src/stores.ts +++ b/src/stores.ts @@ -1,4 +1,5 @@ import { type Writable, writable, type Readable, readable, get } from 'svelte/store'; +import { get as idbGet } from 'idb-keyval'; import type { Cell } from './cells/Cells'; import { BaseCell, type CellTypes } from './cells/BaseCell'; @@ -17,7 +18,7 @@ import InsertCell from "./cells/InsertCell"; import type { History } from './database/types'; import type { Result, FiniteImagResult, PlotResult, MatrixResult, SystemResult, DataTableResult } from './resultTypes'; -import { type InsertedSheet, type Sheet, getDefaultConfig } from './sheet/Sheet'; +import { type Config, type InsertedSheet, type Sheet, getDefaultConfig } from './sheet/Sheet'; const defaultTitle = 'New Sheet'; @@ -54,8 +55,6 @@ export const inCellInsertMode = writable(false); export const mathJaxLoaded = writable(false); -export const userDefaultConfig = writable(getDefaultConfig()); - export async function addCell(type: CellTypes, index?: number) { const currentCells = get(cells); const currentResults = get(results); @@ -135,8 +134,18 @@ export function getSheetJson() { return ' ' + JSON.stringify(sheet); } -export function resetSheet() { - config.set({...get(userDefaultConfig)}); +export async function resetSheet() { + let defaultConfig: Config | undefined; + + try { + defaultConfig = await idbGet('defaultConfig'); + } catch(e) { + console.warn('Error retrieving default config for idb'); + defaultConfig = undefined; + } + defaultConfig = defaultConfig ?? getDefaultConfig(); + + config.set(defaultConfig); cells.set([]); title.set(defaultTitle); results.set([]); From 28f3691565c5d4ec849494282ac26d4c96ad6456 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sun, 17 Nov 2024 14:28:42 -0600 Subject: [PATCH 4/8] fix: apply config normalization to config read from idb Config adds fields over time and may need to be updated, uses same logic that is used when loading old sheets --- src/SetDefaultConfigDialog.svelte | 9 ++++----- src/sheet/Sheet.ts | 18 ++++++++++-------- src/stores.ts | 9 ++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/SetDefaultConfigDialog.svelte b/src/SetDefaultConfigDialog.svelte index 6cfdd9a9..f9025735 100644 --- a/src/SetDefaultConfigDialog.svelte +++ b/src/SetDefaultConfigDialog.svelte @@ -3,19 +3,18 @@ import { get, set } from 'idb-keyval'; import { Button } from "carbon-components-svelte"; import CheckmarkOutline from "carbon-icons-svelte/lib/CheckmarkOutline.svelte"; - import { type Config, configsEqual, getDefaultConfig } from "./sheet/Sheet"; + import { type Config, configsEqual, getDefaultConfig, normalizeConfig } from "./sheet/Sheet"; import { config } from "./stores"; - let userDefaultConfig: Config | undefined = getDefaultConfig(); + let userDefaultConfig: Config = getDefaultConfig(); onMount(async () => { try { - userDefaultConfig = await get('defaultConfig'); + userDefaultConfig = normalizeConfig(await get('defaultConfig')); } catch(e) { console.warn('Error attempting to load user default config'); - userDefaultConfig = undefined; + userDefaultConfig = getDefaultConfig(); } - userDefaultConfig = userDefaultConfig ?? getDefaultConfig(); }); async function setDefaultConfig() { diff --git a/src/sheet/Sheet.ts b/src/sheet/Sheet.ts index 7f105a53..3bc55d06 100644 --- a/src/sheet/Sheet.ts +++ b/src/sheet/Sheet.ts @@ -322,14 +322,16 @@ export function baseUnitsEqual(baseUnits1: CustomBaseUnits, baseUnits2: CustomBa return result; } -export function normalizeConfig(inputConfig: Config | undefined): Config { - const outputConfig = inputConfig ?? getDefaultConfig(); +export function normalizeConfig(config: Config | undefined): Config { + if (!config) { + return getDefaultConfig(); + } - outputConfig.customBaseUnits = outputConfig.customBaseUnits ?? getDefaultBaseUnits(); // customBaseUnits may not exist - outputConfig.simplifySymbolicExpressions = outputConfig.simplifySymbolicExpressions ?? true; // simplifySymboicExpressions may not exist - outputConfig.convertFloatsToFractions = outputConfig.convertFloatsToFractions ?? true; // convertFloatsToFractions may not exist - outputConfig.fluidConfig = outputConfig.fluidConfig ?? getDefaultFluidConfig(); // fluidConfig may not exist - outputConfig.mathCellConfig.showIntermediateResults = outputConfig.mathCellConfig.showIntermediateResults ?? false; // may not exist + config.customBaseUnits = config.customBaseUnits ?? getDefaultBaseUnits(); // customBaseUnits may not exist + config.simplifySymbolicExpressions = config.simplifySymbolicExpressions ?? true; // simplifySymboicExpressions may not exist + config.convertFloatsToFractions = config.convertFloatsToFractions ?? true; // convertFloatsToFractions may not exist + config.fluidConfig = config.fluidConfig ?? getDefaultFluidConfig(); // fluidConfig may not exist + config.mathCellConfig.showIntermediateResults = config.mathCellConfig.showIntermediateResults ?? false; // may not exist - return outputConfig; + return config; } \ No newline at end of file diff --git a/src/stores.ts b/src/stores.ts index 304a29b4..7ed20a17 100644 --- a/src/stores.ts +++ b/src/stores.ts @@ -18,7 +18,7 @@ import InsertCell from "./cells/InsertCell"; import type { History } from './database/types'; import type { Result, FiniteImagResult, PlotResult, MatrixResult, SystemResult, DataTableResult } from './resultTypes'; -import { type Config, type InsertedSheet, type Sheet, getDefaultConfig } from './sheet/Sheet'; +import { type Config, type InsertedSheet, type Sheet, getDefaultConfig, normalizeConfig } from './sheet/Sheet'; const defaultTitle = 'New Sheet'; @@ -135,15 +135,14 @@ export function getSheetJson() { } export async function resetSheet() { - let defaultConfig: Config | undefined; + let defaultConfig: Config; try { - defaultConfig = await idbGet('defaultConfig'); + defaultConfig = normalizeConfig(await idbGet('defaultConfig')); } catch(e) { console.warn('Error retrieving default config for idb'); - defaultConfig = undefined; + defaultConfig = getDefaultConfig(); } - defaultConfig = defaultConfig ?? getDefaultConfig(); config.set(defaultConfig); cells.set([]); From 37077a924e62ffaff8b223ebf8758d77252f3627 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sun, 17 Nov 2024 19:49:37 -0600 Subject: [PATCH 5/8] feat: add button to apply user default config to current sheet --- src/App.svelte | 2 +- src/SetDefaultConfigDialog.svelte | 40 ++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 4ef1220b..627dcbe0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -2820,7 +2820,7 @@ Please include a link to this sheet in the email to assist in debugging the prob - + { @@ -34,18 +35,39 @@ } } - $: configsMatch = configsEqual($config, userDefaultConfig) + function useDefaultConfig() { + $config = JSON.parse(JSON.stringify(userDefaultConfig)); + } + + $: configsMatch = configsEqual($config, userDefaultConfig); + $: userConfigIsDefaultConfig = configsEqual(userDefaultConfig, defaultConfig); - \ No newline at end of file +
+ + + {#if !configsMatch && !userConfigIsDefaultConfig} + + {/if} +
\ No newline at end of file From 596806977bdfb02c9eb510c7b02290f8154faaf4 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Wed, 20 Nov 2024 14:34:09 -0600 Subject: [PATCH 6/8] feat: improved set default config dialog Adds descriptive information about the current state and adds the persistent storage request button as well --- src/RequestPersistentStorage.svelte | 27 +++++++----- src/SetDefaultConfigDialog.svelte | 68 +++++++++++++++++++++-------- 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/src/RequestPersistentStorage.svelte b/src/RequestPersistentStorage.svelte index 772de2ee..9c71a321 100644 --- a/src/RequestPersistentStorage.svelte +++ b/src/RequestPersistentStorage.svelte @@ -1,14 +1,18 @@

- EngineeringPaper.xyz uses your browser's local storage to store your most recent {numCheckpoints} autosave - checkpoints and your list of recently visited sheets. Your web browser will not automatically persist this + EngineeringPaper.xyz uses your browser's local storage to store your default sheet config, + your {numCheckpoints ?? ""} most recent autosave + checkpoints, and your list of recently visited sheets. Your web browser will not automatically persist this local storage and may clear it at any time. Safari is particularly aggressive about freeing this storage and will automatically clear local storage for a site that has not been visited in the previous seven days.

@@ -28,8 +33,8 @@

Click the button below to request that your browser enables persistent local storage for the - EngineeringPaper.xyz domain. Your browser may popup a dialog that asks you to approve this request. - Chrome and Edge require you to bookmark EngineeringPaper.xyz in order to enable persistent storage. + {hostName} domain. Your browser may popup a dialog that asks you to approve this request. + Chrome and Edge may require you to bookmark {hostName} in order to enable persistent storage.


@@ -45,9 +50,11 @@

- +

diff --git a/src/SetDefaultConfigDialog.svelte b/src/SetDefaultConfigDialog.svelte index 427d8d13..a6c91c93 100644 --- a/src/SetDefaultConfigDialog.svelte +++ b/src/SetDefaultConfigDialog.svelte @@ -1,12 +1,14 @@ @@ -52,22 +64,42 @@ } +
+

+ {#if configsMatch} + The current sheet config matches the user default config. + {:else if !currentConfigIsDefaultConfig} + The current sheet config differs from the user default config, the buttons + below can be used to either save this sheet's config as the user default config or apply the user default + config to this sheet. + {:else} + The current sheet is using the EngineeringPaper.xyz default config which + is different than the user default config. The user default config can be applied to this sheet using + the second button below. + {/if} +

+ +
- {#if !configsMatch && !userConfigIsDefaultConfig} - - {/if} -
\ No newline at end of file + +
+ +
+ +
+ + From 88d01dfbbf32e430eeca13163743da86fe8d9fdd Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sat, 23 Nov 2024 14:37:33 -0600 Subject: [PATCH 7/8] tests: add tests for custom user default config capabilities --- tests/test_custom_base_units.spec.mjs | 98 +++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tests/test_custom_base_units.spec.mjs b/tests/test_custom_base_units.spec.mjs index ffdd31ec..589dd24e 100644 --- a/tests/test_custom_base_units.spec.mjs +++ b/tests/test_custom_base_units.spec.mjs @@ -264,4 +264,102 @@ test('Test cell units supersede with code generation', async () => { `); await page.keyboard.press('Escape'); +}); + +test('Test user default config', async () => { + await page.setLatex(0, String.raw`1\left\lbrack m\right\rbrack=`); + + await page.waitForSelector('text=Updating...', {state: 'detached'}); + + let content = await page.textContent('#result-value-0'); + expect(parseLatexFloat(content)).toBeCloseTo(1, precision); + content = await page.textContent('#result-units-0'); + expect(content).toBe('m'); + + await page.getByRole('button', { name: 'Sheet Settings' }).click(); + await page.getByRole('tab', { name: 'Default Units' }).click(); + await page.getByRole('button', { name: 'inch-lbm-sec'}).click(); + await page.getByRole('tab', { name: 'Set User Default'}).click(); + await expect(page.locator('text=The current sheet config differs from the user default config')).toBeAttached(); + await page.getByRole('button', { name: "Use This Sheet's Config as the User Default Config"}).click(); + await expect(page.locator('text=The current sheet config matches the user default config')).toBeAttached(); + await page.getByRole('button', { name: 'Confirm' }).click(); + + await page.waitForSelector('text=Updating...', {state: 'detached'}); + + content = await page.textContent('#result-value-0'); + expect(parseLatexFloat(content)).toBeCloseTo(1000/25.4, precision); + content = await page.textContent('#result-units-0'); + expect(content).toBe('in'); + + // load new sheet and make sure it is using the user default sheet config + await newSheet(page); + + await page.setLatex(0, String.raw`2\left\lbrack m\right\rbrack=`); + + await page.waitForSelector('text=Updating...', {state: 'detached'}); + + content = await page.textContent('#result-value-0'); + expect(parseLatexFloat(content)).toBeCloseTo(2000/25.4, precision); + content = await page.textContent('#result-units-0'); + expect(content).toBe('in'); + + // change this sheet's config and then apply user default config + await page.getByRole('button', { name: 'Sheet Settings' }).click(); + await page.getByRole('tab', { name: 'Default Units' }).click(); + await page.getByRole('button', { name: 'mm-kg-sec'}).click(); + await page.getByRole('tab', { name: 'Set User Default'}).click(); + await expect(page.locator('text=The current sheet config differs from the user default config')).toBeAttached(); + await page.getByRole('button', { name: 'Confirm' }).click(); + + await page.waitForSelector('text=Updating...', {state: 'detached'}); + + content = await page.textContent('#result-value-0'); + expect(parseLatexFloat(content)).toBeCloseTo(2000, precision); + content = await page.textContent('#result-units-0'); + expect(content).toBe('mm'); + + // apply the user default config + await page.getByRole('button', { name: 'Sheet Settings' }).click(); + await page.getByRole('tab', { name: 'Set User Default'}).click(); + await expect(page.locator('text=The current sheet config differs from the user default config')).toBeAttached(); + await page.getByRole('button', { name: 'Apply the User Default Config to This Sheet'}).click(); + await expect(page.locator('text=The current sheet config matches the user default config')).toBeAttached(); + await page.getByRole('button', { name: 'Confirm' }).click(); + + await page.waitForSelector('text=Updating...', {state: 'detached'}); + + content = await page.textContent('#result-value-0'); + expect(parseLatexFloat(content)).toBeCloseTo(2000/25.4, precision); + content = await page.textContent('#result-units-0'); + expect(content).toBe('in'); + + // switch back to the default config and save it as the user default config + await page.getByRole('button', { name: 'Sheet Settings' }).click(); + await page.getByRole('tab', { name: 'Set User Default'}).click(); + await expect(page.locator('text=The current sheet config matches the user default config')).toBeAttached(); + await page.getByRole('button', { name: 'Restore Defaults'}).click(); + await expect(page.locator('text=The current sheet is using the EngineeringPaper.xyz default config which is different than the user default config')).toBeAttached(); + await page.getByRole('button', { name: "Use This Sheet's Config as the User Default Config"}).click(); + await expect(page.locator('text=The current sheet config matches the user default config')).toBeAttached(); + + await page.waitForSelector('text=Updating...', {state: 'detached'}); + + content = await page.textContent('#result-value-0'); + expect(parseLatexFloat(content)).toBeCloseTo(2, precision); + content = await page.textContent('#result-units-0'); + expect(content).toBe('m'); + + // load new sheet and make sure it is using the default sheet config + await newSheet(page); + + await page.setLatex(0, String.raw`3\left\lbrack m\right\rbrack=`); + + await page.waitForSelector('text=Updating...', {state: 'detached'}); + + content = await page.textContent('#result-value-0'); + expect(parseLatexFloat(content)).toBeCloseTo(3, precision); + content = await page.textContent('#result-units-0'); + expect(content).toBe('m'); + }); \ No newline at end of file From b197066ac0fc613a5f478cd3b4fb8706e9a81126 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sat, 23 Nov 2024 21:06:22 -0600 Subject: [PATCH 8/8] chore: bump version and update new features dialog --- src/App.svelte | 2 +- src/Updates.svelte | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/App.svelte b/src/App.svelte index 627dcbe0..2af3b6e8 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -96,7 +96,7 @@ const apiUrl = window.location.origin; - const currentVersion = 20241102; + const currentVersion = 20241123; const tutorialHash = "moJCuTwjPi7dZeZn5QiuaP"; const termsVersion = 20240110; diff --git a/src/Updates.svelte b/src/Updates.svelte index c1711e26..c620b1c9 100644 --- a/src/Updates.svelte +++ b/src/Updates.svelte @@ -16,6 +16,19 @@ } +November 23, 2024 +

New Custom Default Sheet Settings Feature

+

+ You can now set your own custom default sheet settings (default units, default number + formating, etc.). These defaults will be used whenever you create a new sheet + and these settings can also be applied to existing sheets. All of this functionality + is accessible through the "Set User Default" tab of the "Sheet Settings" + dialog (available using the sheet settings button + at the top toolbar). +

+ +
+ November 2, 2024

Matrix Multiplication Improvements