Skip to content

Commit 36f1a1c

Browse files
committed
feat: improve ui
1 parent dbf92e1 commit 36f1a1c

File tree

18 files changed

+425
-259
lines changed

18 files changed

+425
-259
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ packages/kit/skills
1919
*.tsbuildinfo
2020
docs/.vitepress/cache
2121
.turbo
22+
.context

docs/kit/logs.md

Lines changed: 21 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The Logs system allows plugins to emit structured log entries from both the serv
44

55
## Use Cases
66

7-
- **Accessibility audits** — Run axe or similar tools on the client side, report warnings with element positions and autofix suggestions
7+
- **Accessibility audits** — Run axe or similar tools on the client side, report warnings with element positions
88
- **Runtime errors** — Capture and display errors with stack traces
99
- **Linting & testing** — Run ESLint or test runners alongside the dev server and surface results with file positions
1010
- **Notifications** — Short-lived messages like "URL copied" that auto-dismiss
@@ -19,7 +19,6 @@ The Logs system allows plugins to emit structured log entries from both the serv
1919
| `stacktrace` | `string` | No | Stack trace string |
2020
| `filePosition` | `{ file, line?, column? }` | No | Source file location (clickable in the panel) |
2121
| `elementPosition` | `{ selector?, boundingBox?, description? }` | No | DOM element position info |
22-
| `autofix` | `{ type: 'rpc', name: string } \| Function` | No | Autofix action |
2322
| `notify` | `boolean` | No | Show as a toast notification |
2423
| `category` | `string` | No | Grouping category (e.g., `'a11y'`, `'lint'`) |
2524
| `labels` | `string[]` | No | Tags for filtering |
@@ -28,55 +27,53 @@ The Logs system allows plugins to emit structured log entries from both the serv
2827
| `status` | `'loading' \| 'idle'` | No | Status indicator (shows spinner when `'loading'`) |
2928
| `id` | `string` | No | Explicit id for deduplication — re-adding with the same id updates the existing entry |
3029

30+
The `source` field is automatically set to `'server'` or `'client'` depending on where the log was emitted.
31+
3132
## Server-Side Usage
3233

33-
In your plugin's `devtools.setup`, use `context.logs` to emit log entries. The `add()` method returns a **handle** with `.update()` and `.dismiss()` helpers:
34+
In your plugin's `devtools.setup`, use `context.logs` to emit log entries:
3435

3536
```ts
3637
export function myPlugin() {
3738
return {
3839
name: 'my-plugin',
3940
devtools: {
40-
async setup(context) {
41+
setup(context) {
4142
// Simple log
42-
await context.logs.add({
43+
context.logs.add({
4344
message: 'Plugin initialized',
4445
level: 'info',
4546
})
4647

4748
// Log with loading state, then update
48-
const log = await context.logs.add({
49+
const entry = context.logs.add({
50+
id: 'my-build',
4951
message: 'Building...',
5052
level: 'info',
5153
status: 'loading',
5254
})
5355

54-
// Later, update via the handle
55-
await log.update({
56+
// Later, update via update()
57+
context.logs.update(entry.id, {
5658
message: 'Build complete',
5759
level: 'success',
5860
status: 'idle',
5961
})
60-
61-
// Or dismiss it
62-
await log.dismiss()
6362
},
6463
},
6564
}
6665
}
6766
```
6867

69-
The `source` field is automatically set to the plugin name.
70-
7168
## Client-Side Usage
7269

73-
In dock action scripts, use `context.logs`the same API as on the server:
70+
In dock action scripts, use `context.logs`an async client that communicates via RPC:
7471

7572
```ts
7673
import type { DockClientScriptContext } from '@vitejs/devtools-kit/client'
7774

7875
export default async function (context: DockClientScriptContext) {
79-
const log1 = await context.logs.add({
76+
const log = await context.logs.add({
8077
message: 'Running audit...',
8178
level: 'info',
8279
status: 'loading',
@@ -86,19 +83,17 @@ export default async function (context: DockClientScriptContext) {
8683

8784
// ... do work ...
8885

89-
await log1.update({
86+
await log.update({
9087
message: 'Audit complete — 3 issues found',
9188
level: 'warn',
9289
status: 'idle',
9390
})
9491
}
9592
```
9693

97-
The `source` is automatically set to the dock entry id.
94+
## Log Handle (Client-Side)
9895

99-
## Log Handle
100-
101-
`context.logs.add()` returns a `DevToolsLogHandle` with:
96+
`context.logs.add()` on the client returns a `DevToolsLogHandle` with:
10297

10398
| Property/Method | Description |
10499
|-----------------|-------------|
@@ -109,62 +104,22 @@ The `source` is automatically set to the dock entry id.
109104

110105
## Deduplication
111106

112-
When you call `context.logs.add()` with an explicit `id` that already exists, the existing entry is **updated** instead of duplicated. This is useful for logs that represent ongoing operations:
107+
When you call `add()` with an explicit `id` that already exists, the existing entry is **updated** instead of duplicated. This is useful for logs that represent ongoing operations:
113108

114109
```ts
115110
// First call creates the entry
116-
await context.logs.add({ id: 'my-scan', message: 'Scanning...', level: 'info', status: 'loading' })
111+
context.logs.add({ id: 'my-scan', message: 'Scanning...', level: 'info', status: 'loading' })
117112

118113
// Second call with same id updates it
119-
await context.logs.add({ id: 'my-scan', message: 'Scan complete', level: 'success', status: 'idle' })
120-
```
121-
122-
## Autofix
123-
124-
Autofix actions let users fix issues with a single click. There are two approaches:
125-
126-
### RPC-Based Autofix
127-
128-
Register an RPC function for the fix, then reference it by name:
129-
130-
```ts
131-
context.rpc.register(defineRpcFunction({
132-
name: 'my-plugin:fix-deprecated-api',
133-
type: 'action',
134-
setup: () => ({
135-
async handler() {
136-
// Perform the fix
137-
},
138-
}),
139-
}))
140-
141-
await context.logs.add({
142-
message: 'Deprecated API usage',
143-
level: 'warn',
144-
autofix: { type: 'rpc', name: 'my-plugin:fix-deprecated-api' },
145-
})
146-
```
147-
148-
### Function Autofix
149-
150-
For server-side plugins, you can pass a function directly:
151-
152-
```ts
153-
await context.logs.add({
154-
message: 'Missing configuration',
155-
level: 'warn',
156-
autofix: async () => {
157-
// Write the config file
158-
},
159-
})
114+
context.logs.add({ id: 'my-scan', message: 'Scan complete', level: 'success', status: 'idle' })
160115
```
161116

162117
## Toast Notifications
163118

164119
Set `notify: true` to show the log entry as a toast notification overlay. Toasts appear regardless of whether the Logs panel is open.
165120

166121
```ts
167-
await context.logs.add({
122+
context.logs.add({
168123
message: 'URL copied to clipboard',
169124
level: 'success',
170125
notify: true,
@@ -178,10 +133,10 @@ The default auto-dismiss time for toasts is 5 seconds.
178133

179134
```ts
180135
// Remove a specific log by id
181-
await context.logs.remove(entryId)
136+
context.logs.remove(entryId)
182137

183138
// Clear all logs
184-
await context.logs.clear()
139+
context.logs.clear()
185140
```
186141

187142
Logs have a maximum capacity of 1000 entries. When the limit is reached, the oldest entries are automatically removed.

packages/core/playground/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRouter, createWebHistory } from 'vue-router'
33
import { routes } from 'vue-router/auto-routes'
44

55
import App from './App.vue'
6+
import 'virtual:uno.css'
67
import './style.css'
78

89
const router = createRouter({

0 commit comments

Comments
 (0)