mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-03 13:18:56 +00:00
29 lines
756 B
TypeScript
29 lines
756 B
TypeScript
/**
|
|
* 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<T>(ctx: DataGridContext<T>): void {
|
|
setContext(DATA_GRID_CONTEXT_KEY, ctx);
|
|
}
|
|
|
|
/**
|
|
* Get the DataGrid context (called by child components)
|
|
*/
|
|
export function getDataGridContext<T = unknown>(): DataGridContext<T> {
|
|
const ctx = getContext<DataGridContext<T>>(DATA_GRID_CONTEXT_KEY);
|
|
if (!ctx) {
|
|
throw new Error('DataGrid context not found. Ensure component is used within a DataGrid.');
|
|
}
|
|
return ctx;
|
|
}
|