page.mdx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. export const metadata = { title: "Changelog" }
  2. # Changelog
  3. Notable changes and updates to json-render.
  4. ## v0.8.0
  5. February 2026
  6. ### New: `@json-render/react-pdf`
  7. PDF renderer for json-render, powered by [`@react-pdf/renderer`](https://react-pdf.org/). Define catalogs and registries the same way as `@json-render/react`, but output PDF documents instead of web UI.
  8. ```bash
  9. npm install @json-render/core @json-render/react-pdf
  10. ```
  11. ```typescript
  12. import { renderToBuffer } from "@json-render/react-pdf";
  13. import type { Spec } from "@json-render/core";
  14. const spec: Spec = {
  15. root: "doc",
  16. elements: {
  17. doc: { type: "Document", props: { title: "Invoice" }, children: ["page"] },
  18. page: {
  19. type: "Page",
  20. props: { size: "A4" },
  21. children: ["heading", "table"],
  22. },
  23. heading: {
  24. type: "Heading",
  25. props: { text: "Invoice #1234", level: "h1" },
  26. children: [],
  27. },
  28. table: {
  29. type: "Table",
  30. props: {
  31. columns: [
  32. { header: "Item", width: "60%" },
  33. { header: "Price", width: "40%", align: "right" },
  34. ],
  35. rows: [
  36. ["Widget A", "$10.00"],
  37. ["Widget B", "$25.00"],
  38. ],
  39. },
  40. children: [],
  41. },
  42. },
  43. };
  44. const buffer = await renderToBuffer(spec);
  45. ```
  46. Server-side rendering APIs:
  47. - `renderToBuffer(spec)` -- render to an in-memory PDF buffer
  48. - `renderToStream(spec)` -- render to a readable stream (pipe to HTTP response)
  49. - `renderToFile(spec, path)` -- render directly to a file
  50. 15 standard components covering document structure (Document, Page), layout (View, Row, Column), content (Heading, Text, Image, Link), data (Table, List), decorative (Divider, Spacer), and page-level (PageNumber).
  51. Supports custom catalogs with `defineRegistry`, server-safe imports via `@json-render/react-pdf/server`, and full context support (state, visibility, actions, validation, repeat scopes).
  52. ---
  53. ## v0.7.0
  54. February 2026
  55. ### New: `@json-render/shadcn`
  56. Pre-built [shadcn/ui](https://ui.shadcn.com/) component library for json-render. 36 components built on Radix UI + Tailwind CSS, ready to use with `defineCatalog` and `defineRegistry`.
  57. ```bash
  58. npm install @json-render/shadcn
  59. ```
  60. ```typescript
  61. import { defineCatalog } from "@json-render/core";
  62. import { schema } from "@json-render/react/schema";
  63. import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog";
  64. import { defineRegistry } from "@json-render/react";
  65. import { shadcnComponents } from "@json-render/shadcn";
  66. const catalog = defineCatalog(schema, {
  67. components: {
  68. Card: shadcnComponentDefinitions.Card,
  69. Button: shadcnComponentDefinitions.Button,
  70. Input: shadcnComponentDefinitions.Input,
  71. },
  72. actions: {},
  73. });
  74. const { registry } = defineRegistry(catalog, {
  75. components: {
  76. Card: shadcnComponents.Card,
  77. Button: shadcnComponents.Button,
  78. Input: shadcnComponents.Input,
  79. },
  80. });
  81. ```
  82. Components include: layout (Card, Stack, Grid, Separator), navigation (Tabs, Accordion, Collapsible, Pagination), overlay (Dialog, Drawer, Tooltip, Popover, DropdownMenu), content (Heading, Text, Image, Avatar, Badge, Alert, Carousel, Table), feedback (Progress, Skeleton, Spinner), and input (Button, Link, Input, Textarea, Select, Checkbox, Radio, Switch, Slider, Toggle, ToggleGroup, ButtonGroup).
  83. See the [API reference](/docs/api/shadcn) for full details.
  84. ### New: Event Handles (`on()`)
  85. Components now receive an `on(event)` function in addition to `emit(event)`. The `on()` function returns an `EventHandle` with metadata:
  86. - `emit()` -- fire the event
  87. - `shouldPreventDefault` -- whether any action binding requested `preventDefault`
  88. - `bound` -- whether any handler is bound to this event
  89. ```tsx
  90. Link: ({ props, on }) => {
  91. const click = on("click");
  92. return (
  93. <a href={props.href} onClick={(e) => {
  94. if (click.shouldPreventDefault) e.preventDefault();
  95. click.emit();
  96. }}>{props.label}</a>
  97. );
  98. },
  99. ```
  100. ### New: `BaseComponentProps`
  101. Catalog-agnostic base type for component render functions. Use when building reusable component libraries (like `@json-render/shadcn`) that are not tied to a specific catalog.
  102. ```typescript
  103. import type { BaseComponentProps } from "@json-render/react";
  104. const Card = ({ props, children }: BaseComponentProps<{ title?: string }>) => (
  105. <div>{props.title}{children}</div>
  106. );
  107. ```
  108. ### New: Built-in Actions in Schema
  109. Schemas can now declare `builtInActions` -- actions that are always available at runtime and automatically injected into prompts. The React schema declares `setState`, `pushState`, and `removeState` as built-in, so they appear in prompts without needing to be listed in catalog `actions`.
  110. ### New: `preventDefault` on `ActionBinding`
  111. Action bindings now support a `preventDefault` boolean field, allowing the LLM to request that default browser behavior (e.g. navigation on links) be prevented.
  112. ### Improved: Stream Transform Text Block Splitting
  113. `createJsonRenderTransform()` now properly splits text blocks around spec data by emitting `text-end`/`text-start` pairs. This ensures the AI SDK creates separate text parts, preserving correct interleaving of prose and UI in `message.parts`.
  114. ### Improved: `defineRegistry` Actions Requirement
  115. `defineRegistry` now conditionally requires the `actions` field only when the catalog declares actions. Catalogs with no actions (e.g. `actions: {}`) no longer need to pass an empty actions object.
  116. ---
  117. ## v0.6.0
  118. February 2026
  119. ### New: Chat Mode (Inline GenUI)
  120. json-render now supports two generation modes: **Generate** (JSONL-only, the default) and **Chat** (text + JSONL inline). Chat mode lets the AI respond conversationally with embedded UI specs, ideal for chatbots and copilot experiences.
  121. ```typescript
  122. // Generate mode (default) — AI outputs only JSONL
  123. const prompt = catalog.prompt();
  124. // Chat mode — AI outputs text + JSONL inline
  125. const chatPrompt = catalog.prompt({ mode: "chat" });
  126. ```
  127. On the server, `pipeJsonRender()` separates text from JSONL patches in a mixed stream:
  128. ```typescript
  129. import { pipeJsonRender } from "@json-render/core";
  130. import { createUIMessageStream, createUIMessageStreamResponse } from "ai";
  131. const stream = createUIMessageStream({
  132. execute: async ({ writer }) => {
  133. writer.merge(pipeJsonRender(result.toUIMessageStream()));
  134. },
  135. });
  136. return createUIMessageStreamResponse({ stream });
  137. ```
  138. On the client, `useJsonRenderMessage` extracts the spec and text from message parts:
  139. ```tsx
  140. import { useJsonRenderMessage } from "@json-render/react";
  141. function ChatMessage({ message }) {
  142. const { spec, text, hasSpec } = useJsonRenderMessage(message.parts);
  143. return (
  144. <div>
  145. {text && <Markdown>{text}</Markdown>}
  146. {hasSpec && <Renderer spec={spec} registry={registry} />}
  147. </div>
  148. );
  149. }
  150. ```
  151. ### New: AI SDK Integration
  152. First-class Vercel AI SDK support with typed data parts and stream utilities.
  153. - `SpecDataPart` type for `data-spec` stream parts (patch, flat, nested payloads)
  154. - `SPEC_DATA_PART` / `SPEC_DATA_PART_TYPE` constants for type-safe part filtering
  155. - `createJsonRenderTransform()` low-level TransformStream for custom pipelines
  156. - `createMixedStreamParser()` for parsing mixed text + JSONL streams
  157. ### New: Two-Way Binding
  158. Props can now use `$bindState` and `$bindItem` expressions for two-way data binding. The renderer resolves bindings and passes a `bindings` map to components, enabling write-back to state without custom `valuePath` props.
  159. ```json
  160. {
  161. "type": "Input",
  162. "props": { "label": "Email", "value": { "$bindState": "/form/email" } }
  163. }
  164. ```
  165. ```tsx
  166. import { useBoundProp } from "@json-render/react";
  167. Input: ({ props, bindings }) => {
  168. const [value, setValue] = useBoundProp<string>(props.value, bindings?.value);
  169. return <input value={value ?? ""} onChange={(e) => setValue(e.target.value)} />;
  170. }
  171. ```
  172. ### New: Expression-Based Props and Visibility
  173. All dynamic expressions now use structured `$state`, `$item`, and `$index` objects instead of string token rewriting. This is simpler, more explicit, and works for both props and visibility conditions.
  174. **Props:**
  175. ```json
  176. { "title": { "$state": "/user/name" } }
  177. { "label": { "$item": "title" } }
  178. { "position": { "$index": true } }
  179. ```
  180. **Visibility:**
  181. ```json
  182. { "$state": "/isAdmin" }
  183. { "$state": "/role", "eq": "admin" }
  184. [{ "$state": "/isAdmin" }, { "$state": "/feature" }]
  185. { "$or": [{ "$state": "/roleA" }, { "$state": "/roleB" }] }
  186. { "$item": "isActive" }
  187. { "$index": true, "gt": 0 }
  188. ```
  189. Comparison operators: `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `not`.
  190. ### New: React Chat Hooks
  191. - `useChatUI()` — full chat hook with message history, streaming, and spec extraction
  192. - `useJsonRenderMessage()` — extract spec + text from a message's parts array
  193. - `buildSpecFromParts()` / `getTextFromParts()` — utilities for working with AI SDK message parts
  194. - `useBoundProp()` — two-way binding hook for `$bindState` / `$bindItem`
  195. ### New: Chat Example
  196. Full-featured chat example (`examples/chat`) with AI agent, tool calls (crypto, GitHub, Hacker News, weather, search), theme toggle, and streaming inline UI generation.
  197. ### Improved: Renderer Performance
  198. - `ElementRenderer` is now `React.memo`'d for better performance with repeat lists
  199. - `emit` is always defined (never `undefined`)
  200. - Repeat scope passes the actual item object, eliminating string token rewriting
  201. ### Improved: Utilities
  202. - `applySpecPatch()` — typed wrapper for applying a single patch to a Spec
  203. - `nestedToFlat()` — convert nested tree specs to flat format
  204. - `resolveBindings()` / `resolveActionParam()` — resolve binding paths and action params
  205. ### Breaking Changes
  206. - `{ $path }` and `{ path }` replaced by `{ $state }`, `{ $item }`, `{ $index }` in props
  207. - Visibility: `{ path }` -> `{ $state }`, `{ and/or/not }` -> `{ $and/$or }` with `not` as operator flag
  208. - `DynamicValue`: `{ path: string }` -> `{ $state: string }`
  209. - `repeat.path` -> `repeat.statePath`
  210. - Action params: `path` -> `statePath` in setState action
  211. - `actionHandlers` -> `handlers` on `JSONUIProvider` / `ActionProvider`
  212. - `AuthState` and `{ auth }` visibility conditions removed (model auth as regular state)
  213. - Legacy catalog API removed: `createCatalog`, `generateCatalogPrompt`, `generateSystemPrompt`
  214. - React exports removed: `createRendererFromCatalog`, `rewriteRepeatTokens`
  215. - Codegen: `traverseTree` -> `traverseSpec`
  216. See the [Migration Guide](/docs/migration) for detailed upgrade instructions.
  217. ---
  218. ## v0.5.0
  219. February 2026
  220. ### New: @json-render/react-native
  221. Full React Native renderer with 25+ standard components, data binding, visibility, actions, and dynamic props. Build AI-generated native mobile UIs with the same catalog-driven approach as web.
  222. ```tsx
  223. import { defineCatalog } from "@json-render/core";
  224. import { schema } from "@json-render/react-native/schema";
  225. import {
  226. standardComponentDefinitions,
  227. standardActionDefinitions,
  228. } from "@json-render/react-native/catalog";
  229. import { defineRegistry, Renderer } from "@json-render/react-native";
  230. const catalog = defineCatalog(schema, {
  231. components: { ...standardComponentDefinitions },
  232. actions: standardActionDefinitions,
  233. });
  234. const { registry } = defineRegistry(catalog, { components: {} });
  235. <Renderer spec={spec} registry={registry} />
  236. ```
  237. Includes standard components for layout (Container, Row, Column, ScrollContainer, SafeArea, Pressable, Spacer, Divider), content (Heading, Paragraph, Label, Image, Avatar, Badge, Chip), input (Button, TextInput, Switch, Checkbox, Slider, SearchBar), feedback (Spinner, ProgressBar), and composite (Card, ListItem, Modal).
  238. ### New: Event System
  239. Components now use `emit` to fire named events instead of directly dispatching actions. The element's `on` field maps events to action bindings, decoupling component logic from action handling.
  240. ```tsx
  241. // Component emits a named event
  242. Button: ({ props, emit }) => (
  243. <button onClick={() => emit("press")}>{props.label}</button>
  244. ),
  245. // Element spec maps events to actions
  246. {
  247. "type": "Button",
  248. "props": { "label": "Submit" },
  249. "on": { "press": { "action": "submit", "params": { "formId": "main" } } }
  250. }
  251. ```
  252. ### New: Repeat/List Rendering
  253. Elements can now iterate over state arrays using the `repeat` field. Child elements use `{ "$item": "field" }` to read from the current item and `{ "$index": true }` for the current array index.
  254. ```json
  255. {
  256. "type": "Column",
  257. "repeat": { "statePath": "/posts", "key": "id" },
  258. "children": ["post-card"]
  259. }
  260. ```
  261. ```json
  262. {
  263. "type": "Card",
  264. "props": { "title": { "$item": "title" } }
  265. }
  266. ```
  267. ### New: User Prompt Builder
  268. Build structured user prompts with optional spec refinement and state context:
  269. ```typescript
  270. import { buildUserPrompt } from "@json-render/core";
  271. // Fresh generation
  272. buildUserPrompt({ prompt: "create a todo app" });
  273. // Refinement (patch-only mode)
  274. buildUserPrompt({ prompt: "add a toggle", currentSpec: spec });
  275. // With runtime state
  276. buildUserPrompt({ prompt: "show data", state: { todos: [] } });
  277. ```
  278. ### New: Spec Validation
  279. Validate spec structure and auto-fix common issues:
  280. ```typescript
  281. import { validateSpec, autoFixSpec } from "@json-render/core";
  282. const { valid, issues } = validateSpec(spec);
  283. const fixed = autoFixSpec(spec);
  284. ```
  285. ### Improved: State Management
  286. `DataProvider` has been renamed to `StateProvider` with a clearer API. State is now a first-class part of specs. Elements can bind to state via `$state` expressions, and the built-in `setState` action updates state directly.
  287. ### Improved: AI Prompts
  288. Schema prompts now include streaming best practices, repeat/list examples, and state patching guidance. Schemas can also define `defaultRules` that are always included in generated prompts.
  289. ### Improved: Documentation
  290. - All documentation pages migrated to MDX
  291. - AI-powered documentation chat
  292. - Dynamic Open Graph images for all docs pages
  293. - Improved playground
  294. ### Breaking Changes
  295. - `DataProvider` renamed to `StateProvider`
  296. - `useData` renamed to `useStateStore`, `useDataValue` to `useStateValue`, `useDataBinding` to `useStateBinding`
  297. - `onAction` renamed to `emit` in component context
  298. - `DataModel` type renamed to `StateModel`
  299. - `Action` type renamed to `ActionBinding` (old name still available but deprecated)
  300. ---
  301. ## v0.4.0
  302. February 2026
  303. ### New: Custom Schema System
  304. Create custom output formats with `defineSchema`. Each renderer now defines its own schema, enabling completely different spec formats for different use cases.
  305. ```typescript
  306. import { defineSchema } from "@json-render/core";
  307. const mySchema = defineSchema((s) => ({
  308. spec: s.object({
  309. pages: s.array(s.object({
  310. title: s.string(),
  311. blocks: s.array(s.ref("catalog.blocks")),
  312. })),
  313. }),
  314. catalog: s.object({
  315. blocks: s.map({ props: s.zod(), description: s.string() }),
  316. }),
  317. }), {
  318. promptTemplate: myPromptTemplate,
  319. });
  320. ```
  321. ### New: Component Slots
  322. Components can now define which slots they accept. Use `["default"]` for regular children, or named slots like `["header", "footer"]` for more complex layouts.
  323. ```typescript
  324. const catalog = defineCatalog(schema, {
  325. components: {
  326. Card: {
  327. props: z.object({ title: z.string() }),
  328. slots: ["default"], // accepts children
  329. description: "A card container",
  330. },
  331. Layout: {
  332. props: z.object({}),
  333. slots: ["header", "content", "footer"], // named slots
  334. description: "Page layout with header, content, footer",
  335. },
  336. },
  337. });
  338. ```
  339. ### New: AI Prompt Generation
  340. Catalogs now generate AI system prompts automatically with `catalog.prompt()`. The prompt includes all component definitions, props schemas, and action descriptions - ensuring the AI only generates valid specs.
  341. ```typescript
  342. import { defineCatalog } from "@json-render/core";
  343. import { schema } from "@json-render/react/schema";
  344. const catalog = defineCatalog(schema, {
  345. components: { /* ... */ },
  346. actions: { /* ... */ },
  347. });
  348. // Generate system prompt for AI
  349. const systemPrompt = catalog.prompt();
  350. // Use with any AI SDK
  351. const result = await streamText({
  352. model: "claude-haiku-4.5",
  353. system: systemPrompt,
  354. prompt: userMessage,
  355. });
  356. ```
  357. ### New: @json-render/remotion
  358. Generate AI-powered videos with Remotion. Define video catalogs, stream timeline specs, and render with the Remotion Player.
  359. ```tsx
  360. import { Player } from "@remotion/player";
  361. import { Renderer, schema, standardComponentDefinitions } from "@json-render/remotion";
  362. const catalog = defineCatalog(schema, {
  363. components: standardComponentDefinitions,
  364. transitions: standardTransitionDefinitions,
  365. });
  366. <Player
  367. component={Renderer}
  368. inputProps={{ spec }}
  369. durationInFrames={spec.composition.durationInFrames}
  370. fps={spec.composition.fps}
  371. compositionWidth={spec.composition.width}
  372. compositionHeight={spec.composition.height}
  373. />
  374. ```
  375. Includes 10 standard video components (TitleCard, TypingText, SplitScreen, etc.), 7 transition types, and the ClipWrapper utility for custom components.
  376. ### New: SpecStream
  377. SpecStream is json-render's streaming format for progressively building specs from JSONL patches. The new compiler API makes it easy to process streaming AI responses.
  378. ```typescript
  379. import { createSpecStreamCompiler } from "@json-render/core";
  380. const compiler = createSpecStreamCompiler<MySpec>();
  381. // Process streaming chunks
  382. const { result, newPatches } = compiler.push(chunk);
  383. setSpec(result); // Update UI with partial result
  384. ```
  385. ### Improved: Dashboard Example
  386. The dashboard example is now a full-featured accounting dashboard with:
  387. - Persistent SQLite database with Drizzle ORM
  388. - RESTful API for customers, invoices, expenses, accounts
  389. - Draggable widget reordering
  390. - AI-powered widget generation with streaming
  391. - Real data binding to database records
  392. ### Improved: Documentation
  393. - Interactive playground for testing specs
  394. - New guides: Custom Schema, Streaming, Code Export
  395. - Full API reference for all packages
  396. - Integration guides: A2UI, AG-UI, Adaptive Cards, OpenAPI
  397. ### Breaking Changes
  398. - `UITree` type renamed to `Spec`
  399. - Schema is now imported from renderer packages (`@json-render/react`) not core
  400. - `defineCatalog` now requires a schema as first argument
  401. ---
  402. ## v0.3.0
  403. January 2026
  404. Internal release with codegen foundations.
  405. - Added `@json-render/codegen` package (spec traversal and JSX serialization)
  406. - Configurable AI model via environment variables
  407. - Documentation improvements and bug fixes
  408. *Note: Only @json-render/core was published to npm for this release.*
  409. ---
  410. ## v0.2.0
  411. January 2026
  412. Initial public release.
  413. - Core catalog and spec types
  414. - React renderer with contexts for data, actions, visibility
  415. - AI prompt generation from catalogs
  416. - Basic streaming support
  417. - Dashboard example application