@vitejs/devtools-kit 0.0.0-alpha.21 → 0.0.0-alpha.22
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 +2 -1
- package/dist/client.mjs +59 -1
- package/dist/{index-FzXSK6np.d.mts → index-mqRYU7D7.d.mts} +38 -9
- package/dist/index.d.mts +4 -3
- package/dist/shared-state-BLTtoMWB.d.mts +53 -0
- package/dist/shared-state-Bi50d6nv.mjs +38 -0
- package/dist/utils/events.d.mts +1 -1
- package/dist/utils/shared-state.d.mts +2 -50
- package/dist/utils/shared-state.mjs +1 -26
- package/package.json +2 -2
- /package/dist/{events-BrHMyEqJ.d.mts → events-ChUECkY3.d.mts} +0 -0
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-
|
|
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-mqRYU7D7.mjs";
|
|
2
|
+
import "./shared-state-BLTtoMWB.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-Bi50d6nv.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,60 @@ 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: async (key, syncId) => {
|
|
1115
|
+
const state = sharedState.get(key);
|
|
1116
|
+
if (!state || state.syncIds.has(syncId)) return;
|
|
1117
|
+
const newState = await rpc.call("vite:internal:rpc:server-state:get", key);
|
|
1118
|
+
state.mutate(() => newState, syncId);
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
rpc.client.register({
|
|
1122
|
+
name: "vite:internal:rpc:client-state:patch",
|
|
1123
|
+
type: "event",
|
|
1124
|
+
handler: async (key, patches, syncId) => {
|
|
1125
|
+
const state = sharedState.get(key);
|
|
1126
|
+
if (state) 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
|
+
if (options?.initialValue !== void 0) {
|
|
1142
|
+
const state = createSharedState({
|
|
1143
|
+
initialState: options.initialValue,
|
|
1144
|
+
enablePatches: false
|
|
1145
|
+
});
|
|
1146
|
+
sharedState.set(key, state);
|
|
1147
|
+
registerSharedState(key, state);
|
|
1148
|
+
return state;
|
|
1149
|
+
} else {
|
|
1150
|
+
const state = createSharedState({
|
|
1151
|
+
initialState: await rpc.call("vite:internal:rpc:server-state:get", key),
|
|
1152
|
+
enablePatches: false
|
|
1153
|
+
});
|
|
1154
|
+
sharedState.set(key, state);
|
|
1155
|
+
registerSharedState(key, state);
|
|
1156
|
+
return state;
|
|
1157
|
+
}
|
|
1158
|
+
} };
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1106
1161
|
//#endregion
|
|
1107
1162
|
//#region src/client/rpc.ts
|
|
1108
1163
|
const CONNECTION_META_KEY = "__VITE_DEVTOOLS_CONNECTION_META__";
|
|
@@ -1165,6 +1220,7 @@ async function getDevToolsRpcClient(options = {}) {
|
|
|
1165
1220
|
const serverRpc = createRpcClient(clientRpc.functions, {
|
|
1166
1221
|
preset: createWsRpcPreset({
|
|
1167
1222
|
url,
|
|
1223
|
+
authId,
|
|
1168
1224
|
...options.wsOptions
|
|
1169
1225
|
}),
|
|
1170
1226
|
rpcOptions
|
|
@@ -1219,8 +1275,10 @@ async function getDevToolsRpcClient(options = {}) {
|
|
|
1219
1275
|
callOptional: (...args) => {
|
|
1220
1276
|
return serverRpc.$callOptional(...args);
|
|
1221
1277
|
},
|
|
1222
|
-
client: clientRpc
|
|
1278
|
+
client: clientRpc,
|
|
1279
|
+
sharedState: void 0
|
|
1223
1280
|
};
|
|
1281
|
+
rpc.sharedState = createRpcSharedStateClientHost(rpc);
|
|
1224
1282
|
context.rpc = rpc;
|
|
1225
1283
|
requestTrust();
|
|
1226
1284
|
return rpc;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as EventEmitter } from "./events-
|
|
1
|
+
import { t as EventEmitter } from "./events-ChUECkY3.mjs";
|
|
2
|
+
import { o as SharedState } from "./shared-state-BLTtoMWB.mjs";
|
|
2
3
|
import { RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
|
|
3
4
|
import { Raw } from "vue";
|
|
4
5
|
import { BirpcOptions, BirpcReturn } from "birpc";
|
|
@@ -99,6 +100,14 @@ interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
|
|
|
99
100
|
type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
|
|
100
101
|
type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
|
|
101
102
|
//#endregion
|
|
103
|
+
//#region ../rpc/src/presets/ws/server.d.ts
|
|
104
|
+
interface DevToolsNodeRpcSessionMeta {
|
|
105
|
+
id: number;
|
|
106
|
+
ws?: WebSocket;
|
|
107
|
+
clientAuthId?: string;
|
|
108
|
+
isTrusted?: boolean;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
102
111
|
//#region src/types/rpc-augments.d.ts
|
|
103
112
|
/**
|
|
104
113
|
* To be extended
|
|
@@ -108,6 +117,10 @@ interface DevToolsRpcClientFunctions {}
|
|
|
108
117
|
* To be extended
|
|
109
118
|
*/
|
|
110
119
|
interface DevToolsRpcServerFunctions {}
|
|
120
|
+
/**
|
|
121
|
+
* To be extended
|
|
122
|
+
*/
|
|
123
|
+
interface DevToolsRpcSharedStates {}
|
|
111
124
|
//#endregion
|
|
112
125
|
//#region src/types/terminals.d.ts
|
|
113
126
|
interface DevToolsTerminalSessionStreamChunkEvent {
|
|
@@ -239,28 +252,39 @@ interface ConnectionMeta {
|
|
|
239
252
|
}
|
|
240
253
|
//#endregion
|
|
241
254
|
//#region src/types/rpc.d.ts
|
|
242
|
-
interface DevToolsNodeRpcSessionMeta {
|
|
243
|
-
id: number;
|
|
244
|
-
ws?: WebSocket;
|
|
245
|
-
clientAuthId?: string;
|
|
246
|
-
isTrusted?: boolean;
|
|
247
|
-
}
|
|
248
255
|
interface DevToolsNodeRpcSession {
|
|
249
256
|
meta: DevToolsNodeRpcSessionMeta;
|
|
250
257
|
rpc: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>;
|
|
251
258
|
}
|
|
259
|
+
interface RpcBroadcastOptions<METHOD, Args extends any[]> {
|
|
260
|
+
method: METHOD;
|
|
261
|
+
args: Args;
|
|
262
|
+
optional?: boolean;
|
|
263
|
+
event?: boolean;
|
|
264
|
+
filter?: (client: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>) => boolean | void;
|
|
265
|
+
}
|
|
252
266
|
type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
|
|
253
267
|
/**
|
|
254
268
|
* Broadcast a message to all connected clients
|
|
255
269
|
*/
|
|
256
|
-
broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(
|
|
270
|
+
broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(options: RpcBroadcastOptions<T, Args>) => Promise<void>;
|
|
257
271
|
/**
|
|
258
272
|
* Get the current RPC client
|
|
259
273
|
*
|
|
260
274
|
* Available in RPC functions to get the current RPC client
|
|
261
275
|
*/
|
|
262
276
|
getCurrentRpcSession: () => DevToolsNodeRpcSession | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* The shared state host
|
|
279
|
+
*/
|
|
280
|
+
sharedState: RpcSharedStateHost;
|
|
263
281
|
};
|
|
282
|
+
interface RpcSharedStateGetOptions<T> {
|
|
283
|
+
initialValue?: T;
|
|
284
|
+
}
|
|
285
|
+
interface RpcSharedStateHost {
|
|
286
|
+
get: <T extends keyof DevToolsRpcSharedStates>(key: T, options?: RpcSharedStateGetOptions<DevToolsRpcSharedStates[T]>) => Promise<SharedState<DevToolsRpcSharedStates[T]>>;
|
|
287
|
+
}
|
|
264
288
|
//#endregion
|
|
265
289
|
//#region src/types/utils.d.ts
|
|
266
290
|
type Thenable<T> = T | Promise<T>;
|
|
@@ -302,6 +326,7 @@ interface WebSocketRpcClientOptions {
|
|
|
302
326
|
onConnected?: (e: Event) => void;
|
|
303
327
|
onError?: (e: Error) => void;
|
|
304
328
|
onDisconnected?: (e: CloseEvent) => void;
|
|
329
|
+
authId?: string;
|
|
305
330
|
}
|
|
306
331
|
//#endregion
|
|
307
332
|
//#region src/client/rpc.d.ts
|
|
@@ -356,6 +381,10 @@ interface DevToolsRpcClient {
|
|
|
356
381
|
* The client RPC host
|
|
357
382
|
*/
|
|
358
383
|
client: DevToolsClientRpcHost;
|
|
384
|
+
/**
|
|
385
|
+
* The shared state host
|
|
386
|
+
*/
|
|
387
|
+
sharedState: RpcSharedStateHost;
|
|
359
388
|
}
|
|
360
389
|
declare function getDevToolsRpcClient(options?: DevToolsRpcClientOptions): Promise<DevToolsRpcClient>;
|
|
361
390
|
//#endregion
|
|
@@ -453,4 +482,4 @@ interface DockClientScriptContext extends DocksContext {
|
|
|
453
482
|
current: DockEntryState;
|
|
454
483
|
}
|
|
455
484
|
//#endregion
|
|
456
|
-
export {
|
|
485
|
+
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-
|
|
2
|
-
import { A as
|
|
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-mqRYU7D7.mjs";
|
|
3
|
+
import "./shared-state-BLTtoMWB.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
|
+
initialState: 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.initialState;
|
|
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 };
|
package/dist/utils/events.d.mts
CHANGED
|
@@ -1,50 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
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-BLTtoMWB.mjs";
|
|
2
|
+
export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, SharedStatePatch, createSharedState };
|
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { applyPatches, produce, produceWithPatches } from "immer";
|
|
1
|
+
import { t as createSharedState } from "../shared-state-Bi50d6nv.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.
|
|
4
|
+
"version": "0.0.0-alpha.22",
|
|
5
5
|
"description": "Vite DevTools Kit",
|
|
6
6
|
"author": "VoidZero Inc.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"birpc": "^4.0.0",
|
|
40
40
|
"birpc-x": "0.0.6",
|
|
41
41
|
"immer": "^11.1.0",
|
|
42
|
-
"@vitejs/devtools-rpc": "0.0.0-alpha.
|
|
42
|
+
"@vitejs/devtools-rpc": "0.0.0-alpha.22"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"my-ua-parser": "^2.0.4",
|
|
File without changes
|