Skip to content

Commit 9840419

Browse files
antfuclaude
andauthored
feat: JSON Render dock type and Git UI example (#203)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dea70a1 commit 9840419

Some content is hidden

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

48 files changed

+2290
-157
lines changed

docs/.vitepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default extendConfig(withMermaid(defineConfig({
6969
{ text: 'RPC', link: '/kit/rpc' },
7070
{ text: 'Shared State', link: '/kit/shared-state' },
7171
{ text: 'Logs', link: '/kit/logs' },
72+
{ text: 'JSON Render', link: '/kit/json-render' },
7273
{ text: 'Examples', link: '/kit/examples' },
7374
],
7475
},

docs/kit/dock-system.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ Dock entries are the primary way for users to interact with your DevTools integr
88

99
## Entry Types
1010

11-
DevTools Kit supports four types of dock entries:
11+
DevTools Kit supports five types of dock entries:
1212

1313
| Type | Description | Use Case |
1414
|------|-------------|----------|
1515
| `iframe` | Displays your UI in an iframe panel | Full-featured UIs, dashboards, data visualization |
1616
| `action` | Button that triggers client-side scripts | Inspectors, toggles, one-time actions |
1717
| `custom-render` | Renders directly in the user's app DOM | When you need direct DOM access or framework integration |
1818
| `launcher` | Actionable setup card shown in panel | Run one-time setup tasks before showing other tools |
19+
| `json-render` | Renders UI from a JSON spec — no client code needed | Data panels, config viewers, simple interactive tools |
1920

2021
## Iframe Panels
2122

@@ -71,7 +72,7 @@ interface DockEntry {
7172
/** Icon URL, data URI, or Iconify icon name (e.g., 'ph:house-duotone') */
7273
icon: string
7374
/** Entry type */
74-
type: 'iframe' | 'action' | 'custom-render' | 'launcher'
75+
type: 'iframe' | 'action' | 'custom-render' | 'launcher' | 'json-render'
7576
/** URL to load in the iframe (for type: 'iframe') */
7677
url?: string
7778
/** Action configuration (for type: 'action') */
@@ -86,6 +87,8 @@ interface DockEntry {
8687
buttonStart?: string
8788
buttonLoading?: string
8889
}
90+
/** JsonRenderer handle created by ctx.createJsonRenderer() (for type: 'json-render') */
91+
ui?: JsonRenderer
8992
}
9093
```
9194

@@ -296,6 +299,48 @@ ctx.docks.register({
296299
> [!NOTE]
297300
> Built-in logs panel (`~logs`) is currently reserved and hidden while log UI is under development.
298301
302+
## JSON Render Panels
303+
304+
JSON render panels let you describe your UI as a JSON spec on the server side — **no client code needed.** This is the simplest way to add a DevTools panel.
305+
306+
Use `ctx.createJsonRenderer()` to create a renderer handle, then pass it as `ui` when registering a `json-render` dock entry:
307+
308+
```ts
309+
const ui = ctx.createJsonRenderer({
310+
root: 'root',
311+
elements: {
312+
root: {
313+
type: 'Stack',
314+
props: { direction: 'vertical', gap: 12 },
315+
children: ['heading', 'info'],
316+
},
317+
heading: {
318+
type: 'Text',
319+
props: { content: 'Hello from JSON!', variant: 'heading' },
320+
},
321+
info: {
322+
type: 'KeyValueTable',
323+
props: {
324+
entries: [
325+
{ key: 'Version', value: '1.0.0' },
326+
{ key: 'Status', value: 'Running' },
327+
],
328+
},
329+
},
330+
},
331+
})
332+
333+
ctx.docks.register({
334+
id: 'my-panel',
335+
title: 'My Panel',
336+
icon: 'ph:chart-bar-duotone',
337+
type: 'json-render',
338+
ui,
339+
})
340+
```
341+
342+
See the [JSON Render](/kit/json-render) page for the full component reference, dynamic updates, actions, state bindings, and examples.
343+
299344
## Communication with Server
300345

301346
All client scripts (actions and custom renderers) can communicate with the server using [RPC](./rpc):

docs/kit/examples.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,18 @@ A file explorer dock that lists, reads, and writes files through RPC.
3232
- Detecting backend mode (`websocket` vs `static`) on the client
3333

3434
**Source:** [`examples/plugin-file-explorer`](https://github.com/vitejs/devtools/tree/main/examples/plugin-file-explorer)
35+
36+
## Git UI
37+
38+
An interactive Git panel built entirely with server-side JSON specs — no client code at all.
39+
40+
**Features demonstrated:**
41+
42+
- Using the `json-render` dock type for zero-client-code panels
43+
- Building a `JsonRenderSpec` from server-side data (git branch, status, log)
44+
- Dynamic spec updates via shared state (`sharedStateKey`)
45+
- Button actions bridged to RPC functions (`git-ui:refresh`, `git-ui:commit`)
46+
- Text input with `$bindState` two-way binding and `$state` in action params
47+
- Updating dock badge text reactively
48+
49+
**Source:** [`examples/plugin-git-ui`](https://github.com/vitejs/devtools/tree/main/examples/plugin-git-ui)

0 commit comments

Comments
 (0)