@u-devtools/core 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/README.md +119 -0
- package/dist/index.cjs.js +46 -1
- package/dist/index.d.ts +871 -64
- package/dist/index.es.js +3113 -56
- package/dist/vite/vite.config.base.cjs.js +1 -0
- package/dist/vite/vite.config.base.d.ts +59 -0
- package/dist/vite/vite.config.base.js +91 -0
- package/dist/vite.config.base.d.ts +42 -0
- package/package.json +26 -18
- package/src/bridge-app.ts +198 -51
- package/src/control.ts +23 -52
- package/src/event-bus.ts +126 -0
- package/src/index.ts +476 -44
- package/src/schemas/rpc.ts +36 -0
- package/src/schemas/settings.ts +125 -0
- package/src/transport.ts +172 -0
- package/src/transports/broadcast-transport.ts +174 -0
- package/src/transports/hmr-transport.ts +82 -0
- package/src/transports/websocket-transport.ts +158 -0
- package/vite/vite.config.base.ts +81 -14
- package/vite/clean-timestamp-plugin.ts +0 -28
package/src/index.ts
CHANGED
|
@@ -1,107 +1,225 @@
|
|
|
1
|
+
// Forward reference for AppBridge (exported at the end of file)
|
|
2
|
+
import type { AppBridge } from './bridge-app';
|
|
3
|
+
|
|
1
4
|
// --- RPC Interfaces ---
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* RPC message structure for communication between Server and Client contexts.
|
|
8
|
+
* Used for typed RPC over WebSocket (Server ↔ Client).
|
|
9
|
+
*
|
|
10
|
+
* @template T - Type of the payload data
|
|
11
|
+
*/
|
|
2
12
|
export interface RpcMessage<T = unknown> {
|
|
13
|
+
/** Unique message identifier */
|
|
3
14
|
id: string;
|
|
15
|
+
/** Message type: 'request' for RPC calls, 'response' for replies, 'event' for broadcasts */
|
|
4
16
|
type: 'request' | 'response' | 'event';
|
|
17
|
+
/** RPC method name (for requests) */
|
|
5
18
|
method?: string;
|
|
19
|
+
/** Message payload data */
|
|
6
20
|
payload?: T;
|
|
21
|
+
/** Error information (for error responses) */
|
|
7
22
|
error?: unknown;
|
|
8
23
|
}
|
|
9
24
|
|
|
25
|
+
/**
|
|
26
|
+
* RPC Client Interface for making remote procedure calls.
|
|
27
|
+
* Provides methods to call server methods and subscribe to events.
|
|
28
|
+
*
|
|
29
|
+
* Communication: Server ↔ Client via WebSocket (Vite HMR or custom WebSocket)
|
|
30
|
+
*/
|
|
10
31
|
export interface RpcClientInterface {
|
|
32
|
+
/**
|
|
33
|
+
* Call a remote method on the server.
|
|
34
|
+
* @param method - Method name (e.g., 'sys:getPlugins')
|
|
35
|
+
* @param payload - Optional payload data
|
|
36
|
+
* @returns Promise that resolves with the method result
|
|
37
|
+
* @template T - Return type of the method
|
|
38
|
+
*/
|
|
11
39
|
call<T = unknown>(method: string, payload?: unknown): Promise<T>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Subscribe to events from the server.
|
|
43
|
+
* @param event - Event name
|
|
44
|
+
* @param callback - Callback function to handle events
|
|
45
|
+
* @returns Function to unsubscribe from the event
|
|
46
|
+
*/
|
|
12
47
|
on(event: string, callback: (data: unknown) => void): () => void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Unsubscribe from events (optional, some transports may not support it).
|
|
51
|
+
* @param event - Event name
|
|
52
|
+
* @param callback - Callback function to remove
|
|
53
|
+
*/
|
|
13
54
|
off?(event: string, callback: (data: unknown) => void): void;
|
|
14
55
|
}
|
|
15
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Command definition for Command Palette (accessible via Cmd+K / Ctrl+K).
|
|
59
|
+
* Commands allow users to quickly access plugin functionality.
|
|
60
|
+
*/
|
|
16
61
|
export interface PluginCommand {
|
|
62
|
+
/** Unique command identifier (e.g., 'my-plugin:clear') */
|
|
17
63
|
id: string;
|
|
64
|
+
/** Display label in command palette */
|
|
18
65
|
label: string;
|
|
66
|
+
/** Heroicons icon name (optional) */
|
|
19
67
|
icon?: string;
|
|
68
|
+
/** Action to execute when command is triggered */
|
|
20
69
|
action: () => void | Promise<void>;
|
|
70
|
+
/** Keyboard shortcut keys (e.g., ['Meta', 'K', 'C']) */
|
|
21
71
|
shortcut?: string[];
|
|
22
72
|
}
|
|
23
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Storage API for plugin-specific persistent storage.
|
|
76
|
+
* Used for internal plugin state (e.g., last opened file, view preferences).
|
|
77
|
+
* Storage is isolated per plugin and persists across sessions.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import type { StorageApi } from '@u-devtools/core';
|
|
82
|
+
*
|
|
83
|
+
* function useStorage(api: StorageApi) {
|
|
84
|
+
* // Store values
|
|
85
|
+
* api.set('lastView', 'list');
|
|
86
|
+
* api.set('filters', { category: 'all', sort: 'name' });
|
|
87
|
+
* api.set('items', ['item1', 'item2', 'item3']);
|
|
88
|
+
*
|
|
89
|
+
* // Retrieve values with defaults
|
|
90
|
+
* const lastView = api.get('lastView', 'default');
|
|
91
|
+
* const filters = api.get('filters', { category: 'all' });
|
|
92
|
+
* const items = api.get<string[]>('items', []);
|
|
93
|
+
*
|
|
94
|
+
* // Remove values
|
|
95
|
+
* api.remove('lastView');
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
24
99
|
export interface StorageApi {
|
|
100
|
+
/**
|
|
101
|
+
* Get a stored value.
|
|
102
|
+
* @param key - Storage key
|
|
103
|
+
* @param def - Default value if key doesn't exist
|
|
104
|
+
* @returns Stored value or default
|
|
105
|
+
* @template T - Type of the stored value
|
|
106
|
+
*/
|
|
25
107
|
get<T>(key: string, def: T): T;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Set a stored value.
|
|
111
|
+
* @param key - Storage key
|
|
112
|
+
* @param value - Value to store
|
|
113
|
+
* @template T - Type of the value
|
|
114
|
+
*/
|
|
26
115
|
set<T>(key: string, value: T): void;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Remove a stored value.
|
|
119
|
+
* @param key - Storage key to remove
|
|
120
|
+
*/
|
|
27
121
|
remove(key: string): void;
|
|
28
122
|
}
|
|
29
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Settings API for user-configurable plugin settings.
|
|
126
|
+
* Settings are displayed in DevTools settings panel and persist across sessions.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* import type { SettingsApi } from '@u-devtools/core';
|
|
131
|
+
*
|
|
132
|
+
* function useSettings(api: SettingsApi) {
|
|
133
|
+
* // Get setting with default
|
|
134
|
+
* const fontSize = api.get('fontSize', 14);
|
|
135
|
+
* const theme = api.get('theme', 'dark');
|
|
136
|
+
* const enabled = api.get('enabled', true);
|
|
137
|
+
*
|
|
138
|
+
* // Set settings
|
|
139
|
+
* api.set('fontSize', 16);
|
|
140
|
+
* api.set('theme', 'light');
|
|
141
|
+
* api.set('enabled', false);
|
|
142
|
+
*
|
|
143
|
+
* // Access all settings reactively (for Vue bindings)
|
|
144
|
+
* const allSettings = api.all;
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
30
148
|
export interface SettingsApi {
|
|
31
149
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @param key
|
|
34
|
-
* @param defaultValue
|
|
150
|
+
* Get a setting value.
|
|
151
|
+
* @param key Setting key (without plugin prefix)
|
|
152
|
+
* @param defaultValue Default value if setting is not set
|
|
35
153
|
*/
|
|
36
154
|
get<T>(key: string, defaultValue?: T): T;
|
|
37
155
|
|
|
38
156
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param key
|
|
41
|
-
* @param value
|
|
157
|
+
* Set a setting value.
|
|
158
|
+
* @param key Setting key
|
|
159
|
+
* @param value New value
|
|
42
160
|
*/
|
|
43
161
|
set(key: string, value: unknown): void;
|
|
44
162
|
|
|
45
163
|
/**
|
|
46
|
-
*
|
|
164
|
+
* Reactive object of all settings (for UI bindings)
|
|
47
165
|
*/
|
|
48
166
|
all: Record<string, unknown>;
|
|
49
167
|
}
|
|
50
168
|
|
|
51
169
|
export interface ShortcutApi {
|
|
52
170
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param keys
|
|
55
|
-
* @param action
|
|
56
|
-
* @returns
|
|
171
|
+
* Register a keyboard shortcut.
|
|
172
|
+
* @param keys Array of keys (e.g., ['Meta', 'K'])
|
|
173
|
+
* @param action Action to execute on key press
|
|
174
|
+
* @returns Function to unregister the shortcut
|
|
57
175
|
*/
|
|
58
176
|
register(keys: string[], action: () => void): () => void;
|
|
59
177
|
}
|
|
60
178
|
|
|
61
179
|
export interface ClipboardApi {
|
|
62
180
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @param text
|
|
65
|
-
* @param successMessage
|
|
181
|
+
* Copy text to clipboard.
|
|
182
|
+
* @param text Text to copy
|
|
183
|
+
* @param successMessage Success message (optional)
|
|
66
184
|
*/
|
|
67
185
|
copy(text: string, successMessage?: string): Promise<void>;
|
|
68
186
|
|
|
69
187
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @returns
|
|
188
|
+
* Read text from clipboard.
|
|
189
|
+
* @returns Text from clipboard or empty string on error
|
|
72
190
|
*/
|
|
73
191
|
read(): Promise<string>;
|
|
74
192
|
}
|
|
75
193
|
|
|
76
194
|
export interface EventBusApi {
|
|
77
195
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param event
|
|
80
|
-
* @param data
|
|
196
|
+
* Emit an event.
|
|
197
|
+
* @param event Event name
|
|
198
|
+
* @param data Event data
|
|
81
199
|
*/
|
|
82
200
|
emit(event: string, data?: unknown): void;
|
|
83
201
|
|
|
84
202
|
/**
|
|
85
|
-
*
|
|
86
|
-
* @param event
|
|
87
|
-
* @param handler
|
|
88
|
-
* @returns
|
|
203
|
+
* Subscribe to an event.
|
|
204
|
+
* @param event Event name
|
|
205
|
+
* @param handler Event handler
|
|
206
|
+
* @returns Function to unsubscribe
|
|
89
207
|
*/
|
|
90
208
|
on(event: string, handler: (data: unknown) => void): () => void;
|
|
91
209
|
|
|
92
210
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @param event
|
|
95
|
-
* @param handler
|
|
211
|
+
* Unsubscribe from an event.
|
|
212
|
+
* @param event Event name
|
|
213
|
+
* @param handler Event handler
|
|
96
214
|
*/
|
|
97
215
|
off(event: string, handler: (data: unknown) => void): void;
|
|
98
216
|
}
|
|
99
217
|
|
|
100
218
|
export interface DialogApi {
|
|
101
219
|
/**
|
|
102
|
-
*
|
|
103
|
-
* @param options
|
|
104
|
-
* @returns Promise
|
|
220
|
+
* Show a confirmation dialog.
|
|
221
|
+
* @param options Dialog options
|
|
222
|
+
* @returns Promise with result (true if confirmed)
|
|
105
223
|
*/
|
|
106
224
|
confirm(options: {
|
|
107
225
|
title: string;
|
|
@@ -111,9 +229,9 @@ export interface DialogApi {
|
|
|
111
229
|
}): Promise<boolean>;
|
|
112
230
|
|
|
113
231
|
/**
|
|
114
|
-
*
|
|
115
|
-
* @param options
|
|
116
|
-
* @returns Promise
|
|
232
|
+
* Show an input dialog.
|
|
233
|
+
* @param options Dialog options
|
|
234
|
+
* @returns Promise with entered text or null if cancelled
|
|
117
235
|
*/
|
|
118
236
|
prompt(options: {
|
|
119
237
|
title: string;
|
|
@@ -122,58 +240,335 @@ export interface DialogApi {
|
|
|
122
240
|
}): Promise<string | null>;
|
|
123
241
|
}
|
|
124
242
|
|
|
243
|
+
export interface NavigationApi {
|
|
244
|
+
/**
|
|
245
|
+
* Switch active plugin
|
|
246
|
+
*/
|
|
247
|
+
openPlugin(pluginName: string): void;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Client API - Main API object provided to plugins in Client context.
|
|
252
|
+
* Provides access to all DevTools services: RPC, storage, settings, notifications, etc.
|
|
253
|
+
*
|
|
254
|
+
* Available in: Client context (Vue 3 iframe)
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* import type { PluginClientInstance } from '@u-devtools/core';
|
|
259
|
+
*
|
|
260
|
+
* const plugin: PluginClientInstance = {
|
|
261
|
+
* name: 'My Plugin',
|
|
262
|
+
* icon: 'Cube',
|
|
263
|
+
*
|
|
264
|
+
* renderMain(container, api) {
|
|
265
|
+
* // Use api.storage for plugin state
|
|
266
|
+
* api.storage.set('lastView', 'list');
|
|
267
|
+
* const lastView = api.storage.get('lastView', 'default');
|
|
268
|
+
*
|
|
269
|
+
* // Use api.settings for user preferences
|
|
270
|
+
* api.settings.set('fontSize', 16);
|
|
271
|
+
* const fontSize = api.settings.get('fontSize', 14);
|
|
272
|
+
*
|
|
273
|
+
* // Navigation
|
|
274
|
+
* api.navigation.openPlugin('other-plugin');
|
|
275
|
+
*
|
|
276
|
+
* // Event bus
|
|
277
|
+
* api.bus.on('other-plugin:event', (data) => {
|
|
278
|
+
* console.log('Received event:', data);
|
|
279
|
+
* });
|
|
280
|
+
* api.bus.emit('my-plugin:event', { data: 'value' });
|
|
281
|
+
*
|
|
282
|
+
* // Async operations (use async IIFE for await)
|
|
283
|
+
* (async () => {
|
|
284
|
+
* // Use api.rpc to call server methods
|
|
285
|
+
* const data = await api.rpc.call('my-plugin:getData');
|
|
286
|
+
*
|
|
287
|
+
* // Notifications
|
|
288
|
+
* api.notify('Data saved successfully', 'success');
|
|
289
|
+
*
|
|
290
|
+
* // Clipboard
|
|
291
|
+
* await api.clipboard.copy('text to copy');
|
|
292
|
+
*
|
|
293
|
+
* // Dialog
|
|
294
|
+
* const confirmed = await api.dialog.confirm({
|
|
295
|
+
* title: 'Confirm',
|
|
296
|
+
* message: 'Are you sure?',
|
|
297
|
+
* });
|
|
298
|
+
* })();
|
|
299
|
+
*
|
|
300
|
+
* return () => {}; // Cleanup function
|
|
301
|
+
* }
|
|
302
|
+
* };
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
125
305
|
export interface ClientApi {
|
|
306
|
+
/** RPC client for calling server methods */
|
|
126
307
|
rpc: RpcClientInterface;
|
|
308
|
+
/** Show a notification to the user */
|
|
127
309
|
notify: (msg: string, type?: 'info' | 'error' | 'success') => void;
|
|
128
|
-
|
|
129
|
-
|
|
310
|
+
/** Storage API for plugin-specific persistent state (e.g., last opened file) */
|
|
311
|
+
storage: StorageApi;
|
|
312
|
+
/** Settings API for user-configurable preferences (e.g., font size, theme) */
|
|
313
|
+
settings: SettingsApi;
|
|
314
|
+
/** Keyboard shortcuts API */
|
|
130
315
|
shortcuts: ShortcutApi;
|
|
316
|
+
/** Clipboard operations API */
|
|
131
317
|
clipboard: ClipboardApi;
|
|
318
|
+
/** Event bus for plugin-to-plugin communication */
|
|
132
319
|
bus: EventBusApi;
|
|
320
|
+
/** Dialog API for confirmations and prompts */
|
|
133
321
|
dialog: DialogApi;
|
|
322
|
+
/** Navigation API for switching between plugins */
|
|
323
|
+
navigation: NavigationApi;
|
|
134
324
|
}
|
|
135
325
|
|
|
136
326
|
// --- Plugin Interfaces ---
|
|
137
327
|
export type UnmountFn = () => void;
|
|
138
328
|
|
|
329
|
+
/**
|
|
330
|
+
* Setting type for plugin settings schema.
|
|
331
|
+
* Defines the input type for user-configurable settings.
|
|
332
|
+
*/
|
|
139
333
|
export type SettingType = 'string' | 'number' | 'boolean' | 'select' | 'array';
|
|
140
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Setting schema definition for a single setting.
|
|
337
|
+
* Used to define user-configurable settings that appear in the DevTools settings panel.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```typescript
|
|
341
|
+
* const pluginWithSettings: PluginClientInstance = {
|
|
342
|
+
* name: 'My Plugin',
|
|
343
|
+
* icon: 'Cube',
|
|
344
|
+
*
|
|
345
|
+
* settings: {
|
|
346
|
+
* fontSize: {
|
|
347
|
+
* label: 'Font Size',
|
|
348
|
+
* description: 'Base font size for the plugin',
|
|
349
|
+
* type: 'number',
|
|
350
|
+
* default: 14,
|
|
351
|
+
* },
|
|
352
|
+
* theme: {
|
|
353
|
+
* label: 'Theme',
|
|
354
|
+
* type: 'select',
|
|
355
|
+
* default: 'dark',
|
|
356
|
+
* options: [
|
|
357
|
+
* { label: 'Dark', value: 'dark' },
|
|
358
|
+
* { label: 'Light', value: 'light' },
|
|
359
|
+
* ],
|
|
360
|
+
* },
|
|
361
|
+
* },
|
|
362
|
+
*
|
|
363
|
+
* renderMain(container, api) {
|
|
364
|
+
* // Access settings
|
|
365
|
+
* const fontSize = api.settings.get('fontSize', 14);
|
|
366
|
+
* const theme = api.settings.get('theme', 'dark');
|
|
367
|
+
*
|
|
368
|
+
* return () => {};
|
|
369
|
+
* }
|
|
370
|
+
* };
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
141
373
|
export interface SettingSchemaDef {
|
|
374
|
+
/** Display label for the setting */
|
|
142
375
|
label: string;
|
|
376
|
+
/** Optional description/tooltip text */
|
|
143
377
|
description?: string;
|
|
378
|
+
/** Setting type (determines input component) */
|
|
144
379
|
type: SettingType;
|
|
380
|
+
/** Default value */
|
|
145
381
|
default?: unknown;
|
|
146
|
-
|
|
382
|
+
/** Options for 'select' type settings */
|
|
147
383
|
options?: { label: string; value: unknown }[];
|
|
148
|
-
|
|
384
|
+
/** Schema for array items (for 'array' type with object items) */
|
|
149
385
|
items?: Record<string, SettingSchemaDef>;
|
|
150
|
-
|
|
386
|
+
/** Item type for 'array' type with primitive items ('string' or 'number') */
|
|
151
387
|
itemType?: 'string' | 'number';
|
|
152
388
|
}
|
|
153
389
|
|
|
390
|
+
/**
|
|
391
|
+
* Plugin settings schema - defines all user-configurable settings for a plugin.
|
|
392
|
+
*
|
|
393
|
+
* Settings are automatically displayed in the DevTools settings panel and
|
|
394
|
+
* can be accessed via `api.settings.get()` and `api.settings.set()`.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* const plugin: PluginClientInstance = {
|
|
399
|
+
* name: 'My Plugin',
|
|
400
|
+
* icon: 'Cube',
|
|
401
|
+
* settings: {
|
|
402
|
+
* apiUrl: {
|
|
403
|
+
* label: 'API URL',
|
|
404
|
+
* type: 'string',
|
|
405
|
+
* default: 'https://api.example.com'
|
|
406
|
+
* },
|
|
407
|
+
* timeout: {
|
|
408
|
+
* label: 'Timeout (ms)',
|
|
409
|
+
* type: 'number',
|
|
410
|
+
* default: 5000
|
|
411
|
+
* }
|
|
412
|
+
* }
|
|
413
|
+
* };
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
154
416
|
export interface PluginSettingsSchema {
|
|
155
417
|
[key: string]: SettingSchemaDef;
|
|
156
418
|
}
|
|
157
419
|
|
|
420
|
+
/**
|
|
421
|
+
* Menu item for the "General" section in ActivityBar.
|
|
422
|
+
*
|
|
423
|
+
* Allows plugins to add their actions to the general menu, even if the plugin
|
|
424
|
+
* itself is hidden from the main ActivityBar menu.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* const plugin: PluginClientInstance = {
|
|
429
|
+
* name: 'Plugins',
|
|
430
|
+
* icon: 'Squares2X2',
|
|
431
|
+
* hideFromMenu: true,
|
|
432
|
+
* generalMenuItems: [
|
|
433
|
+
* {
|
|
434
|
+
* label: 'Extensions',
|
|
435
|
+
* icon: 'Squares2X2',
|
|
436
|
+
* action: (api) => {
|
|
437
|
+
* api.navigation.openPlugin('Plugins');
|
|
438
|
+
* }
|
|
439
|
+
* }
|
|
440
|
+
* ]
|
|
441
|
+
* };
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
export interface GeneralMenuItem {
|
|
445
|
+
/** Menu item label text */
|
|
446
|
+
label: string;
|
|
447
|
+
/** Heroicons icon name (e.g., 'Cube', 'MagnifyingGlass') */
|
|
448
|
+
icon: string;
|
|
449
|
+
/**
|
|
450
|
+
* Action callback when menu item is clicked.
|
|
451
|
+
* @param api - Client API for interacting with DevTools
|
|
452
|
+
*/
|
|
453
|
+
action: (api: ClientApi) => void;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Plugin Client Instance - Definition of a plugin's UI and behavior in Client context.
|
|
458
|
+
* This is the main export from a plugin's client.ts file.
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```ts
|
|
462
|
+
* import type { PluginClientInstance } from '@u-devtools/core';
|
|
463
|
+
*
|
|
464
|
+
* const plugin: PluginClientInstance = {
|
|
465
|
+
* name: 'My Plugin',
|
|
466
|
+
* icon: 'Cube',
|
|
467
|
+
* settings: { },
|
|
468
|
+
* commands: [ ],
|
|
469
|
+
* renderMain(container, api) {
|
|
470
|
+
* // Render your plugin UI
|
|
471
|
+
* return () => { };
|
|
472
|
+
* }
|
|
473
|
+
* };
|
|
474
|
+
*
|
|
475
|
+
* export default plugin;
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
158
478
|
export interface PluginClientInstance {
|
|
479
|
+
/** Display name shown in DevTools UI */
|
|
159
480
|
name: string;
|
|
481
|
+
/** Heroicons icon name (e.g., 'Cube', 'MagnifyingGlass', 'WrenchScrewdriver') */
|
|
160
482
|
icon: string;
|
|
161
483
|
|
|
484
|
+
/**
|
|
485
|
+
* Hide plugin from main ActivityBar menu.
|
|
486
|
+
* Plugin will still be accessible via navigation API or generalMenuItems.
|
|
487
|
+
*/
|
|
488
|
+
hideFromMenu?: boolean;
|
|
489
|
+
|
|
490
|
+
/** Settings schema for user-configurable options */
|
|
162
491
|
settings?: PluginSettingsSchema;
|
|
492
|
+
|
|
493
|
+
/** Commands accessible via Command Palette (Cmd+K / Ctrl+K) */
|
|
163
494
|
commands?: PluginCommand[];
|
|
164
495
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
496
|
+
/**
|
|
497
|
+
* Menu items for the "General" section in ActivityBar.
|
|
498
|
+
* Allows plugins to add their actions to the general menu.
|
|
499
|
+
*/
|
|
500
|
+
generalMenuItems?: GeneralMenuItem[];
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Render sidebar panel (optional).
|
|
504
|
+
* @param el - Container element to render into
|
|
505
|
+
* @param api - Client API for plugin functionality
|
|
506
|
+
* @param options - Additional options including AppBridge
|
|
507
|
+
* @returns Cleanup function called when plugin is unmounted
|
|
508
|
+
*/
|
|
509
|
+
renderSidebar?: (el: HTMLElement, api: ClientApi, options: { bridge: AppBridge<any> }) => UnmountFn;
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Render main panel (optional).
|
|
513
|
+
* This is the primary UI for your plugin.
|
|
514
|
+
* @param el - Container element to render into
|
|
515
|
+
* @param api - Client API for plugin functionality
|
|
516
|
+
* @param options - Additional options including AppBridge
|
|
517
|
+
* @returns Cleanup function called when plugin is unmounted
|
|
518
|
+
*/
|
|
519
|
+
renderMain?: (el: HTMLElement, api: ClientApi, options: { bridge: AppBridge<any> }) => UnmountFn;
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Render custom settings UI (optional).
|
|
523
|
+
* If not provided, settings will use the default form based on settings schema.
|
|
524
|
+
* @param el - Container element to render into
|
|
525
|
+
* @param api - Client API for plugin functionality
|
|
526
|
+
* @param options - Additional options including AppBridge
|
|
527
|
+
* @returns Cleanup function called when plugin is unmounted
|
|
528
|
+
*/
|
|
529
|
+
renderSettings?: (el: HTMLElement, api: ClientApi, options: { bridge: AppBridge<any> }) => UnmountFn;
|
|
168
530
|
}
|
|
169
531
|
|
|
532
|
+
/**
|
|
533
|
+
* Server Context - Context object provided to server-side plugin setup.
|
|
534
|
+
* Available in: Server context (Node.js - Vite dev server)
|
|
535
|
+
*/
|
|
170
536
|
export interface ServerContext {
|
|
537
|
+
/** Project root directory path */
|
|
171
538
|
root: string;
|
|
539
|
+
/** Vite dev server instance (for advanced use cases) */
|
|
172
540
|
server: unknown;
|
|
173
541
|
}
|
|
174
542
|
|
|
543
|
+
/**
|
|
544
|
+
* RPC Server Interface - Interface for handling RPC requests from clients.
|
|
545
|
+
* Used in server-side plugin setup to register method handlers.
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* ```ts
|
|
549
|
+
* export function setupServer(rpc: RpcServerInterface, ctx: ServerContext) {
|
|
550
|
+
* rpc.handle('my-plugin:getData', async (payload) => {
|
|
551
|
+
* // Handle RPC call
|
|
552
|
+
* return { data: 'result' };
|
|
553
|
+
* });
|
|
554
|
+
*
|
|
555
|
+
* rpc.broadcast('my-plugin:update', { data: 'new' });
|
|
556
|
+
* }
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
175
559
|
export interface RpcServerInterface {
|
|
560
|
+
/**
|
|
561
|
+
* Register a handler for an RPC method.
|
|
562
|
+
* @param method - Method name (e.g., 'my-plugin:getData')
|
|
563
|
+
* @param fn - Handler function that receives payload and returns result
|
|
564
|
+
*/
|
|
176
565
|
handle(method: string, fn: (payload: unknown) => Promise<unknown> | unknown): void;
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Broadcast an event to all connected clients.
|
|
569
|
+
* @param event - Event name
|
|
570
|
+
* @param payload - Optional event data
|
|
571
|
+
*/
|
|
177
572
|
broadcast(event: string, payload?: unknown): void;
|
|
178
573
|
}
|
|
179
574
|
|
|
@@ -183,18 +578,47 @@ export interface PluginMetadata {
|
|
|
183
578
|
description?: string;
|
|
184
579
|
author?: string;
|
|
185
580
|
homepage?: string;
|
|
186
|
-
|
|
581
|
+
repository?: string; // Repository URL (GitHub, GitLab, etc.)
|
|
187
582
|
}
|
|
188
583
|
|
|
584
|
+
/**
|
|
585
|
+
* DevTools Plugin Definition - Server-side plugin configuration.
|
|
586
|
+
* Defines a plugin's structure and entry points for all three execution contexts.
|
|
587
|
+
*
|
|
588
|
+
* Created using definePlugin() helper from @u-devtools/kit/define-plugin.
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { definePlugin } from '@u-devtools/kit/define-plugin';
|
|
593
|
+
*
|
|
594
|
+
* export default definePlugin({
|
|
595
|
+
* name: 'My Plugin',
|
|
596
|
+
* root: import.meta.url,
|
|
597
|
+
* client: './client',
|
|
598
|
+
* app: './app',
|
|
599
|
+
* server: './server',
|
|
600
|
+
* });
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
189
603
|
export interface DevToolsPlugin {
|
|
604
|
+
/** Display name of the plugin */
|
|
190
605
|
name: string;
|
|
606
|
+
/** Absolute path to client.ts file (Client context) */
|
|
191
607
|
clientPath?: string;
|
|
608
|
+
/** Absolute path to app.ts file (App context - main window) */
|
|
192
609
|
appPath?: string;
|
|
610
|
+
/**
|
|
611
|
+
* Server-side setup function (Server context - Node.js).
|
|
612
|
+
* Called when plugin is loaded to register RPC handlers.
|
|
613
|
+
* @param rpc - RPC server interface for handling requests
|
|
614
|
+
* @param ctx - Server context with root path and Vite server instance
|
|
615
|
+
*/
|
|
193
616
|
setupServer?: (rpc: RpcServerInterface, ctx: ServerContext) => void;
|
|
617
|
+
/** Plugin metadata (name, version, description, etc.) */
|
|
194
618
|
meta?: PluginMetadata;
|
|
195
619
|
/**
|
|
196
|
-
* Optional Vite plugins to be
|
|
197
|
-
* These plugins will be
|
|
620
|
+
* Optional Vite plugins to be merged with the main DevTools plugin.
|
|
621
|
+
* These plugins will be added to the Vite configuration.
|
|
198
622
|
*/
|
|
199
623
|
vitePlugins?: (() => import('vite').PluginOption | import('vite').PluginOption[])[];
|
|
200
624
|
}
|
|
@@ -208,5 +632,13 @@ export interface InspectorEvent {
|
|
|
208
632
|
};
|
|
209
633
|
}
|
|
210
634
|
|
|
211
|
-
export { AppBridge } from './bridge-app';
|
|
635
|
+
export { AppBridge, SyncedState } from './bridge-app';
|
|
212
636
|
export * from './control';
|
|
637
|
+
export { Transport } from './transport';
|
|
638
|
+
export { HmrTransport } from './transports/hmr-transport';
|
|
639
|
+
export * from './schemas/settings';
|
|
640
|
+
export * from './schemas/rpc';
|
|
641
|
+
export { BroadcastTransport } from './transports/broadcast-transport';
|
|
642
|
+
export { WebSocketTransport } from './transports/websocket-transport';
|
|
643
|
+
export { TypedEventBus, type BusEvents } from './event-bus';
|
|
644
|
+
|