@vitejs/devtools-kit 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.
package/dist/client.d.mts CHANGED
@@ -1,2 +1,3 @@
1
- import { a as DockEntryState, c as DocksContext, d as RpcClientEvents, f as DevToolsRpcClient, i as DockClientType, l as DocksEntriesContext, m as getDevToolsRpcClient, n as DevToolsClientContext, o as DockEntryStateEvents, p as DevToolsRpcClientOptions, r as DevToolsClientRpcHost, s as DockPanelStorage, t as DockClientScriptContext, u as DocksPanelContext } from "./index-FzXSK6np.mjs";
1
+ import { a as DockEntryState, c as DocksContext, d as RpcClientEvents, f as DevToolsRpcClient, i as DockClientType, l as DocksEntriesContext, m as getDevToolsRpcClient, n as DevToolsClientContext, o as DockEntryStateEvents, p as DevToolsRpcClientOptions, r as DevToolsClientRpcHost, s as DockPanelStorage, t as DockClientScriptContext, u as DocksPanelContext } from "./index-Pzr9xl88.mjs";
2
+ import "./shared-state-7JDpUVVs.mjs";
2
3
  export { DevToolsClientContext, DevToolsClientRpcHost, DevToolsRpcClient, DevToolsRpcClientOptions, DockClientScriptContext, DockClientType, DockEntryState, DockEntryStateEvents, DockPanelStorage, DocksContext, DocksEntriesContext, DocksPanelContext, RpcClientEvents, getDevToolsRpcClient };
package/dist/client.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { t as createEventEmitter } from "./events-CWYZG96x.mjs";
2
2
  import { t as nanoid } from "./nanoid-B0pJU5uW.mjs";
3
+ import { t as createSharedState } from "./shared-state-BAC6HwFS.mjs";
3
4
  import { RpcFunctionsCollectorBase } from "birpc-x";
4
5
  import { createRpcClient } from "@vitejs/devtools-rpc";
5
6
  import { createWsRpcPreset } from "@vitejs/devtools-rpc/presets/ws/client";
@@ -1103,6 +1104,74 @@ function promiseWithResolver() {
1103
1104
  };
1104
1105
  }
1105
1106
 
1107
+ //#endregion
1108
+ //#region src/client/rpc-shared-state.ts
1109
+ function createRpcSharedStateClientHost(rpc) {
1110
+ const sharedState = /* @__PURE__ */ new Map();
1111
+ rpc.client.register({
1112
+ name: "vite:internal:rpc:client-state:updated",
1113
+ type: "event",
1114
+ handler: (key, fullState, syncId) => {
1115
+ const state = sharedState.get(key);
1116
+ if (!state || state.syncIds.has(syncId)) return;
1117
+ state.mutate(() => fullState, syncId);
1118
+ }
1119
+ });
1120
+ rpc.client.register({
1121
+ name: "vite:internal:rpc:client-state:patch",
1122
+ type: "event",
1123
+ handler: (key, patches, syncId) => {
1124
+ const state = sharedState.get(key);
1125
+ if (!state || state.syncIds.has(syncId)) return;
1126
+ state.patch(patches, syncId);
1127
+ }
1128
+ });
1129
+ function registerSharedState(key, state) {
1130
+ const offs = [];
1131
+ offs.push(state.on("updated", (fullState, patches, syncId) => {
1132
+ if (patches) rpc.callEvent("vite:internal:rpc:server-state:patch", key, patches, syncId);
1133
+ else rpc.callEvent("vite:internal:rpc:server-state:set", key, fullState, syncId);
1134
+ }));
1135
+ return () => {
1136
+ for (const off of offs) off();
1137
+ };
1138
+ }
1139
+ return { get: async (key, options) => {
1140
+ if (sharedState.has(key)) return sharedState.get(key);
1141
+ const state = createSharedState({
1142
+ initialValue: options?.initialValue,
1143
+ enablePatches: false
1144
+ });
1145
+ async function initSharedState() {
1146
+ rpc.callEvent("vite:internal:rpc:server-state:subscribe", key);
1147
+ if (options?.initialValue !== void 0) {
1148
+ sharedState.set(key, state);
1149
+ rpc.call("vite:internal:rpc:server-state:get", key).then((serverState) => {
1150
+ state.mutate(() => serverState);
1151
+ }).catch((error) => {
1152
+ console.error("Error getting server state", error);
1153
+ });
1154
+ registerSharedState(key, state);
1155
+ return state;
1156
+ } else {
1157
+ const initialValue = await rpc.call("vite:internal:rpc:server-state:get", key);
1158
+ state.mutate(() => initialValue);
1159
+ sharedState.set(key, state);
1160
+ registerSharedState(key, state);
1161
+ return state;
1162
+ }
1163
+ }
1164
+ return new Promise((resolve) => {
1165
+ if (!rpc.isTrusted) {
1166
+ resolve(state);
1167
+ rpc.events.on("rpc:is-trusted:updated", (isTrusted) => {
1168
+ if (isTrusted) initSharedState();
1169
+ });
1170
+ } else initSharedState().then(resolve);
1171
+ });
1172
+ } };
1173
+ }
1174
+
1106
1175
  //#endregion
1107
1176
  //#region src/client/rpc.ts
1108
1177
  const CONNECTION_META_KEY = "__VITE_DEVTOOLS_CONNECTION_META__";
@@ -1165,6 +1234,7 @@ async function getDevToolsRpcClient(options = {}) {
1165
1234
  const serverRpc = createRpcClient(clientRpc.functions, {
1166
1235
  preset: createWsRpcPreset({
1167
1236
  url,
1237
+ authId,
1168
1238
  ...options.wsOptions
1169
1239
  }),
1170
1240
  rpcOptions
@@ -1219,8 +1289,10 @@ async function getDevToolsRpcClient(options = {}) {
1219
1289
  callOptional: (...args) => {
1220
1290
  return serverRpc.$callOptional(...args);
1221
1291
  },
1222
- client: clientRpc
1292
+ client: clientRpc,
1293
+ sharedState: void 0
1223
1294
  };
1295
+ rpc.sharedState = createRpcSharedStateClientHost(rpc);
1224
1296
  context.rpc = rpc;
1225
1297
  requestTrust();
1226
1298
  return rpc;
@@ -1,4 +1,5 @@
1
- import { t as EventEmitter } from "./events-BrHMyEqJ.mjs";
1
+ import { t as EventEmitter } from "./events-ChUECkY3.mjs";
2
+ import { o as SharedState } from "./shared-state-7JDpUVVs.mjs";
2
3
  import { RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
3
4
  import { Raw } from "vue";
4
5
  import { BirpcOptions, BirpcReturn } from "birpc";
@@ -16,9 +17,11 @@ interface DevToolsDockHost {
16
17
  update: (patch: Partial<T>) => void;
17
18
  };
18
19
  update: (entry: DevToolsDockUserEntry) => void;
19
- values: () => DevToolsDockUserEntry[];
20
+ values: (options?: {
21
+ includeBuiltin?: boolean;
22
+ }) => DevToolsDockEntry[];
20
23
  }
21
- type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default';
24
+ type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default' | 'builtin';
22
25
  type DevToolsDockEntryIcon = string | {
23
26
  light: string;
24
27
  dark: string;
@@ -94,11 +97,20 @@ interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
94
97
  }
95
98
  interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
96
99
  type: '~builtin';
97
- id: '~terminals' | '~logs' | '~client-auth-notice';
100
+ id: '~terminals' | '~logs' | '~client-auth-notice' | '~settings';
98
101
  }
99
102
  type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
100
103
  type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
101
104
  //#endregion
105
+ //#region ../rpc/src/presets/ws/server.d.ts
106
+ interface DevToolsNodeRpcSessionMeta {
107
+ id: number;
108
+ ws?: WebSocket;
109
+ clientAuthId?: string;
110
+ isTrusted?: boolean;
111
+ subscribedStates: Set<string>;
112
+ }
113
+ //#endregion
102
114
  //#region src/types/rpc-augments.d.ts
103
115
  /**
104
116
  * To be extended
@@ -108,6 +120,10 @@ interface DevToolsRpcClientFunctions {}
108
120
  * To be extended
109
121
  */
110
122
  interface DevToolsRpcServerFunctions {}
123
+ /**
124
+ * To be extended
125
+ */
126
+ interface DevToolsRpcSharedStates {}
111
127
  //#endregion
112
128
  //#region src/types/terminals.d.ts
113
129
  interface DevToolsTerminalSessionStreamChunkEvent {
@@ -239,28 +255,39 @@ interface ConnectionMeta {
239
255
  }
240
256
  //#endregion
241
257
  //#region src/types/rpc.d.ts
242
- interface DevToolsNodeRpcSessionMeta {
243
- id: number;
244
- ws?: WebSocket;
245
- clientAuthId?: string;
246
- isTrusted?: boolean;
247
- }
248
258
  interface DevToolsNodeRpcSession {
249
259
  meta: DevToolsNodeRpcSessionMeta;
250
260
  rpc: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>;
251
261
  }
262
+ interface RpcBroadcastOptions<METHOD, Args extends any[]> {
263
+ method: METHOD;
264
+ args: Args;
265
+ optional?: boolean;
266
+ event?: boolean;
267
+ filter?: (client: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>) => boolean | void;
268
+ }
252
269
  type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
253
270
  /**
254
271
  * Broadcast a message to all connected clients
255
272
  */
256
- broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(name: T, ...args: Args) => Promise<(Awaited<ReturnType<DevToolsRpcClientFunctions[T]>> | undefined)[]>;
273
+ broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(options: RpcBroadcastOptions<T, Args>) => Promise<void>;
257
274
  /**
258
275
  * Get the current RPC client
259
276
  *
260
277
  * Available in RPC functions to get the current RPC client
261
278
  */
262
279
  getCurrentRpcSession: () => DevToolsNodeRpcSession | undefined;
280
+ /**
281
+ * The shared state host
282
+ */
283
+ sharedState: RpcSharedStateHost;
263
284
  };
285
+ interface RpcSharedStateGetOptions<T> {
286
+ initialValue?: T;
287
+ }
288
+ interface RpcSharedStateHost {
289
+ get: <T extends keyof DevToolsRpcSharedStates>(key: T, options?: RpcSharedStateGetOptions<DevToolsRpcSharedStates[T]>) => Promise<SharedState<DevToolsRpcSharedStates[T]>>;
290
+ }
264
291
  //#endregion
265
292
  //#region src/types/utils.d.ts
266
293
  type Thenable<T> = T | Promise<T>;
@@ -302,6 +329,7 @@ interface WebSocketRpcClientOptions {
302
329
  onConnected?: (e: Event) => void;
303
330
  onError?: (e: Error) => void;
304
331
  onDisconnected?: (e: CloseEvent) => void;
332
+ authId?: string;
305
333
  }
306
334
  //#endregion
307
335
  //#region src/client/rpc.d.ts
@@ -356,6 +384,10 @@ interface DevToolsRpcClient {
356
384
  * The client RPC host
357
385
  */
358
386
  client: DevToolsClientRpcHost;
387
+ /**
388
+ * The shared state host
389
+ */
390
+ sharedState: RpcSharedStateHost;
359
391
  }
360
392
  declare function getDevToolsRpcClient(options?: DevToolsRpcClientOptions): Promise<DevToolsRpcClient>;
361
393
  //#endregion
@@ -453,4 +485,4 @@ interface DockClientScriptContext extends DocksContext {
453
485
  current: DockEntryState;
454
486
  }
455
487
  //#endregion
456
- export { DevToolsViewHost as A, ClientScriptEntry as B, DevToolsNodeRpcSessionMeta as C, DevToolsNodeContext as D, DevToolsCapabilities as E, DevToolsTerminalSessionBase as F, DevToolsDockHost as G, DevToolsDockEntryBase as H, DevToolsTerminalSessionStreamChunkEvent as I, DevToolsViewBuiltin as J, DevToolsDockUserEntry as K, DevToolsTerminalStatus as L, DevToolsChildProcessTerminalSession as M, DevToolsTerminalHost as N, DevToolsNodeUtils as O, DevToolsTerminalSession as P, DevToolsViewLauncherStatus as Q, DevToolsRpcClientFunctions as R, DevToolsNodeRpcSession as S, ConnectionMeta as T, DevToolsDockEntryCategory as U, DevToolsDockEntry as V, DevToolsDockEntryIcon as W, DevToolsViewIframe as X, DevToolsViewCustomRender as Y, DevToolsViewLauncher as Z, PluginWithDevTools as _, DockEntryState as a, PartialWithoutId as b, DocksContext as c, RpcClientEvents as d, DevToolsRpcClient as f, RpcDefinitionsToFunctions as g, RpcDefinitionsFilter as h, DockClientType as i, DevToolsChildProcessExecuteOptions as j, DevToolsPluginOptions as k, DocksEntriesContext as l, getDevToolsRpcClient as m, DevToolsClientContext as n, DockEntryStateEvents as o, DevToolsRpcClientOptions as p, DevToolsViewAction as q, DevToolsClientRpcHost as r, DockPanelStorage as s, DockClientScriptContext as t, DocksPanelContext as u, ViteConfigDevtoolsOptions as v, RpcFunctionsHost as w, Thenable as x, EntriesToObject as y, DevToolsRpcServerFunctions as z };
488
+ export { DevToolsViewCustomRender as $, DevToolsNodeUtils as A, DevToolsRpcClientFunctions as B, RpcBroadcastOptions as C, ConnectionMeta as D, RpcSharedStateHost as E, DevToolsTerminalHost as F, DevToolsDockEntry as G, DevToolsRpcSharedStates as H, DevToolsTerminalSession as I, DevToolsDockEntryIcon as J, DevToolsDockEntryBase as K, DevToolsTerminalSessionBase as L, DevToolsViewHost as M, DevToolsChildProcessExecuteOptions as N, DevToolsCapabilities as O, DevToolsChildProcessTerminalSession as P, DevToolsViewBuiltin as Q, DevToolsTerminalSessionStreamChunkEvent as R, DevToolsNodeRpcSession as S, RpcSharedStateGetOptions as T, DevToolsNodeRpcSessionMeta as U, DevToolsRpcServerFunctions as V, ClientScriptEntry as W, DevToolsDockUserEntry as X, DevToolsDockHost as Y, DevToolsViewAction as Z, PluginWithDevTools as _, DockEntryState as a, PartialWithoutId as b, DocksContext as c, RpcClientEvents as d, DevToolsViewIframe as et, DevToolsRpcClient as f, RpcDefinitionsToFunctions as g, RpcDefinitionsFilter as h, DockClientType as i, DevToolsPluginOptions as j, DevToolsNodeContext as k, DocksEntriesContext as l, getDevToolsRpcClient as m, DevToolsClientContext as n, DevToolsViewLauncherStatus as nt, DockEntryStateEvents as o, DevToolsRpcClientOptions as p, DevToolsDockEntryCategory as q, DevToolsClientRpcHost as r, DockPanelStorage as s, DockClientScriptContext as t, DevToolsViewLauncher as tt, DocksPanelContext as u, ViteConfigDevtoolsOptions as v, RpcFunctionsHost as w, Thenable as x, EntriesToObject as y, DevToolsTerminalStatus as z };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
- import { n as EventUnsubscribe, r as EventsMap, t as EventEmitter } from "./events-BrHMyEqJ.mjs";
2
- import { A as DevToolsViewHost, B as ClientScriptEntry, C as DevToolsNodeRpcSessionMeta, D as DevToolsNodeContext, E as DevToolsCapabilities, F as DevToolsTerminalSessionBase, G as DevToolsDockHost, H as DevToolsDockEntryBase, I as DevToolsTerminalSessionStreamChunkEvent, J as DevToolsViewBuiltin, K as DevToolsDockUserEntry, L as DevToolsTerminalStatus, M as DevToolsChildProcessTerminalSession, N as DevToolsTerminalHost, O as DevToolsNodeUtils, P as DevToolsTerminalSession, Q as DevToolsViewLauncherStatus, R as DevToolsRpcClientFunctions, S as DevToolsNodeRpcSession, T as ConnectionMeta, U as DevToolsDockEntryCategory, V as DevToolsDockEntry, W as DevToolsDockEntryIcon, X as DevToolsViewIframe, Y as DevToolsViewCustomRender, Z as DevToolsViewLauncher, _ as PluginWithDevTools, b as PartialWithoutId, g as RpcDefinitionsToFunctions, h as RpcDefinitionsFilter, j as DevToolsChildProcessExecuteOptions, k as DevToolsPluginOptions, q as DevToolsViewAction, v as ViteConfigDevtoolsOptions, w as RpcFunctionsHost, x as Thenable, y as EntriesToObject, z as DevToolsRpcServerFunctions } from "./index-FzXSK6np.mjs";
1
+ import { n as EventUnsubscribe, r as EventsMap, t as EventEmitter } from "./events-ChUECkY3.mjs";
2
+ import { $ as DevToolsViewCustomRender, A as DevToolsNodeUtils, B as DevToolsRpcClientFunctions, C as RpcBroadcastOptions, D as ConnectionMeta, E as RpcSharedStateHost, F as DevToolsTerminalHost, G as DevToolsDockEntry, H as DevToolsRpcSharedStates, I as DevToolsTerminalSession, J as DevToolsDockEntryIcon, K as DevToolsDockEntryBase, L as DevToolsTerminalSessionBase, M as DevToolsViewHost, N as DevToolsChildProcessExecuteOptions, O as DevToolsCapabilities, P as DevToolsChildProcessTerminalSession, Q as DevToolsViewBuiltin, R as DevToolsTerminalSessionStreamChunkEvent, S as DevToolsNodeRpcSession, T as RpcSharedStateGetOptions, U as DevToolsNodeRpcSessionMeta, V as DevToolsRpcServerFunctions, W as ClientScriptEntry, X as DevToolsDockUserEntry, Y as DevToolsDockHost, Z as DevToolsViewAction, _ as PluginWithDevTools, b as PartialWithoutId, et as DevToolsViewIframe, g as RpcDefinitionsToFunctions, h as RpcDefinitionsFilter, j as DevToolsPluginOptions, k as DevToolsNodeContext, nt as DevToolsViewLauncherStatus, q as DevToolsDockEntryCategory, tt as DevToolsViewLauncher, v as ViteConfigDevtoolsOptions, w as RpcFunctionsHost, x as Thenable, y as EntriesToObject, z as DevToolsTerminalStatus } from "./index-Pzr9xl88.mjs";
3
+ import "./shared-state-7JDpUVVs.mjs";
3
4
  import * as birpc_x0 from "birpc-x";
4
5
 
5
6
  //#region src/utils/define.d.ts
6
7
  declare const defineRpcFunction: <NAME extends string, TYPE extends birpc_x0.RpcFunctionType, ARGS$1 extends any[], RETURN$1 = void>(definition: birpc_x0.RpcFunctionDefinition<NAME, TYPE, ARGS$1, RETURN$1, DevToolsNodeContext>) => birpc_x0.RpcFunctionDefinition<NAME, TYPE, ARGS$1, RETURN$1, DevToolsNodeContext>;
7
8
  //#endregion
8
- export { ClientScriptEntry, ConnectionMeta, DevToolsCapabilities, DevToolsChildProcessExecuteOptions, DevToolsChildProcessTerminalSession, DevToolsDockEntry, DevToolsDockEntryBase, DevToolsDockEntryCategory, DevToolsDockEntryIcon, DevToolsDockHost, DevToolsDockUserEntry, DevToolsNodeContext, DevToolsNodeRpcSession, DevToolsNodeRpcSessionMeta, DevToolsNodeUtils, DevToolsPluginOptions, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevToolsTerminalHost, DevToolsTerminalSession, DevToolsTerminalSessionBase, DevToolsTerminalSessionStreamChunkEvent, DevToolsTerminalStatus, DevToolsViewAction, DevToolsViewBuiltin, DevToolsViewCustomRender, DevToolsViewHost, DevToolsViewIframe, DevToolsViewLauncher, DevToolsViewLauncherStatus, EntriesToObject, EventEmitter, EventUnsubscribe, EventsMap, PartialWithoutId, PluginWithDevTools, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsHost, Thenable, ViteConfigDevtoolsOptions, defineRpcFunction };
9
+ export { ClientScriptEntry, ConnectionMeta, DevToolsCapabilities, DevToolsChildProcessExecuteOptions, DevToolsChildProcessTerminalSession, DevToolsDockEntry, DevToolsDockEntryBase, DevToolsDockEntryCategory, DevToolsDockEntryIcon, DevToolsDockHost, DevToolsDockUserEntry, DevToolsNodeContext, DevToolsNodeRpcSession, DevToolsNodeRpcSessionMeta, DevToolsNodeUtils, DevToolsPluginOptions, DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, DevToolsRpcSharedStates, DevToolsTerminalHost, DevToolsTerminalSession, DevToolsTerminalSessionBase, DevToolsTerminalSessionStreamChunkEvent, DevToolsTerminalStatus, DevToolsViewAction, DevToolsViewBuiltin, DevToolsViewCustomRender, DevToolsViewHost, DevToolsViewIframe, DevToolsViewLauncher, DevToolsViewLauncherStatus, EntriesToObject, EventEmitter, EventUnsubscribe, EventsMap, PartialWithoutId, PluginWithDevTools, RpcBroadcastOptions, RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsHost, RpcSharedStateGetOptions, RpcSharedStateHost, Thenable, ViteConfigDevtoolsOptions, defineRpcFunction };
@@ -0,0 +1,53 @@
1
+ import { t as EventEmitter } from "./events-ChUECkY3.mjs";
2
+ import { Objectish, Patch, Patch as SharedStatePatch } from "immer";
3
+
4
+ //#region src/utils/shared-state.d.ts
5
+ type ImmutablePrimitive = undefined | null | boolean | string | number | Function;
6
+ 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>;
7
+ type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
8
+ type ImmutableMap<K$1, V$1> = ReadonlyMap<Immutable<K$1>, Immutable<V$1>>;
9
+ type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
10
+ type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
11
+ /**
12
+ * State host that is immutable by default with explicit mutate.
13
+ */
14
+ interface SharedState<T> {
15
+ /**
16
+ * Get the current state. Immutable.
17
+ */
18
+ value: () => Immutable<T>;
19
+ /**
20
+ * Subscribe to state changes.
21
+ */
22
+ on: EventEmitter<SharedStateEvents<T>>['on'];
23
+ /**
24
+ * Mutate the state.
25
+ */
26
+ mutate: (fn: (state: T) => void, syncId?: string) => void;
27
+ /**
28
+ * Apply patches to the state.
29
+ */
30
+ patch: (patches: Patch[], syncId?: string) => void;
31
+ /**
32
+ * Sync IDs that have been applied to the state.
33
+ */
34
+ syncIds: Set<string>;
35
+ }
36
+ interface SharedStateEvents<T> {
37
+ updated: (fullState: T, patches: Patch[] | undefined, syncId: string) => void;
38
+ }
39
+ interface SharedStateOptions<T> {
40
+ /**
41
+ * Initial state.
42
+ */
43
+ initialValue: T;
44
+ /**
45
+ * Enable patches.
46
+ *
47
+ * @default false
48
+ */
49
+ enablePatches?: boolean;
50
+ }
51
+ declare function createSharedState<T extends Objectish>(options: SharedStateOptions<T>): SharedState<T>;
52
+ //#endregion
53
+ export { ImmutableSet as a, SharedStateOptions as c, ImmutableObject as i, SharedStatePatch as l, ImmutableArray as n, SharedState as o, ImmutableMap as r, SharedStateEvents as s, Immutable as t, createSharedState as u };
@@ -0,0 +1,38 @@
1
+ import { t as createEventEmitter } from "./events-CWYZG96x.mjs";
2
+ import { t as nanoid } from "./nanoid-B0pJU5uW.mjs";
3
+ import { applyPatches, enablePatches, produce, produceWithPatches } from "immer";
4
+
5
+ //#region src/utils/shared-state.ts
6
+ function createSharedState(options) {
7
+ const { enablePatches: enablePatches$1 = false } = options;
8
+ const events = createEventEmitter();
9
+ let state = options.initialValue;
10
+ const syncIds = /* @__PURE__ */ new Set();
11
+ return {
12
+ on: events.on,
13
+ value: () => state,
14
+ patch: (patches, syncId = nanoid()) => {
15
+ if (syncIds.has(syncId)) return;
16
+ enablePatches();
17
+ state = applyPatches(state, patches);
18
+ syncIds.add(syncId);
19
+ events.emit("updated", state, void 0, syncId);
20
+ },
21
+ mutate: (fn, syncId = nanoid()) => {
22
+ if (syncIds.has(syncId)) return;
23
+ syncIds.add(syncId);
24
+ if (enablePatches$1) {
25
+ const [newState, patches] = produceWithPatches(state, fn);
26
+ state = newState;
27
+ events.emit("updated", state, patches, syncId);
28
+ } else {
29
+ state = produce(state, fn);
30
+ events.emit("updated", state, void 0, syncId);
31
+ }
32
+ },
33
+ syncIds
34
+ };
35
+ }
36
+
37
+ //#endregion
38
+ export { createSharedState as t };
@@ -1,4 +1,4 @@
1
- import { r as EventsMap, t as EventEmitter } from "../events-BrHMyEqJ.mjs";
1
+ import { r as EventsMap, t as EventEmitter } from "../events-ChUECkY3.mjs";
2
2
 
3
3
  //#region src/utils/events.d.ts
4
4
 
@@ -1,50 +1,2 @@
1
- import { t as EventEmitter } from "../events-BrHMyEqJ.mjs";
2
- import { Objectish, Patch } from "immer";
3
-
4
- //#region src/utils/shared-state.d.ts
5
- type ImmutablePrimitive = undefined | null | boolean | string | number | Function;
6
- 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>;
7
- type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
8
- type ImmutableMap<K$1, V$1> = ReadonlyMap<Immutable<K$1>, Immutable<V$1>>;
9
- type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
10
- type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
11
- /**
12
- * State host that is immutable by default with explicit mutate.
13
- */
14
- interface SharedState<T> {
15
- /**
16
- * Get the current state. Immutable.
17
- */
18
- get: () => Immutable<T>;
19
- /**
20
- * Subscribe to state changes.
21
- */
22
- on: EventEmitter<SharedStateEvents<T>>['on'];
23
- /**
24
- * Mutate the state.
25
- */
26
- mutate: (fn: (state: T) => void) => void;
27
- /**
28
- * Apply patches to the state.
29
- */
30
- patch: (patches: Patch[]) => void;
31
- }
32
- interface SharedStateEvents<T> {
33
- updated: (state: T) => void;
34
- patches: (patches: Patch[]) => void;
35
- }
36
- interface SharedStateOptions<T> {
37
- /**
38
- * Initial state.
39
- */
40
- initialState: T;
41
- /**
42
- * Enable patches.
43
- *
44
- * @default false
45
- */
46
- enablePatches?: boolean;
47
- }
48
- declare function createSharedState<T extends Objectish>(options: SharedStateOptions<T>): SharedState<T>;
49
- //#endregion
50
- export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, createSharedState };
1
+ import { a as ImmutableSet, c as SharedStateOptions, i as ImmutableObject, l as SharedStatePatch, n as ImmutableArray, o as SharedState, r as ImmutableMap, s as SharedStateEvents, t as Immutable, u as createSharedState } from "../shared-state-7JDpUVVs.mjs";
2
+ export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, SharedStatePatch, createSharedState };
@@ -1,28 +1,3 @@
1
- import { t as createEventEmitter } from "../events-CWYZG96x.mjs";
2
- import { applyPatches, produce, produceWithPatches } from "immer";
1
+ import { t as createSharedState } from "../shared-state-BAC6HwFS.mjs";
3
2
 
4
- //#region src/utils/shared-state.ts
5
- function createSharedState(options) {
6
- const { enablePatches = false } = options;
7
- const events = createEventEmitter();
8
- let state = options.initialState;
9
- return {
10
- on: events.on,
11
- get: () => state,
12
- patch: (patches) => {
13
- state = applyPatches(state, patches);
14
- events.emit("updated", state);
15
- },
16
- mutate: (fn) => {
17
- if (enablePatches) {
18
- const [newState, patches] = produceWithPatches(state, fn);
19
- state = newState;
20
- events.emit("patches", patches);
21
- } else state = produce(state, fn);
22
- events.emit("updated", state);
23
- }
24
- };
25
- }
26
-
27
- //#endregion
28
3
  export { createSharedState };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitejs/devtools-kit",
3
3
  "type": "module",
4
- "version": "0.0.0-alpha.21",
4
+ "version": "0.0.0-alpha.23",
5
5
  "description": "Vite DevTools Kit",
6
6
  "author": "VoidZero Inc.",
7
7
  "license": "MIT",
@@ -38,13 +38,13 @@
38
38
  "dependencies": {
39
39
  "birpc": "^4.0.0",
40
40
  "birpc-x": "0.0.6",
41
- "immer": "^11.1.0",
42
- "@vitejs/devtools-rpc": "0.0.0-alpha.21"
41
+ "immer": "^11.1.3",
42
+ "@vitejs/devtools-rpc": "0.0.0-alpha.23"
43
43
  },
44
44
  "devDependencies": {
45
45
  "my-ua-parser": "^2.0.4",
46
- "tsdown": "^0.18.2",
47
- "vite": "^8.0.0-beta.3"
46
+ "tsdown": "^0.18.4",
47
+ "vite": "^8.0.0-beta.5"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsdown",