import { ColumnConfig as BaseColumnConfig, GridConfig as BaseGridConfig, CellRenderContext, ColumnEditorContext, ColumnFieldKey, EmptyContext, HeaderCellContext, HeaderLabelContext, LoadingContext } from '@toolbox-web/grid'; import { ReactNode } from 'react'; /** * Column configuration for React applications. * * Extends the base ColumnConfig with `renderer` and `editor` properties * that accept React render functions returning JSX. * * @example * ```tsx * import type { GridConfig, ColumnConfig } from '@toolbox-web/grid-react'; * * const columns: ColumnConfig[] = [ * { field: 'name', header: 'Name' }, * { * field: 'status', * header: 'Status', * renderer: (ctx) => , * editor: (ctx) => ( * * ), * }, * ]; * ``` * @since 0.0.1 */ export interface ColumnConfig> extends Omit, 'renderer' | 'viewRenderer' | 'editor' | 'headerRenderer' | 'headerLabelRenderer'> { /** * React component renderer for cell display. * Receives cell context and returns a React node (JSX). * * Same property name as vanilla JS, but accepts React components. */ renderer?: (ctx: CellRenderContext) => ReactNode; /** * React component editor for cell editing. * Receives editor context with commit/cancel functions and returns a React node (JSX). * * Same property name as vanilla JS, but accepts React components. */ editor?: (ctx: ColumnEditorContext) => ReactNode; /** * React component header renderer for full header cell control. * Receives header cell context and returns a React node (JSX). */ headerRenderer?: (ctx: HeaderCellContext) => ReactNode; /** * React component header label renderer for customizing just the label portion. * Receives header label context and returns a React node (JSX). */ headerLabelRenderer?: (ctx: HeaderLabelContext) => ReactNode; } /** * Grid configuration for React applications. * * Uses React-augmented ColumnConfig that accepts JSX render functions. * * @example * ```tsx * import type { GridConfig } from '@toolbox-web/grid-react'; * * const config: GridConfig = { * columns: [ * { field: 'name', header: 'Name' }, * { * field: 'status', * renderer: (ctx) => , * }, * ], * }; * ``` * @since 0.0.1 */ export type GridConfig> = Omit, 'columns' | 'loadingRenderer' | 'emptyRenderer'> & { columns?: ColumnConfig[]; /** * Custom loading renderer - can be a vanilla DOM function or a React render function returning JSX. */ loadingRenderer?: BaseGridConfig['loadingRenderer'] | ((ctx: LoadingContext) => ReactNode); /** * Custom empty-state renderer shown when the grid has no rows and is not * loading. Can be a vanilla DOM function (returning `HTMLElement | string`) * or a React render function returning JSX. Set explicitly to `null` to * suppress the built-in default message. */ emptyRenderer?: BaseGridConfig['emptyRenderer'] | ((ctx: EmptyContext) => ReactNode); }; /** * Clean up config-based editor and renderer portals whose containers are * inside the given element. Called by the React GridAdapter's `releaseCell` * to unmount portals created by `wrapReactEditor` / `wrapReactRenderer` * (which bypass the adapter's per-cell portal tracking). * * Targets both `.react-cell-editor` AND `.react-cell-renderer` containers: * editors always tear down on cell release, and renderers MUST also tear * down before the editing pipeline runs `cell.innerHTML = ''` (otherwise * React's still-mounted fiber tree points at orphan DOM and throws on the * next commit — see `wrapReactRenderer` doc and issue #250). The renderer * cache will create a fresh container on the next render via its * cellEl.contains() check. * * @internal */ export declare function cleanupConfigRootsIn(parentEl: HTMLElement): void; /** * Returns a function that, when invoked, blurs the focused input/textarea/select * inside `container` (if any). Used by the `before-edit-close` bridge so editors * with `onBlur={commit}` flush their pending value before the cell DOM is torn * down by Tab / programmatic row exit. The native `.blur()` method fires both * `blur` (non-bubbling) and `focusout` (bubbling) — React's event delegation * listens to `focusout` and maps it to `onBlur`. * @internal */ export declare function makeFlushFocusedInput(container: HTMLElement): () => void; /** * Wraps a React renderer function into a DOM-returning viewRenderer. * Used internally by DataGrid to process reactRenderer properties. * * Cache invariant: a cached `{ portalKey, container }` is only safe to reuse * while `container` is still attached to the original cell. The editing * pipeline (`editor-injection.ts`) wipes a cell with `cell.innerHTML = ''` * when an editor opens — this detaches the renderer container from the cell * without React knowing, leaving React's fiber tree pointing at orphaned * nodes. If we then reuse the cached entry on the next render, the user's * `onCellCommit` → `setRows` triggers a React commit that tries to * `removeChild` nodes that no longer exist in the DOM and throws * `NotFoundError: Failed to execute 'removeChild' on 'Node'` (issue #250). * * Defense: before reusing a cached entry, verify the container is still * inside the cell. If not, synchronously unmount the stale React root * (`removeFromContainer(..., { sync: true })` so it tears down before any * batched user setState runs against it) and create a fresh container. */ export declare function wrapReactRenderer(renderFn: (ctx: CellRenderContext) => ReactNode): (ctx: CellRenderContext) => HTMLElement; /** * Wraps a React editor function into a DOM-returning editor spec. * Used internally by DataGrid to process reactEditor properties. */ export declare function wrapReactEditor(editorFn: (ctx: ColumnEditorContext) => ReactNode): (ctx: ColumnEditorContext) => HTMLElement; /** * Wraps a React header renderer function into a DOM-returning function. * Used internally by DataGrid to process headerRenderer properties. */ export declare function wrapReactHeaderRenderer(renderFn: (ctx: HeaderCellContext) => ReactNode): (ctx: HeaderCellContext) => HTMLElement; /** * Wraps a React header label renderer function into a DOM-returning function. * Used internally by DataGrid to process headerLabelRenderer properties. */ export declare function wrapReactHeaderLabelRenderer(renderFn: (ctx: HeaderLabelContext) => ReactNode): (ctx: HeaderLabelContext) => HTMLElement; /** * Wraps a React loading renderer function into a DOM-returning function. * Used internally by processGridConfig to process loadingRenderer properties. * Skips wrapping if the function already returns an HTMLElement or string (vanilla DOM renderer). */ export declare function wrapReactLoadingRenderer(renderFn: (ctx: LoadingContext) => ReactNode): (ctx: LoadingContext) => HTMLElement | string; /** * Wraps a React empty-state renderer into a DOM-returning function. * Mirrors `wrapReactLoadingRenderer`: vanilla `HTMLElement | string` returns * are passed through unchanged so consumers can mix DOM-only and React * renderers freely. */ export declare function wrapReactEmptyRenderer(renderFn: (ctx: EmptyContext) => ReactNode): (ctx: EmptyContext) => HTMLElement | string; /** * Processes a GridConfig, converting React renderer/editor functions * to DOM-returning functions that the grid core understands. * * @internal Used by DataGrid component */ export declare function processGridConfig(config: GridConfig | undefined): BaseGridConfig | undefined; //# sourceMappingURL=react-column-config.d.ts.map