Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/shy-donuts-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@json-render/shadcn-svelte": minor
---

Add a new `@json-render/shadcn-svelte` package with 36 pre-built shadcn-svelte components, catalog definitions, and Svelte renderer adapters for json-render.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ out/
build
dist
*.tsbuildinfo
.svelte-kit/


# Debug
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Generate dynamic, personalized UIs from prompts without sacrificing reliability.
npm install @json-render/core @json-render/react
# for React with pre-built shadcn/ui components
npm install @json-render/shadcn
# for Svelte with pre-built shadcn-svelte components
npm install @json-render/shadcn-svelte
# or for React Native
npm install @json-render/core @json-render/react-native
# or for video
Expand Down Expand Up @@ -113,8 +115,10 @@ function Dashboard({ spec }) {
|---------|-------------|
| `@json-render/core` | Schemas, catalogs, AI prompts, dynamic props, SpecStream utilities |
| `@json-render/react` | React renderer, contexts, hooks |
| `@json-render/svelte` | Svelte 5 renderer, providers, and helpers |
| `@json-render/vue` | Vue 3 renderer, composables, providers |
| `@json-render/shadcn` | 36 pre-built shadcn/ui components (Radix UI + Tailwind CSS) |
| `@json-render/shadcn-svelte` | 36 pre-built shadcn-svelte components (Svelte 5 + Tailwind CSS) |
| `@json-render/react-native` | React Native renderer with standard mobile components |
| `@json-render/remotion` | Remotion video renderer, timeline schema |
| `@json-render/react-pdf` | React PDF renderer for generating PDF documents from specs |
Expand Down Expand Up @@ -394,8 +398,9 @@ pnpm dev
- http://dashboard-demo.json-render.localhost:1355 - Example Dashboard
- http://remotion-demo.json-render.localhost:1355 - Remotion Video Example
- Chat Example: run `pnpm dev` in `examples/chat`
- Svelte Example: run `pnpm dev` in `examples/svelte` or `examples/svelte-chat`
- Vue Example: run `pnpm dev` in `examples/vue`
- Vite Renderers (React + Vue): run `pnpm dev` in `examples/vite-renderers`
- Vite Renderers (React + Vue + Svelte): run `pnpm dev` in `examples/vite-renderers`
- React Native example: run `npx expo start` in `examples/react-native`

## How It Works
Expand Down
59 changes: 59 additions & 0 deletions apps/web/app/(main)/docs/api/shadcn-svelte/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { pageMetadata } from "@/lib/page-metadata"
export const metadata = pageMetadata("docs/api/shadcn-svelte")

# @json-render/shadcn-svelte

Pre-built [shadcn-svelte](https://www.shadcn-svelte.com/) components for json-render. 36 components built on Svelte 5 + Tailwind CSS, ready to use with `schema.createCatalog` and `defineRegistry`.

## Installation

```bash
npm install @json-render/shadcn-svelte @json-render/core @json-render/svelte zod
```

Your app must have Tailwind CSS configured.

## Entry Points

| Entry Point | Exports | Use For |
|-------------|---------|---------|
| `@json-render/shadcn-svelte` | `shadcnComponents`, `shadcnComponentDefinitions` | Svelte implementations + shared definitions |
| `@json-render/shadcn-svelte/catalog` | `shadcnComponentDefinitions` | Catalog schemas (server-safe, no renderer dependency) |

## Usage

Pick the components you need from the standard definitions:

```typescript
import { schema } from "@json-render/svelte/schema";
import { shadcnComponentDefinitions } from "@json-render/shadcn-svelte/catalog";
import { defineRegistry } from "@json-render/svelte";
import { shadcnComponents } from "@json-render/shadcn-svelte";

const catalog = schema.createCatalog({
components: {
Card: shadcnComponentDefinitions.Card,
Stack: shadcnComponentDefinitions.Stack,
Heading: shadcnComponentDefinitions.Heading,
Button: shadcnComponentDefinitions.Button,
Input: shadcnComponentDefinitions.Input,
},
actions: {},
});

const { registry } = defineRegistry(catalog, {
components: {
Card: shadcnComponents.Card,
Stack: shadcnComponents.Stack,
Heading: shadcnComponents.Heading,
Button: shadcnComponents.Button,
Input: shadcnComponents.Input,
},
});
```

## Notes

- Built-in state actions (`setState`, `pushState`, `removeState`, `validateForm`) come from `@json-render/svelte`
- Components rely on Tailwind utility classes and design tokens
- Form components support `checks` and `validateOn` validation timing
126 changes: 126 additions & 0 deletions apps/web/app/(main)/docs/api/svelte/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { pageMetadata } from "@/lib/page-metadata"
export const metadata = pageMetadata("docs/api/svelte")

# @json-render/svelte

Svelte 5 components, providers, and helpers for rendering json-render specs.

## Installation

<PackageInstall packages="@json-render/core @json-render/svelte" />

Peer dependencies: `svelte ^5.0.0` and `zod ^4.0.0`.

<PackageInstall packages="svelte zod" />

## Components

### Renderer

```svelte
<Renderer
spec={spec} // Spec | null
registry={registry}
loading={false}
/>
```

Renders a spec with your component registry. If `spec` is `null`, it renders nothing.

### JsonUIProvider

Convenience wrapper around `StateProvider`, `VisibilityProvider`, `ValidationProvider`, and `ActionProvider`.

```svelte
<JsonUIProvider
initialState={{}}
handlers={handlers}
validationFunctions={validationFunctions}
>
<Renderer {spec} {registry} />
</JsonUIProvider>
```

## defineRegistry

Create a typed component registry and action handlers from a catalog.

```typescript
import { defineRegistry } from "@json-render/svelte";

const { registry, handlers, executeAction } = defineRegistry(catalog, {
components: {
Card,
Button,
},
actions: {
submit: async (params, setState, state) => {
// custom action logic
},
},
});
```

`handlers` is designed for `JsonUIProvider`/`ActionProvider`. `executeAction` is an imperative helper.

## Component Props

Registry components receive `BaseComponentProps<TProps>`:

```typescript
interface BaseComponentProps<TProps> {
props: TProps;
children?: Snippet;
emit: (event: string) => void;
bindings?: Record<string, string>;
loading?: boolean;
}
```

Use `emit("eventName")` to trigger handlers declared in the spec `on` bindings.

## Context Helpers

Use these helpers inside Svelte components:

- `getStateValue(path)` - read/write state via `.current`
- `getBoundProp(() => value, () => bindingPath)` - write back resolved `$bindState` / `$bindItem` values
- `isVisible(condition)` - evaluate visibility via `.current`
- `getAction(name)` - read a registered action handler via `.current`
- `getFieldValidation(ctx, path, config)` - get field validation state + actions

For advanced usage, access full contexts:

- `getStateContext()`
- `getActionContext()`
- `getVisibilityContext()`
- `getValidationContext()`
- `getOptionalValidationContext()`

## Streaming

### createUIStream

```typescript
const stream = createUIStream({
api: "/api/generate-ui",
onComplete: (spec) => console.log(spec),
});

await stream.send("Create a login form");

console.log(stream.spec);
console.log(stream.isStreaming);
```

### createChatUI

```typescript
const chat = createChatUI({ api: "/api/chat-ui" });
await chat.send("Build a settings panel");
console.log(chat.messages, chat.isStreaming);
```

## Schema Export

Use `schema` from `@json-render/svelte` when defining catalogs for Svelte specs.
8 changes: 8 additions & 0 deletions apps/web/app/(main)/docs/installation/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ Peer dependencies: `vue ^3.5.0` and `zod ^4.0.0`.

<PackageInstall packages="vue zod" />

## For Svelte

<PackageInstall packages="@json-render/core @json-render/svelte" />

Peer dependencies: `svelte ^5.0.0` and `zod ^4.0.0`.

<PackageInstall packages="svelte zod" />

## For React UI with shadcn/ui

Pre-built components for fast prototyping and production use:
Expand Down
9 changes: 8 additions & 1 deletion apps/web/lib/docs-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ export const docsNavigation: NavSection[] = [
href: "https://github.com/vercel-labs/json-render/tree/main/examples/remotion",
external: true,
},
{
title: "Svelte",
href: "https://github.com/vercel-labs/json-render/tree/main/examples/svelte",
external: true,
},
{
title: "Vue",
href: "https://github.com/vercel-labs/json-render/tree/main/examples/vue",
external: true,
},
{
title: "Renders with Vite (Vue / React)",
title: "Renders with Vite (Vue / React / Svelte)",
href: "https://github.com/vercel-labs/json-render/tree/main/examples/vite-renderers",
external: true,
},
Expand Down Expand Up @@ -105,9 +110,11 @@ export const docsNavigation: NavSection[] = [
{ title: "@json-render/react", href: "/docs/api/react" },
{ title: "@json-render/react-pdf", href: "/docs/api/react-pdf" },
{ title: "@json-render/shadcn", href: "/docs/api/shadcn" },
{ title: "@json-render/shadcn-svelte", href: "/docs/api/shadcn-svelte" },
{ title: "@json-render/react-native", href: "/docs/api/react-native" },
{ title: "@json-render/remotion", href: "/docs/api/remotion" },
{ title: "@json-render/vue", href: "/docs/api/vue" },
{ title: "@json-render/svelte", href: "/docs/api/svelte" },
{ title: "@json-render/codegen", href: "/docs/api/codegen" },
],
},
Expand Down
2 changes: 2 additions & 0 deletions apps/web/lib/page-titles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ export const PAGE_TITLES: Record<string, string> = {
"docs/api/vue": "@json-render/vue API",
"docs/api/react-pdf": "@json-render/react-pdf API",
"docs/api/react-native": "@json-render/react-native API",
"docs/api/svelte": "@json-render/svelte API",
"docs/api/codegen": "@json-render/codegen API",
"docs/api/remotion": "@json-render/remotion API",
"docs/api/shadcn": "@json-render/shadcn API",
"docs/api/shadcn-svelte": "@json-render/shadcn-svelte API",
};

/**
Expand Down
23 changes: 23 additions & 0 deletions examples/svelte-chat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
node_modules

# Output
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
1 change: 1 addition & 0 deletions examples/svelte-chat/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
42 changes: 42 additions & 0 deletions examples/svelte-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# sv

Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```sh
# create a new project
npx sv create my-app
```

To recreate this project with the same configuration:

```sh
# recreate this project
npx sv create --template minimal --types ts --no-install svelte-chat
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```sh
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

To create a production version of your app:

```sh
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
16 changes: 16 additions & 0 deletions examples/svelte-chat/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://shadcn-svelte.com/schema.json",
"tailwind": {
"css": "src/app.css",
"baseColor": "zinc"
},
"aliases": {
"components": "$lib/components",
"utils": "$lib/utils",
"ui": "$lib/components/ui",
"hooks": "$lib/hooks",
"lib": "$lib"
},
"typescript": true,
"registry": "https://shadcn-svelte.com/registry"
}
Loading