@vitejs/devtools 0.0.0-alpha.21 → 0.0.0-alpha.23

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.
@@ -0,0 +1,71 @@
1
+ import { I as shallowRef, N as reactive, T as watch, j as markRaw } from "./vue.runtime.esm-bundler-B98sE5ly.js";
2
+ import { createEventEmitter } from "@vitejs/devtools-kit/utils/events";
3
+
4
+ //#region src/client/webcomponents/constants.ts
5
+ const BUILTIN_ENTRY_CLIENT_AUTH_NOTICE = Object.freeze({
6
+ type: "~builtin",
7
+ id: "~client-auth-notice",
8
+ title: "Unauthorized",
9
+ icon: "i-fluent-emoji-flat-warning"
10
+ });
11
+ const BUILTIN_ENTRIES = Object.freeze([BUILTIN_ENTRY_CLIENT_AUTH_NOTICE]);
12
+ const DEFAULT_CATEGORIES_ORDER = {
13
+ default: 0,
14
+ app: 100,
15
+ framework: 200,
16
+ web: 300,
17
+ advanced: 400,
18
+ builtin: 500
19
+ };
20
+
21
+ //#endregion
22
+ //#region src/client/webcomponents/state/docks.ts
23
+ function DEFAULT_DOCK_PANEL_STORE() {
24
+ return {
25
+ width: 80,
26
+ height: 80,
27
+ top: 0,
28
+ left: 10,
29
+ position: "bottom",
30
+ open: false,
31
+ inactiveTimeout: 3e3
32
+ };
33
+ }
34
+ function createDockEntryState(entry, selected) {
35
+ const events = createEventEmitter();
36
+ const state = reactive({
37
+ entryMeta: entry,
38
+ get isActive() {
39
+ return selected.value?.id === entry.id;
40
+ },
41
+ domElements: {},
42
+ events: markRaw(events)
43
+ });
44
+ watch(() => selected.value?.id, (newSelectedId) => {
45
+ if (newSelectedId === entry.id) events.emit("entry:activated");
46
+ else events.emit("entry:deactivated");
47
+ }, { immediate: true });
48
+ watch(() => state.domElements.iframe, (newIframe) => {
49
+ if (newIframe) events.emit("dom:iframe:mounted", newIframe);
50
+ }, { immediate: true });
51
+ watch(() => state.domElements.panel, (newPanel) => {
52
+ if (newPanel) events.emit("dom:panel:mounted", newPanel);
53
+ }, { immediate: true });
54
+ return state;
55
+ }
56
+ function sharedStateToRef(sharedState) {
57
+ const ref = shallowRef(sharedState.value());
58
+ sharedState.on("updated", (newState) => {
59
+ ref.value = newState;
60
+ });
61
+ return ref;
62
+ }
63
+ let _docksEntriesRef;
64
+ async function useDocksEntries(rpc) {
65
+ if (_docksEntriesRef) return _docksEntriesRef;
66
+ _docksEntriesRef = sharedStateToRef(await rpc.sharedState.get("vite:internal:docks", { initialValue: [] }));
67
+ return _docksEntriesRef;
68
+ }
69
+
70
+ //#endregion
71
+ export { BUILTIN_ENTRY_CLIENT_AUTH_NOTICE as a, BUILTIN_ENTRIES as i, createDockEntryState as n, DEFAULT_CATEGORIES_ORDER as o, useDocksEntries as r, DEFAULT_DOCK_PANEL_STORE as t };
@@ -0,0 +1,9 @@
1
+ //#region \0/plugin-vue/export-helper
2
+ var export_helper_default = (sfc, props) => {
3
+ const target = sfc.__vccOpts || sfc;
4
+ for (const [key, val] of props) target[key] = val;
5
+ return target;
6
+ };
7
+
8
+ //#endregion
9
+ export { export_helper_default as t };
@@ -1,8 +1,10 @@
1
1
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
2
2
  import { RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
3
+ import "node:http";
3
4
  import { Raw } from "vue";
4
5
  import { BirpcReturn } from "birpc";
5
6
  import { WebSocket } from "ws";
7
+ import { Patch, Patch as SharedStatePatch } from "immer";
6
8
  import { ChildProcess } from "node:child_process";
7
9
 
8
10
  //#region ../kit/src/types/events.d.ts
@@ -23,14 +25,14 @@ interface EventEmitter<Events extends EventsMap> {
23
25
  * @param event The event name.
24
26
  * @param args The arguments for listeners.
25
27
  */
26
- emit: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
28
+ emit: <K$1 extends keyof Events>(event: K$1, ...args: Parameters<Events[K$1]>) => void;
27
29
  /**
28
30
  * Calls the listeners for a given event once and then removes the listener.
29
31
  *
30
32
  * @param event The event name.
31
33
  * @param args The arguments for listeners.
32
34
  */
33
- emitOnce: <K extends keyof Events>(event: K, ...args: Parameters<Events[K]>) => void;
35
+ emitOnce: <K$1 extends keyof Events>(event: K$1, ...args: Parameters<Events[K$1]>) => void;
34
36
  /**
35
37
  * Event names in keys and arrays with listeners in values.
36
38
  *
@@ -54,7 +56,7 @@ interface EventEmitter<Events extends EventsMap> {
54
56
  * @param cb The listener function.
55
57
  * @returns Unbind listener from event.
56
58
  */
57
- on: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
59
+ on: <K$1 extends keyof Events>(event: K$1, cb: Events[K$1]) => EventUnsubscribe;
58
60
  /**
59
61
  * Add a listener for a given event once.
60
62
  *
@@ -72,7 +74,7 @@ interface EventEmitter<Events extends EventsMap> {
72
74
  * @param cb The listener function.
73
75
  * @returns Unbind listener from event.
74
76
  */
75
- once: <K extends keyof Events>(event: K, cb: Events[K]) => EventUnsubscribe;
77
+ once: <K$1 extends keyof Events>(event: K$1, cb: Events[K$1]) => EventUnsubscribe;
76
78
  }
77
79
  //#endregion
78
80
  //#region ../kit/src/types/docks.d.ts
@@ -85,9 +87,11 @@ interface DevToolsDockHost {
85
87
  update: (patch: Partial<T>) => void;
86
88
  };
87
89
  update: (entry: DevToolsDockUserEntry) => void;
88
- values: () => DevToolsDockUserEntry[];
90
+ values: (options?: {
91
+ includeBuiltin?: boolean;
92
+ }) => DevToolsDockEntry[];
89
93
  }
90
- type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default';
94
+ type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default' | 'builtin';
91
95
  type DevToolsDockEntryIcon = string | {
92
96
  light: string;
93
97
  dark: string;
@@ -163,11 +167,56 @@ interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
163
167
  }
164
168
  interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
165
169
  type: '~builtin';
166
- id: '~terminals' | '~logs' | '~client-auth-notice';
170
+ id: '~terminals' | '~logs' | '~client-auth-notice' | '~settings';
167
171
  }
168
172
  type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
169
173
  type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
170
174
  //#endregion
175
+ //#region ../rpc/src/presets/ws/server.d.ts
176
+ interface DevToolsNodeRpcSessionMeta {
177
+ id: number;
178
+ ws?: WebSocket;
179
+ clientAuthId?: string;
180
+ isTrusted?: boolean;
181
+ subscribedStates: Set<string>;
182
+ }
183
+ //#endregion
184
+ //#region ../kit/src/utils/shared-state.d.ts
185
+ type ImmutablePrimitive = undefined | null | boolean | string | number | Function;
186
+ type Immutable<T> = T extends ImmutablePrimitive ? T : T extends Array<infer U> ? ImmutableArray<U> : T extends Map<infer K, infer V> ? ImmutableMap<K, V> : T extends Set<infer M> ? ImmutableSet<M> : ImmutableObject<T>;
187
+ type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
188
+ type ImmutableMap<K$1, V$1> = ReadonlyMap<Immutable<K$1>, Immutable<V$1>>;
189
+ type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
190
+ type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
191
+ /**
192
+ * State host that is immutable by default with explicit mutate.
193
+ */
194
+ interface SharedState<T> {
195
+ /**
196
+ * Get the current state. Immutable.
197
+ */
198
+ value: () => Immutable<T>;
199
+ /**
200
+ * Subscribe to state changes.
201
+ */
202
+ on: EventEmitter<SharedStateEvents<T>>['on'];
203
+ /**
204
+ * Mutate the state.
205
+ */
206
+ mutate: (fn: (state: T) => void, syncId?: string) => void;
207
+ /**
208
+ * Apply patches to the state.
209
+ */
210
+ patch: (patches: Patch[], syncId?: string) => void;
211
+ /**
212
+ * Sync IDs that have been applied to the state.
213
+ */
214
+ syncIds: Set<string>;
215
+ }
216
+ interface SharedStateEvents<T> {
217
+ updated: (fullState: T, patches: Patch[] | undefined, syncId: string) => void;
218
+ }
219
+ //#endregion
171
220
  //#region ../kit/src/types/rpc-augments.d.ts
172
221
  /**
173
222
  * To be extended
@@ -177,6 +226,10 @@ interface DevToolsRpcClientFunctions {}
177
226
  * To be extended
178
227
  */
179
228
  interface DevToolsRpcServerFunctions {}
229
+ /**
230
+ * To be extended
231
+ */
232
+ interface DevToolsRpcSharedStates {}
180
233
  //#endregion
181
234
  //#region ../kit/src/types/terminals.d.ts
182
235
  interface DevToolsTerminalSessionStreamChunkEvent {
@@ -308,28 +361,39 @@ interface ConnectionMeta {
308
361
  }
309
362
  //#endregion
310
363
  //#region ../kit/src/types/rpc.d.ts
311
- interface DevToolsNodeRpcSessionMeta {
312
- id: number;
313
- ws?: WebSocket;
314
- clientAuthId?: string;
315
- isTrusted?: boolean;
316
- }
317
364
  interface DevToolsNodeRpcSession {
318
365
  meta: DevToolsNodeRpcSessionMeta;
319
366
  rpc: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>;
320
367
  }
368
+ interface RpcBroadcastOptions<METHOD, Args extends any[]> {
369
+ method: METHOD;
370
+ args: Args;
371
+ optional?: boolean;
372
+ event?: boolean;
373
+ filter?: (client: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>) => boolean | void;
374
+ }
321
375
  type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
322
376
  /**
323
377
  * Broadcast a message to all connected clients
324
378
  */
325
- broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(name: T, ...args: Args) => Promise<(Awaited<ReturnType<DevToolsRpcClientFunctions[T]>> | undefined)[]>;
379
+ broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(options: RpcBroadcastOptions<T, Args>) => Promise<void>;
326
380
  /**
327
381
  * Get the current RPC client
328
382
  *
329
383
  * Available in RPC functions to get the current RPC client
330
384
  */
331
385
  getCurrentRpcSession: () => DevToolsNodeRpcSession | undefined;
386
+ /**
387
+ * The shared state host
388
+ */
389
+ sharedState: RpcSharedStateHost;
332
390
  };
391
+ interface RpcSharedStateGetOptions<T> {
392
+ initialValue?: T;
393
+ }
394
+ interface RpcSharedStateHost {
395
+ get: <T extends keyof DevToolsRpcSharedStates>(key: T, options?: RpcSharedStateGetOptions<DevToolsRpcSharedStates[T]>) => Promise<SharedState<DevToolsRpcSharedStates[T]>>;
396
+ }
333
397
  //#endregion
334
398
  //#region ../kit/src/types/vite-augment.d.ts
335
399
  declare module 'vite' {
@@ -395,6 +459,10 @@ interface DevToolsRpcClient {
395
459
  * The client RPC host
396
460
  */
397
461
  client: DevToolsClientRpcHost;
462
+ /**
463
+ * The shared state host
464
+ */
465
+ sharedState: RpcSharedStateHost;
398
466
  }
399
467
  //#endregion
400
468
  //#region ../kit/src/client/docks.d.ts
@@ -490,4 +558,4 @@ interface DockClientScriptContext extends DocksContext {
490
558
  current: DockEntryState;
491
559
  }
492
560
  //#endregion
493
- export { RpcDefinitionsToFunctions as a, DevToolsTerminalSessionBase as c, DevToolsRpcServerFunctions as d, DevToolsDockEntry as f, DevToolsRpcClient as i, DevToolsTerminalSessionStreamChunkEvent as l, DockPanelStorage as n, ConnectionMeta as o, DocksContext as r, DevToolsNodeContext as s, DockEntryState as t, DevToolsRpcClientFunctions as u };
561
+ export { RpcDefinitionsToFunctions as a, DevToolsTerminalSessionBase as c, DevToolsRpcServerFunctions as d, SharedStatePatch as f, DevToolsRpcClient as i, DevToolsTerminalSessionStreamChunkEvent as l, DockPanelStorage as n, ConnectionMeta as o, DevToolsDockEntry as p, DocksContext as r, DevToolsNodeContext as s, DockEntryState as t, DevToolsRpcClientFunctions as u };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as RpcDefinitionsToFunctions, c as DevToolsTerminalSessionBase, d as DevToolsRpcServerFunctions, f as DevToolsDockEntry, l as DevToolsTerminalSessionStreamChunkEvent, o as ConnectionMeta, s as DevToolsNodeContext, u as DevToolsRpcClientFunctions } from "./index-CWvzFILY.js";
1
+ import { a as RpcDefinitionsToFunctions, c as DevToolsTerminalSessionBase, d as DevToolsRpcServerFunctions, f as SharedStatePatch, l as DevToolsTerminalSessionStreamChunkEvent, o as ConnectionMeta, p as DevToolsDockEntry, s as DevToolsNodeContext, u as DevToolsRpcClientFunctions } from "./index-BYIZX1ss.js";
2
2
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
3
3
  import * as birpc_x0 from "birpc-x";
4
4
  import { RpcFunctionsCollectorBase } from "birpc-x";
@@ -20,22 +20,26 @@ interface DevToolsAuthReturn {
20
20
  }
21
21
  //#endregion
22
22
  //#region src/node/rpc/index.d.ts
23
- declare const builtinRpcDecalrations: readonly [birpc_x0.RpcFunctionDefinition<"vite:core:open-in-editor", "action", [path: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:open-in-finder", "action", [path: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:anonymous:auth", "action", [query: DevToolsAuthInput], Promise<DevToolsAuthReturn>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:docks:list", "static", [], DevToolsDockEntry[], DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:docks:on-launch", "action", [entryId: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:rpc:server:list", "static", [], Promise<{
23
+ declare const builtinRpcDeclarations: readonly [birpc_x0.RpcFunctionDefinition<"vite:core:open-in-editor", "action", [path: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:open-in-finder", "action", [path: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:anonymous:auth", "action", [query: DevToolsAuthInput], Promise<DevToolsAuthReturn>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:docks:on-launch", "action", [entryId: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:rpc:server:list", "static", [], Promise<{
24
24
  [k: string]: {
25
25
  type: any;
26
26
  };
27
- }>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:terminals:list", "static", [], Promise<DevToolsTerminalSessionBase[]>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:terminals:read", "query", [id: string], Promise<{
27
+ }>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:rpc:server-state:get", "query", [key: string], Promise<any>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:rpc:server-state:patch", "query", [key: string, patches: SharedStatePatch[], syncId: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:rpc:server-state:set", "query", [key: string, value: any, syncId: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:rpc:server-state:subscribe", "event", [key: string], Promise<void>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:terminals:list", "static", [], Promise<DevToolsTerminalSessionBase[]>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:internal:terminals:read", "query", [id: string], Promise<{
28
28
  buffer: string[];
29
29
  ts: number;
30
30
  }>, DevToolsNodeContext>];
31
- type BuiltinServerFunctions = RpcDefinitionsToFunctions<typeof builtinRpcDecalrations>;
31
+ type BuiltinServerFunctions = RpcDefinitionsToFunctions<typeof builtinRpcDeclarations>;
32
32
  declare module '@vitejs/devtools-kit' {
33
33
  interface DevToolsRpcServerFunctions extends BuiltinServerFunctions {}
34
34
  interface DevToolsRpcClientFunctions {
35
- 'vite:internal:docks:updated': () => Promise<void>;
35
+ 'vite:internal:rpc:client-state:patch': (key: string, patches: SharedStatePatch[], syncId: string) => Promise<void>;
36
+ 'vite:internal:rpc:client-state:updated': (key: string, fullState: any, syncId: string) => Promise<void>;
36
37
  'vite:internal:terminals:stream-chunk': (data: DevToolsTerminalSessionStreamChunkEvent) => Promise<void>;
37
38
  'vite:internal:terminals:updated': () => Promise<void>;
38
39
  }
40
+ interface DevToolsRpcSharedStates {
41
+ 'vite:internal:docks': DevToolsDockEntry[];
42
+ }
39
43
  }
40
44
  //#endregion
41
45
  //#region src/node/plugins/index.d.ts
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as createDevToolsMiddleware, t as DevTools, u as createDevToolsContext } from "./plugins-Chcj6ENu.js";
1
+ import { n as createDevToolsMiddleware, t as DevTools, u as createDevToolsContext } from "./plugins-BTYJ2nZg.js";
2
2
 
3
3
  export { DevTools, createDevToolsContext, createDevToolsMiddleware };