/** * DataGrid Context * * Provides shared state to child components via Svelte context. */ import { getContext, setContext } from 'svelte'; import type { DataGridContext } from './types'; const DATA_GRID_CONTEXT_KEY = Symbol('data-grid'); /** * Set the DataGrid context (called by DataGrid.svelte) */ export function setDataGridContext(ctx: DataGridContext): void { setContext(DATA_GRID_CONTEXT_KEY, ctx); } /** * Get the DataGrid context (called by child components) */ export function getDataGridContext(): DataGridContext { const ctx = getContext>(DATA_GRID_CONTEXT_KEY); if (!ctx) { throw new Error('DataGrid context not found. Ensure component is used within a DataGrid.'); } return ctx; }