# @contractspec/lib.contracts-runtime-client-react

**React runtime adapters for ContractSpec contracts.**

## What It Provides

- **Layer**: lib.
- **Consumers**: design-system, presentation-runtime-react, bundles.
- Related ContractSpec packages include `@contractspec/lib.contracts-spec`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.
- Related ContractSpec packages include `@contractspec/lib.contracts-spec`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.

## Installation

`npm install @contractspec/lib.contracts-runtime-client-react`

or

`bun add @contractspec/lib.contracts-runtime-client-react`

## Usage

Import the root entrypoint from `@contractspec/lib.contracts-runtime-client-react`, or choose a documented subpath when you only need one part of the package surface.

The form renderer supports the expanded FormSpec field set: readonly inputs, email, autocomplete, address, phone, date, time, datetime, semantic groups, repeated grouped arrays, grid layout hints, progressive `layout.flow` sections/steps, and text/textarea/email input groups. Drivers are expected to provide dedicated slots for rich widgets plus shadcn/Radix-style `Field*` and optional `InputGroup*` slots. Email fields render through the standard input slot with native email input behavior. When input-group slots are absent, text, email, and textarea fields fall back to plain controls.

Autocomplete fields support local filtering and resolver-backed search. Resolver
calls receive the current query, watched dependency values, field name, and an
`AbortSignal` through the existing resolver args object; stale responses are
ignored and selected remote options remain visible when later searches return a
different result set. Custom autocomplete driver slots can read optional
`loading`, `error`, `emptyText`, `loadingText`, and `errorText` props to expose
async state.

### PWA update checks

`usePwaUpdateChecker` from `@contractspec/lib.contracts-runtime-client-react/pwa-update-client` checks the `pwa.update.check` API, exposes required/blocking versus optional update state, supports polling, and delegates actual service worker activation to a host-provided `onApply` callback.

## Architecture

- `src/drivers` is part of the package's public or composition surface.
- `src/feature-render.ts` is part of the package's public or composition surface.
- `src/form-render.impl.tsx` is part of the package's public or composition surface.
- `src/form-render.ts` is part of the package's public or composition surface.
- `src/index.ts` is the root public barrel and package entrypoint.

## Public Entry Points

- Export `.` resolves through `./src/index.ts`.
- Export `./drivers/rn-reusables` resolves through `./src/drivers/rn-reusables.ts`.
- Export `./drivers/shadcn` resolves through `./src/drivers/shadcn.ts`.
- Export `./feature-render` resolves through `./src/feature-render.ts`.
- Export `./form-render` resolves through `./src/form-render.ts`.
- Export `./form-render.impl` resolves through `./src/form-render.impl.tsx`.
- Export `./pwa-update-client` resolves through `./src/pwa-update-client.tsx`.

## Local Commands

- `bun run dev` — contractspec-bun-build dev
- `bun run build` — bun run prebuild && bun run build:bundle && bun run build:types
- `bun run lint` — bun run lint:fix
- `bun run lint:check` — biome check .
- `bun run lint:fix` — biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .
- `bun run typecheck` — tsc --noEmit
- `bun run publish:pkg` — bun publish --tolerate-republish --ignore-scripts --verbose
- `bun run publish:pkg:canary` — bun publish:pkg --tag canary
- `bun run clean` — rm -rf dist
- `bun run build:bundle` — contractspec-bun-build transpile
- `bun run build:types` — contractspec-bun-build types
- `bun run prebuild` — contractspec-bun-build prebuild

## Recent Updates

- Replace eslint+prettier by biomejs to optimize speed.

## Notes

- Driver interface must stay compatible with both shadcn and RN Reusables.
- Form rendering pipeline is a critical path; test thoroughly before changing.
