page.mdx 18 KB

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