// Type definitions for Coherent.js Remix integration. // // Aligned with the runtime exports of ../../src/remix/index.js. import type { ReactElement } from 'react'; import type { CoherentNode } from '@coherent.js/core'; /** A Coherent.js component: a node, or a function of props returning one. */ export type CoherentRemixComponent = CoherentNode | ((props: Props) => CoherentNode); /** The arguments Remix passes to loaders and actions. */ export interface CoherentRemixDataArgs { request: Request; params: Record; context: unknown; } export interface CoherentRemixActionArgs extends CoherentRemixDataArgs { /** The submitted form fields (`Object.fromEntries(await request.formData())`). */ data: Record; } export interface CoherentRemixAdapterOptions { /** Enable client-side hydration. */ hydrate?: boolean; } export interface CoherentRemixAdapter { /** Render a component (or component function) to an HTML string. */ renderComponent(component: CoherentRemixComponent, props?: Props): string; /** * Create a loader that answers with the rendered component as `text/html`. * Without `getProps` the component receives `{ request, params }`. */ createLoader( component: CoherentRemixComponent, getProps?: (args: CoherentRemixDataArgs) => Props | Promise ): (args: CoherentRemixDataArgs) => Promise; /** * Create an action that passes the submitted form to `handler` and renders * the component with its result, unless the handler returns a Response. */ createAction( component: CoherentRemixComponent, handler: (args: CoherentRemixActionArgs) => Result | Response | Promise ): (args: CoherentRemixDataArgs) => Promise; } export function createRemixAdapter(options?: CoherentRemixAdapterOptions): CoherentRemixAdapter; export interface WithCoherentOptions { /** * Tag name of the element the markup is rendered into * @default 'div' */ as?: string; } /** * Wrap a Coherent.js component as a React component for Remix routes. The * markup is rendered inside a wrapper element via `dangerouslySetInnerHTML`. */ export function withCoherent( Component: CoherentRemixComponent, options?: WithCoherentOptions ): (props: Props) => ReactElement;