import { Signal, TNode, Value } from '@tempots/dom'; import type { QueryResourceLoadOptions } from '@tempots/ui'; import type { AsyncResult } from '@tempots/std'; import type { DataTableOptions } from '../data/data-table-types'; /** * Options for {@link QueryDataTable}. * * Combines all {@link DataTableOptions} (except `data` and `loading`, which are * managed internally) with query options from {@link QueryDataSourceOptions}. * * @typeParam Req - The request signal type that triggers loading. * @typeParam T - The row type in the data array. * @typeParam C - Column ID string union. * @typeParam E - The error type (defaults to `unknown`). */ export type QueryDataTableOptions = Omit, 'data' | 'loading'> & { /** Signal whose changes trigger a new load. */ request: Value; /** Async function that fetches data. */ load: (opts: QueryResourceLoadOptions) => Promise; /** Converts unknown errors into the error type E. */ convertError: (error: unknown) => E; /** Called on successful load. */ onSuccess?: (value: T[], req: Req) => void; /** Called on failed load. */ onError?: (error: E, req: Req) => void; /** Called after load completes (success or failure). */ onSettled?: (result: AsyncResult, req: Req) => void; /** * Custom error rendering. When provided, shown instead of default error UI. * Only displayed when no data has been loaded yet (first-load failure). * On reload failures, stale data remains visible. */ errorContent?: (error: Signal, reload: () => void) => TNode; }; /** * A DataTable that loads data asynchronously via a query. * * Combines {@link createQueryDataSource} with {@link DataTable} into a single * component. The DataTable is always mounted (so sort/filter/selection state * persists across reloads), and loading/error states are handled automatically. * * @example * ```ts * QueryDataTable({ * request: searchParams, * load: async ({ request, abortSignal }) => { * const res = await fetch(`/api/users?q=${request.query}`, { signal: abortSignal }) * return res.json() * }, * convertError: String, * columns: [ * { id: 'name', header: 'Name', cell: row => row.map(r => r.name) }, * { id: 'email', header: 'Email', cell: row => row.map(r => r.email) }, * ], * rowId: u => u.id, * pagination: { pageSize: 20 }, * sortable: true, * }) * ``` */ export declare function QueryDataTable(options: QueryDataTableOptions): TNode;