v0.3.1 with Saxon fully working
This commit is contained in:
52
src/workspace/localStorageStore.ts
Normal file
52
src/workspace/localStorageStore.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { createDefaultWorkbenchState } from './defaultWorkspace';
|
||||
import type { WorkbenchState } from './workspaceTypes';
|
||||
|
||||
const STORAGE_KEY = 'xslt-tools:workspace:v1';
|
||||
|
||||
function isWorkbenchState(value: unknown): value is WorkbenchState {
|
||||
if (!value || typeof value !== 'object') return false;
|
||||
|
||||
const candidate = value as Partial<WorkbenchState>;
|
||||
return (
|
||||
candidate.schemaVersion === 1 &&
|
||||
Boolean(candidate.xmlInput) &&
|
||||
Boolean(candidate.xsltCode) &&
|
||||
Boolean(candidate.xmlOutput)
|
||||
);
|
||||
}
|
||||
|
||||
export function loadWorkbenchState(): WorkbenchState {
|
||||
const fallback = createDefaultWorkbenchState();
|
||||
|
||||
try {
|
||||
const raw = window.localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return fallback;
|
||||
|
||||
const parsed = JSON.parse(raw) as unknown;
|
||||
if (!isWorkbenchState(parsed)) return fallback;
|
||||
|
||||
return {
|
||||
...fallback,
|
||||
...parsed,
|
||||
options: { ...fallback.options, ...parsed.options },
|
||||
xmlInput: { ...fallback.xmlInput, ...parsed.xmlInput },
|
||||
xsltCode: { ...fallback.xsltCode, ...parsed.xsltCode },
|
||||
xmlOutput: { ...fallback.xmlOutput, ...parsed.xmlOutput },
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn('Failed to load workspace from LocalStorage.', error);
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
export function saveWorkbenchState(state: WorkbenchState): void {
|
||||
try {
|
||||
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
|
||||
} catch (error) {
|
||||
console.warn('Failed to save workspace to LocalStorage.', error);
|
||||
}
|
||||
}
|
||||
|
||||
export function clearWorkbenchState(): void {
|
||||
window.localStorage.removeItem(STORAGE_KEY);
|
||||
}
|
||||
Reference in New Issue
Block a user