/** * Named views. A thin, packaged manager on top of `api.getState()` / * `api.setState()` so the "save / restore named layouts" feature every * enterprise grid ships is one import instead of hand-rolled glue. * * Storage is pluggable: `localStorageViews(key)` persists per browser, or * pass your own adapter to sync views to a server / per-user account. The * manager itself is pure and synchronous, so it is trivially testable. */ import type { SvGridViewState } from './svgrid-wrapper.types'; export type SavedView = { name: string; state: Partial; createdAt: number; }; export type ViewStorage = { read(): SavedView[]; write(views: SavedView[]): void; }; /** Minimal grid handle the manager needs - `SvGridApi` satisfies it. */ export type ViewStateHost = { getState(): SvGridViewState; setState(state: Partial): void; }; export type NamedViews = { list(): SavedView[]; /** Capture the grid's current state under `name` (overwrites a duplicate). */ save(name: string): SavedView; /** Apply a saved view to the grid. Returns false if the name is unknown. */ load(name: string): boolean; /** Delete a saved view. Returns false if the name is unknown. */ remove(name: string): boolean; rename(from: string, to: string): boolean; has(name: string): boolean; }; /** In-memory storage (default). State lives only as long as the manager. */ export declare function memoryViews(initial?: SavedView[]): ViewStorage; /** localStorage-backed storage. Safe to construct in SSR (no-ops there). */ export declare function localStorageViews(key: string): ViewStorage; export declare function createNamedViews(host: ViewStateHost, options?: { storage?: ViewStorage; }): NamedViews; export type AutoSavedViewOptions = { /** Slot name inside the NamedViews store. Default `'__autosave'`. */ name?: string; /** Sample interval in ms. Default 800. */ intervalMs?: number; /** Skip restore-on-mount (e.g. you already loaded a URL view first). */ skipRestore?: boolean; }; /** * Attach an "always-save-current-layout" slot to a `NamedViews` manager. * Restores once on attach (if a saved view exists under `name`) and * polls `host.getState()` thereafter, saving when the JSON snapshot * changes. * * Returns a `detach()` that stops polling - call it from `onDestroy`. * * ```ts * const views = createNamedViews(api, { storage: localStorageViews('myapp:views') }) * const off = attachAutoSavedView(api, views) * onDestroy(off) * ``` * * Distinct from a user-saved named view: the slot is a single, fixed * name reserved for "what the user left the page looking at." The user * can still call `views.save('Q3 review')` etc. through the same store. */ export declare function attachAutoSavedView(host: ViewStateHost, views: NamedViews, opts?: AutoSavedViewOptions): () => void;