import { createSvGridCore } from './core' import type { RowData, SvGrid, SvGridOptions, TableFeatures, } from './core' export type SvelteGrid< TFeatures extends TableFeatures, TData extends RowData, TSelected = {}, > = SvGrid & { readonly state: Readonly } export function createSvGrid< TFeatures extends TableFeatures, TData extends RowData, TSelected = {}, >( gridOptions: SvGridOptions, selector: (state: Record) => TSelected = () => ({}) as TSelected, ): SvelteGrid { const grid = createSvGridCore(gridOptions) as SvelteGrid let selected = $state(selector(grid.store.state)) grid.store.subscribe(() => { selected = selector(grid.store.state) }) Object.defineProperty(grid, 'state', { get() { return selected }, configurable: true, enumerable: true, }) return grid } export const createGrid = createSvGrid