// 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(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(key: string, value: T): void { try { localStorage.setItem(_buildKey(scope, key), JSON.stringify(value)); } catch { // localStorage full or unavailable — silently ignore for UI preferences } }, }; }