@vitejs/devtools 0.0.0-alpha.12 → 0.0.0-alpha.13

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.
@@ -1,7 +1,13 @@
1
+ import { RpcFunctionsCollectorBase } from "birpc-x";
1
2
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
3
+ import { BirpcReturn } from "birpc";
4
+ import "@vitejs/devtools-rpc/presets/ws/client";
2
5
 
3
6
  //#region ../kit/src/types/rpc-augments.d.ts
4
-
7
+ /**
8
+ * To be extended
9
+ */
10
+ interface DevToolsRpcClientFunctions {}
5
11
  /**
6
12
  * To be extended
7
13
  */
@@ -112,7 +118,13 @@ interface DevToolsNodeContext {
112
118
  utils: DevToolsNodeUtils;
113
119
  }
114
120
  interface DevToolsNodeUtils {
115
- clientEntryFromSimpleFunction: (fn: () => void) => ClientScriptEntry;
121
+ /**
122
+ * Create a simple client script from a function or stringified code
123
+ *
124
+ * @deprecated DO NOT USE. This is mostly for testing only. Please use a proper importable module instead.
125
+ * @experimental
126
+ */
127
+ createSimpleClientScript: (fn: string | ((ctx: DockClientScriptContext) => void)) => ClientScriptEntry;
116
128
  }
117
129
  //#endregion
118
130
  //#region ../kit/src/types/rpc.d.ts
@@ -123,13 +135,7 @@ interface DevToolsNodeUtils {
123
135
  * - query: A function that queries a resource
124
136
  */
125
137
  type RpcFunctionType = 'static' | 'action' | 'query';
126
- interface RpcFunctionsHost {
127
- context: DevToolsNodeContext;
128
- readonly functions: DevToolsRpcServerFunctions;
129
- readonly definitions: Map<string, RpcFunctionDefinition<string, any, any, any>>;
130
- register: (fn: RpcFunctionDefinition<string, any, any, any>) => void;
131
- update: (fn: RpcFunctionDefinition<string, any, any, any>) => void;
132
- }
138
+ type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext>;
133
139
  interface RpcFunctionSetupResult<ARGS extends any[], RETURN = void> {
134
140
  handler: (...args: ARGS) => RETURN;
135
141
  }
@@ -150,4 +156,79 @@ declare module 'vite' {
150
156
  }
151
157
  }
152
158
  //#endregion
153
- export { DevToolsDockEntry as i, RpcFunctionDefinition as n, DevToolsNodeContext as r, RpcDefinitionsToFunctions as t };
159
+ //#region ../kit/src/client/rpc.d.ts
160
+ type DevToolsRpcClient = BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>;
161
+ //#endregion
162
+ //#region ../kit/src/client/docks.d.ts
163
+ interface DockPanelStorage {
164
+ width: number;
165
+ height: number;
166
+ top: number;
167
+ left: number;
168
+ position: 'left' | 'right' | 'bottom' | 'top';
169
+ open: boolean;
170
+ inactiveTimeout: number;
171
+ }
172
+ interface DocksContext {
173
+ /**
174
+ * Type of the client environment
175
+ *
176
+ * 'embedded' - running inside an embedded floating panel
177
+ * 'standalone' - running inside a standlone window (no user app)
178
+ */
179
+ readonly clientType: 'embedded' | 'standalone';
180
+ /**
181
+ * The RPC client to interact with the server
182
+ */
183
+ readonly rpc: DevToolsRpcClient;
184
+ /**
185
+ * The panel context
186
+ */
187
+ panel: DocksPanelContext;
188
+ /**
189
+ * The docks entries context
190
+ */
191
+ docks: DocksEntriesContext;
192
+ }
193
+ interface DocksPanelContext {
194
+ store: DockPanelStorage;
195
+ isDragging: boolean;
196
+ isResizing: boolean;
197
+ readonly isVertical: boolean;
198
+ }
199
+ interface DocksEntriesContext {
200
+ selected: DevToolsDockEntry | null;
201
+ entries: DevToolsDockEntry[];
202
+ entryToStateMap: Map<string, DockEntryState>;
203
+ /**
204
+ * Get the state of a dock entry by its ID
205
+ */
206
+ getStateById: (id: string) => DockEntryState | undefined;
207
+ /**
208
+ * Switch to the selected dock entry, pass `null` to clear the selection
209
+ *
210
+ * @returns Whether the selection was changed successfully
211
+ */
212
+ switchEntry: (id: string | null) => Promise<boolean>;
213
+ }
214
+ interface DockEntryState {
215
+ entryMeta: DevToolsDockEntry;
216
+ readonly isActive: boolean;
217
+ domElements: {
218
+ iframe?: HTMLIFrameElement | null;
219
+ panel?: HTMLDivElement | null;
220
+ };
221
+ }
222
+ //#endregion
223
+ //#region ../kit/src/client/client-script.d.ts
224
+ /**
225
+ * Context for client scripts running in dock entries
226
+ */
227
+ interface DockClientScriptContext extends DocksContext {
228
+ /**
229
+ * The state if the current dock entry
230
+ */
231
+ current: DockEntryState;
232
+ }
233
+ //#endregion
234
+ export { DevToolsNodeContext as a, RpcDefinitionsToFunctions as i, DocksContext as n, DevToolsDockEntry as o, DevToolsRpcClient as r, DockPanelStorage as t };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { i as DevToolsDockEntry, n as RpcFunctionDefinition, r as DevToolsNodeContext, t as RpcDefinitionsToFunctions } from "./index-DdVYVGyC.js";
1
+ import { a as DevToolsNodeContext, i as RpcDefinitionsToFunctions, o as DevToolsDockEntry } from "./index-CuyjTfKA.js";
2
+ import * as birpc_x0 from "birpc-x";
2
3
  import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
3
4
  import * as birpc0 from "birpc";
4
5
  import * as h30 from "h3";
@@ -7,11 +8,11 @@ import * as h30 from "h3";
7
8
  declare function createDevToolsContext(viteConfig: ResolvedConfig, viteServer?: ViteDevServer): Promise<DevToolsNodeContext>;
8
9
  //#endregion
9
10
  //#region src/node/rpc/index.d.ts
10
- declare const builtinRpcFunctions: readonly [RpcFunctionDefinition<"vite:core:list-rpc-functions", "action", [], Promise<{
11
+ declare const builtinRpcFunctions: readonly [birpc_x0.RpcFunctionDefinition<"vite:core:list-rpc-functions", "action", [], Promise<{
11
12
  [k: string]: {
12
13
  type: any;
13
14
  };
14
- }>>, RpcFunctionDefinition<"vite:core:list-dock-entries", "query", [], DevToolsDockEntry[]>, RpcFunctionDefinition<"vite:core:open-in-editor", "action", [path: string], Promise<void>>, RpcFunctionDefinition<"vite:core:open-in-finder", "action", [path: string], Promise<void>>];
15
+ }>, DevToolsNodeContext>, birpc_x0.RpcFunctionDefinition<"vite:core:list-dock-entries", "query", [], DevToolsDockEntry[], DevToolsNodeContext>, 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>];
15
16
  type ServerFunctions = RpcDefinitionsToFunctions<typeof builtinRpcFunctions>;
16
17
  declare module '@vitejs/devtools-kit' {
17
18
  interface DevToolsRpcServerFunctions extends ServerFunctions {}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { d as createDevToolsContext, n as createDevToolsMiddleware, t as DevTools } from "./plugins-znai7bMv.js";
1
+ import { d as createDevToolsContext, n as createDevToolsMiddleware, t as DevTools } from "./plugins-C-9mB5Hx.js";
2
2
  import "./dirs-DcSK9l9L.js";
3
3
 
4
4
  export { DevTools, createDevToolsContext, createDevToolsMiddleware };
@@ -1,9 +1,10 @@
1
1
  import { n as dirDist, t as dirClientStandalone } from "./dirs-DcSK9l9L.js";
2
2
  import Debug from "debug";
3
3
  import { toDataURL } from "mlly";
4
- import { defineRpcFunction, getRpcHandler } from "@vitejs/devtools-kit";
4
+ import { RpcFunctionsCollectorBase } from "birpc-x";
5
5
  import { existsSync } from "node:fs";
6
6
  import sirv from "sirv";
7
+ import { defineRpcFunction } from "@vitejs/devtools-kit";
7
8
  import { join } from "node:path";
8
9
  import process$1 from "node:process";
9
10
  import { normalizePath } from "vite";
@@ -40,7 +41,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
40
41
 
41
42
  //#endregion
42
43
  //#region src/node/context-utils.ts
43
- const ContextUtils = { clientEntryFromSimpleFunction: (fn) => {
44
+ const ContextUtils = { createSimpleClientScript(fn) {
44
45
  return {
45
46
  importFrom: toDataURL(`const fn = ${fn.toString()}; export default fn`),
46
47
  importName: "default"
@@ -69,41 +70,9 @@ var DevToolsDockHost = class {
69
70
 
70
71
  //#endregion
71
72
  //#region src/node/host-functions.ts
72
- var RpcFunctionsHost = class {
73
- definitions = /* @__PURE__ */ new Map();
74
- functions;
73
+ var RpcFunctionsHost = class extends RpcFunctionsCollectorBase {
75
74
  constructor(context) {
76
- this.context = context;
77
- const definitions = this.definitions;
78
- const self = this;
79
- this.functions = new Proxy({}, {
80
- get(_, prop) {
81
- const definition = definitions.get(prop);
82
- if (!definition) return void 0;
83
- return getRpcHandler(definition, self.context);
84
- },
85
- has(_, prop) {
86
- return definitions.has(prop);
87
- },
88
- getOwnPropertyDescriptor(_, prop) {
89
- return {
90
- value: definitions.get(prop)?.handler,
91
- configurable: true,
92
- enumerable: true
93
- };
94
- },
95
- ownKeys() {
96
- return Array.from(definitions.keys());
97
- }
98
- });
99
- }
100
- register(fn) {
101
- if (this.definitions.has(fn.name)) throw new Error(`RPC function "${fn.name}" is already registered`);
102
- this.definitions.set(fn.name, fn);
103
- }
104
- update(fn) {
105
- if (!this.definitions.has(fn.name)) throw new Error(`RPC function "${fn.name}" is not registered. Use register() to add new functions.`);
106
- this.definitions.set(fn.name, fn);
75
+ super(context);
107
76
  }
108
77
  };
109
78