Skip to content

Commit cd1df67

Browse files
committed
Merge remote-tracking branch 'origin/main' into ctate/mcp
# Conflicts: # pnpm-lock.yaml
2 parents 4243637 + 5b929df commit cd1df67

File tree

199 files changed

+10640
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+10640
-449
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ out/
2727
build
2828
dist
2929
*.tsbuildinfo
30+
.svelte-kit/
3031

3132

3233
# Debug

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,9 @@ pnpm dev
463463
- http://react-email-demo.json-render.localhost:1355 - React Email Example
464464
- http://remotion-demo.json-render.localhost:1355 - Remotion Video Example
465465
- Chat Example: run `pnpm dev` in `examples/chat`
466+
- Svelte Example: run `pnpm dev` in `examples/svelte` or `examples/svelte-chat`
466467
- Vue Example: run `pnpm dev` in `examples/vue`
467-
- Vite Renderers (React + Vue): run `pnpm dev` in `examples/vite-renderers`
468+
- Vite Renderers (React + Vue + Svelte): run `pnpm dev` in `examples/vite-renderers`
468469
- React Native example: run `npx expo start` in `examples/react-native`
469470

470471
## How It Works
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { pageMetadata } from "@/lib/page-metadata"
2+
export const metadata = pageMetadata("docs/api/svelte")
3+
4+
# @json-render/svelte
5+
6+
Svelte 5 components, providers, and helpers for rendering json-render specs.
7+
8+
## Installation
9+
10+
<PackageInstall packages="@json-render/core @json-render/svelte" />
11+
12+
Peer dependencies: `svelte ^5.0.0` and `zod ^4.0.0`.
13+
14+
<PackageInstall packages="svelte zod" />
15+
16+
## Components
17+
18+
### Renderer
19+
20+
```svelte
21+
<Renderer
22+
spec={spec} // Spec | null
23+
registry={registry}
24+
loading={false}
25+
/>
26+
```
27+
28+
Renders a spec with your component registry. If `spec` is `null`, it renders nothing.
29+
30+
### JsonUIProvider
31+
32+
Convenience wrapper around `StateProvider`, `VisibilityProvider`, `ValidationProvider`, and `ActionProvider`.
33+
34+
```svelte
35+
<JsonUIProvider
36+
initialState={{}}
37+
handlers={handlers}
38+
validationFunctions={validationFunctions}
39+
>
40+
<Renderer {spec} {registry} />
41+
</JsonUIProvider>
42+
```
43+
44+
## defineRegistry
45+
46+
Create a typed component registry and action handlers from a catalog.
47+
48+
```typescript
49+
import { defineRegistry } from "@json-render/svelte";
50+
51+
const { registry, handlers, executeAction } = defineRegistry(catalog, {
52+
components: {
53+
Card,
54+
Button,
55+
},
56+
actions: {
57+
submit: async (params, setState, state) => {
58+
// custom action logic
59+
},
60+
},
61+
});
62+
```
63+
64+
`handlers` is designed for `JsonUIProvider`/`ActionProvider`. `executeAction` is an imperative helper.
65+
66+
## Component Props
67+
68+
Registry components receive `BaseComponentProps<TProps>`:
69+
70+
```typescript
71+
interface BaseComponentProps<TProps> {
72+
props: TProps;
73+
children?: Snippet;
74+
emit: (event: string) => void;
75+
bindings?: Record<string, string>;
76+
loading?: boolean;
77+
}
78+
```
79+
80+
Use `emit("eventName")` to trigger handlers declared in the spec `on` bindings.
81+
82+
## Context Helpers
83+
84+
Use these helpers inside Svelte components:
85+
86+
- `getStateValue(path)` - read/write state via `.current`
87+
- `getBoundProp(() => value, () => bindingPath)` - write back resolved `$bindState` / `$bindItem` values
88+
- `isVisible(condition)` - evaluate visibility via `.current`
89+
- `getAction(name)` - read a registered action handler via `.current`
90+
- `getFieldValidation(ctx, path, config)` - get field validation state + actions
91+
92+
For advanced usage, access full contexts:
93+
94+
- `getStateContext()`
95+
- `getActionContext()`
96+
- `getVisibilityContext()`
97+
- `getValidationContext()`
98+
- `getOptionalValidationContext()`
99+
100+
## Streaming
101+
102+
### createUIStream
103+
104+
```typescript
105+
const stream = createUIStream({
106+
api: "/api/generate-ui",
107+
onComplete: (spec) => console.log(spec),
108+
});
109+
110+
await stream.send("Create a login form");
111+
112+
console.log(stream.spec);
113+
console.log(stream.isStreaming);
114+
```
115+
116+
### createChatUI
117+
118+
```typescript
119+
const chat = createChatUI({ api: "/api/chat-ui" });
120+
await chat.send("Build a settings panel");
121+
console.log(chat.messages, chat.isStreaming);
122+
```
123+
124+
## Schema Export
125+
126+
Use `schema` from `@json-render/svelte` when defining catalogs for Svelte specs.

apps/web/app/(main)/docs/installation/page.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ Peer dependencies: `vue ^3.5.0` and `zod ^4.0.0`.
2121

2222
<PackageInstall packages="vue zod" />
2323

24+
## For Svelte
25+
26+
<PackageInstall packages="@json-render/core @json-render/svelte" />
27+
28+
Peer dependencies: `svelte ^5.0.0` and `zod ^4.0.0`.
29+
30+
<PackageInstall packages="svelte zod" />
31+
2432
## For React UI with shadcn/ui
2533

2634
Pre-built components for fast prototyping and production use:

apps/web/lib/docs-navigation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,18 @@ export const docsNavigation: NavSection[] = [
8080
href: "https://github.com/vercel-labs/json-render/tree/main/examples/image",
8181
external: true,
8282
},
83+
{
84+
title: "Svelte",
85+
href: "https://github.com/vercel-labs/json-render/tree/main/examples/svelte",
86+
external: true,
87+
},
8388
{
8489
title: "Vue",
8590
href: "https://github.com/vercel-labs/json-render/tree/main/examples/vue",
8691
external: true,
8792
},
8893
{
89-
title: "Renders with Vite (Vue / React)",
94+
title: "Renders with Vite (Vue / React / Svelte)",
9095
href: "https://github.com/vercel-labs/json-render/tree/main/examples/vite-renderers",
9196
external: true,
9297
},
@@ -126,6 +131,7 @@ export const docsNavigation: NavSection[] = [
126131
{ title: "@json-render/image", href: "/docs/api/image" },
127132
{ title: "@json-render/remotion", href: "/docs/api/remotion" },
128133
{ title: "@json-render/vue", href: "/docs/api/vue" },
134+
{ title: "@json-render/svelte", href: "/docs/api/svelte" },
129135
{ title: "@json-render/codegen", href: "/docs/api/codegen" },
130136
{ title: "@json-render/mcp", href: "/docs/api/mcp" },
131137
],

apps/web/lib/page-titles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const PAGE_TITLES: Record<string, string> = {
4545
"docs/api/react-pdf": "@json-render/react-pdf API",
4646
"docs/api/react-email": "@json-render/react-email API",
4747
"docs/api/react-native": "@json-render/react-native API",
48+
"docs/api/svelte": "@json-render/svelte API",
4849
"docs/api/codegen": "@json-render/codegen API",
4950
"docs/api/image": "@json-render/image API",
5051
"docs/api/remotion": "@json-render/remotion API",

examples/react-email/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"react-resizable-panels": "^4.4.1",
2626
"tailwind-merge": "^3.5.0",
2727
"tailwindcss": "^4.1.18",
28-
"zod": "4.3.5"
28+
"zod": "4.3.6"
2929
},
3030
"devDependencies": {
3131
"@internal/typescript-config": "workspace:*",

examples/svelte-chat/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
node_modules
2+
3+
# Output
4+
.output
5+
.vercel
6+
.netlify
7+
.wrangler
8+
/.svelte-kit
9+
/build
10+
11+
# OS
12+
.DS_Store
13+
Thumbs.db
14+
15+
# Env
16+
.env
17+
.env.*
18+
!.env.example
19+
!.env.test
20+
21+
# Vite
22+
vite.config.js.timestamp-*
23+
vite.config.ts.timestamp-*

examples/svelte-chat/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

examples/svelte-chat/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# sv
2+
3+
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
4+
5+
## Creating a project
6+
7+
If you're seeing this, you've probably already done this step. Congrats!
8+
9+
```sh
10+
# create a new project
11+
npx sv create my-app
12+
```
13+
14+
To recreate this project with the same configuration:
15+
16+
```sh
17+
# recreate this project
18+
npx sv create --template minimal --types ts --no-install svelte-chat
19+
```
20+
21+
## Developing
22+
23+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
24+
25+
```sh
26+
npm run dev
27+
28+
# or start the server and open the app in a new browser tab
29+
npm run dev -- --open
30+
```
31+
32+
## Building
33+
34+
To create a production version of your app:
35+
36+
```sh
37+
npm run build
38+
```
39+
40+
You can preview the production build with `npm run preview`.
41+
42+
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.

0 commit comments

Comments
 (0)