All checks were successful
Deploy Nyla Frontend to Integration / deploy (push) Successful in 1m27s
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// Copyright (c) 2026 PowerOn AG
|
|
// All rights reserved.
|
|
/**
|
|
* LayoutPersistenceAdapter — pluggable persistence for layout state.
|
|
*
|
|
* Default implementation uses localStorage.
|
|
* NOT used for navigation state (URL is source-of-truth) or settings values (DB).
|
|
* Use for: panel widths, collapse state, user UI preferences.
|
|
*/
|
|
|
|
import type { LayoutPersistenceAdapter } from './types';
|
|
|
|
const PREFIX = 'po_layout_';
|
|
|
|
function _buildKey(scope: string, key: string): string {
|
|
return `${PREFIX}${scope}:${key}`;
|
|
}
|
|
|
|
export function _createLocalStorageAdapter(scope: string): LayoutPersistenceAdapter {
|
|
return {
|
|
scope,
|
|
load<T>(key: string): T | null {
|
|
try {
|
|
const raw = localStorage.getItem(_buildKey(scope, key));
|
|
if (raw === null) return null;
|
|
return JSON.parse(raw) as T;
|
|
} catch {
|
|
return null;
|
|
}
|
|
},
|
|
save<T>(key: string, value: T): void {
|
|
try {
|
|
localStorage.setItem(_buildKey(scope, key), JSON.stringify(value));
|
|
} catch {
|
|
// localStorage full or unavailable — silently ignore for UI preferences
|
|
}
|
|
},
|
|
};
|
|
}
|