@vitejs/devtools-kit 0.0.0-alpha.26 → 0.0.0-alpha.28

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,507 +0,0 @@
1
- import { t as EventEmitter } from "./events-C3OiqHBC.mjs";
2
- import { o as SharedState } from "./shared-state-BjG-wgCU.mjs";
3
- import * as birpc_x0 from "birpc-x";
4
- import { RpcDefinitionsFilter, RpcDefinitionsToFunctions, RpcFunctionsCollector, RpcFunctionsCollectorBase } from "birpc-x";
5
- import { Raw } from "vue";
6
- import { BirpcOptions, BirpcReturn } from "birpc";
7
- import { WebSocket } from "ws";
8
- import { Plugin, ResolvedConfig, ViteDevServer } from "vite";
9
- import { ChildProcess } from "node:child_process";
10
-
11
- //#region src/types/docks.d.ts
12
- interface DevToolsDockHost {
13
- readonly views: Map<string, DevToolsDockUserEntry>;
14
- readonly events: EventEmitter<{
15
- 'dock:entry:updated': (entry: DevToolsDockUserEntry) => void;
16
- }>;
17
- register: <T extends DevToolsDockUserEntry>(entry: T, force?: boolean) => {
18
- update: (patch: Partial<T>) => void;
19
- };
20
- update: (entry: DevToolsDockUserEntry) => void;
21
- values: (options?: {
22
- includeBuiltin?: boolean;
23
- }) => DevToolsDockEntry[];
24
- }
25
- type DevToolsDockEntryCategory = 'app' | 'framework' | 'web' | 'advanced' | 'default' | '~viteplus' | '~builtin';
26
- type DevToolsDockEntryIcon = string | {
27
- light: string;
28
- dark: string;
29
- };
30
- interface DevToolsDockEntryBase {
31
- id: string;
32
- title: string;
33
- icon: DevToolsDockEntryIcon;
34
- /**
35
- * The default order of the entry in the dock.
36
- * The higher the number the earlier it appears.
37
- * @default 0
38
- */
39
- defaultOrder?: number;
40
- /**
41
- * The category of the entry
42
- * @default 'default'
43
- */
44
- category?: DevToolsDockEntryCategory;
45
- /**
46
- * Whether the entry should be hidden from the user.
47
- * @default false
48
- */
49
- isHidden?: boolean;
50
- }
51
- interface ClientScriptEntry {
52
- /**
53
- * The filepath or module name to import from
54
- */
55
- importFrom: string;
56
- /**
57
- * The name to import the module as
58
- *
59
- * @default 'default'
60
- */
61
- importName?: string;
62
- }
63
- interface DevToolsViewIframe extends DevToolsDockEntryBase {
64
- type: 'iframe';
65
- url: string;
66
- /**
67
- * The id of the iframe, if multiple tabs is assigned with the same id, the iframe will be shared.
68
- *
69
- * When not provided, it would be treated as a unique frame.
70
- */
71
- frameId?: string;
72
- /**
73
- * Optional client script to import into the iframe
74
- */
75
- clientScript?: ClientScriptEntry;
76
- }
77
- type DevToolsViewLauncherStatus = 'idle' | 'loading' | 'success' | 'error';
78
- interface DevToolsViewLauncher extends DevToolsDockEntryBase {
79
- type: 'launcher';
80
- launcher: {
81
- icon?: DevToolsDockEntryIcon;
82
- title: string;
83
- status?: DevToolsViewLauncherStatus;
84
- error?: string;
85
- description?: string;
86
- buttonStart?: string;
87
- buttonLoading?: string;
88
- onLaunch: () => Promise<void>;
89
- };
90
- }
91
- interface DevToolsViewAction extends DevToolsDockEntryBase {
92
- type: 'action';
93
- action: ClientScriptEntry;
94
- }
95
- interface DevToolsViewCustomRender extends DevToolsDockEntryBase {
96
- type: 'custom-render';
97
- renderer: ClientScriptEntry;
98
- }
99
- interface DevToolsViewBuiltin extends DevToolsDockEntryBase {
100
- type: '~builtin';
101
- id: '~terminals' | '~logs' | '~client-auth-notice' | '~settings';
102
- }
103
- type DevToolsDockUserEntry = DevToolsViewIframe | DevToolsViewAction | DevToolsViewCustomRender | DevToolsViewLauncher;
104
- type DevToolsDockEntry = DevToolsDockUserEntry | DevToolsViewBuiltin;
105
- //#endregion
106
- //#region ../rpc/src/presets/ws/server.d.ts
107
- interface DevToolsNodeRpcSessionMeta {
108
- id: number;
109
- ws?: WebSocket;
110
- clientAuthId?: string;
111
- isTrusted?: boolean;
112
- subscribedStates: Set<string>;
113
- }
114
- //#endregion
115
- //#region src/types/rpc-augments.d.ts
116
- /**
117
- * To be extended
118
- */
119
- interface DevToolsRpcClientFunctions {}
120
- /**
121
- * To be extended
122
- */
123
- interface DevToolsRpcServerFunctions {}
124
- /**
125
- * To be extended
126
- */
127
- interface DevToolsRpcSharedStates {}
128
- //#endregion
129
- //#region src/types/terminals.d.ts
130
- interface DevToolsTerminalSessionStreamChunkEvent {
131
- id: string;
132
- chunks: string[];
133
- ts: number;
134
- }
135
- interface DevToolsTerminalHost {
136
- readonly sessions: Map<string, DevToolsTerminalSession>;
137
- readonly events: EventEmitter<{
138
- 'terminal:session:updated': (session: DevToolsTerminalSession) => void;
139
- 'terminal:session:stream-chunk': (data: DevToolsTerminalSessionStreamChunkEvent) => void;
140
- }>;
141
- register: (session: DevToolsTerminalSession) => DevToolsTerminalSession;
142
- update: (session: DevToolsTerminalSession) => void;
143
- startChildProcess: (executeOptions: DevToolsChildProcessExecuteOptions, terminal: Omit<DevToolsTerminalSessionBase, 'status'>) => Promise<DevToolsChildProcessTerminalSession>;
144
- }
145
- type DevToolsTerminalStatus = 'running' | 'stopped' | 'error';
146
- interface DevToolsTerminalSessionBase {
147
- id: string;
148
- title: string;
149
- description?: string;
150
- status: DevToolsTerminalStatus;
151
- icon?: DevToolsDockEntryIcon;
152
- }
153
- interface DevToolsTerminalSession extends DevToolsTerminalSessionBase {
154
- buffer?: string[];
155
- stream?: ReadableStream<string>;
156
- }
157
- interface DevToolsChildProcessExecuteOptions {
158
- command: string;
159
- args: string[];
160
- cwd?: string;
161
- env?: Record<string, string>;
162
- }
163
- interface DevToolsChildProcessTerminalSession extends DevToolsTerminalSession {
164
- type: 'child-process';
165
- executeOptions: DevToolsChildProcessExecuteOptions;
166
- getChildProcess: () => ChildProcess | undefined;
167
- terminate: () => Promise<void>;
168
- restart: () => Promise<void>;
169
- }
170
- //#endregion
171
- //#region src/types/views.d.ts
172
- interface DevToolsViewHost {
173
- /**
174
- * @internal
175
- */
176
- buildStaticDirs: {
177
- baseUrl: string;
178
- distDir: string;
179
- }[];
180
- /**
181
- * Helper to host static files
182
- * - In `dev` mode, it will register middleware to `viteServer.middlewares` to host the static files
183
- * - In `build` mode, it will copy the static files to the dist directory
184
- */
185
- hostStatic: (baseUrl: string, distDir: string) => void;
186
- }
187
- //#endregion
188
- //#region src/types/vite-plugin.d.ts
189
- interface DevToolsCapabilities {
190
- rpc?: boolean;
191
- views?: boolean;
192
- }
193
- interface DevToolsPluginOptions {
194
- capabilities?: {
195
- dev?: DevToolsCapabilities | boolean;
196
- build?: DevToolsCapabilities | boolean;
197
- };
198
- setup: (context: DevToolsNodeContext) => void | Promise<void>;
199
- }
200
- interface DevToolsNodeContext {
201
- /**
202
- * Workspace root directory of Vite DevTools
203
- */
204
- readonly workspaceRoot: string;
205
- /**
206
- * Current working directory of Vite DevTools
207
- */
208
- readonly cwd: string;
209
- /**
210
- * Current mode of Vite DevTools
211
- * - 'dev' - when Vite DevTools is running in dev mode
212
- * - 'build' - when Vite DevTools is running in build mode (no server)
213
- */
214
- readonly mode: 'dev' | 'build';
215
- /**
216
- * Resolved Vite configuration
217
- */
218
- readonly viteConfig: ResolvedConfig;
219
- /**
220
- * Vite dev server instance (only available in dev mode)
221
- */
222
- readonly viteServer?: ViteDevServer;
223
- /**
224
- * RPC functions host, for registering server-side RPC functions and calling client-side RPC functions
225
- */
226
- rpc: RpcFunctionsHost;
227
- /**
228
- * Docks host, for registering dock entries
229
- */
230
- docks: DevToolsDockHost;
231
- /**
232
- * Views host, for registering static views
233
- */
234
- views: DevToolsViewHost;
235
- /**
236
- * Utils for the node context
237
- */
238
- utils: DevToolsNodeUtils;
239
- /**
240
- * Terminals host, for registering terminal sessions and streaming terminal output
241
- */
242
- terminals: DevToolsTerminalHost;
243
- }
244
- interface DevToolsNodeUtils {
245
- /**
246
- * Create a simple client script from a function or stringified code
247
- *
248
- * @deprecated DO NOT USE. This is mostly for testing only. Please use a proper importable module instead.
249
- * @experimental
250
- */
251
- createSimpleClientScript: (fn: string | ((ctx: DockClientScriptContext) => void)) => ClientScriptEntry;
252
- }
253
- interface ConnectionMeta {
254
- backend: 'websocket' | 'static';
255
- websocket?: number | string;
256
- }
257
- //#endregion
258
- //#region src/types/rpc.d.ts
259
- interface DevToolsNodeRpcSession {
260
- meta: DevToolsNodeRpcSessionMeta;
261
- rpc: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>;
262
- }
263
- interface RpcBroadcastOptions<METHOD, Args extends any[]> {
264
- method: METHOD;
265
- args: Args;
266
- optional?: boolean;
267
- event?: boolean;
268
- filter?: (client: BirpcReturn<DevToolsRpcClientFunctions, DevToolsRpcServerFunctions, false>) => boolean | void;
269
- }
270
- type RpcFunctionsHost = RpcFunctionsCollectorBase<DevToolsRpcServerFunctions, DevToolsNodeContext> & {
271
- /**
272
- * Broadcast a message to all connected clients
273
- */
274
- broadcast: <T extends keyof DevToolsRpcClientFunctions, Args extends Parameters<DevToolsRpcClientFunctions[T]>>(options: RpcBroadcastOptions<T, Args>) => Promise<void>;
275
- /**
276
- * Get the current RPC client
277
- *
278
- * Available in RPC functions to get the current RPC client
279
- */
280
- getCurrentRpcSession: () => DevToolsNodeRpcSession | undefined;
281
- /**
282
- * The shared state host
283
- */
284
- sharedState: RpcSharedStateHost;
285
- };
286
- interface RpcSharedStateGetOptions<T> {
287
- sharedState?: SharedState<T>;
288
- initialValue?: T;
289
- }
290
- interface RpcSharedStateHost {
291
- get: <T extends keyof DevToolsRpcSharedStates>(key: T, options?: RpcSharedStateGetOptions<DevToolsRpcSharedStates[T]>) => Promise<SharedState<DevToolsRpcSharedStates[T]>>;
292
- }
293
- //#endregion
294
- //#region src/types/settings.d.ts
295
- interface DevToolsDocksUserSettings {
296
- docksHidden: string[];
297
- docksCategoriesHidden: string[];
298
- docksPinned: string[];
299
- docksCustomOrder: Record<string, number>;
300
- showIframeAddressBar: boolean;
301
- }
302
- //#endregion
303
- //#region src/types/utils.d.ts
304
- type Thenable<T> = T | Promise<T>;
305
- type EntriesToObject<T extends readonly [string, any][]> = { [K in T[number] as K[0]]: K[1] };
306
- type PartialWithoutId<T extends {
307
- id: string;
308
- }> = Partial<Omit<T, 'id'>> & {
309
- id: string;
310
- };
311
- //#endregion
312
- //#region src/types/vite-augment.d.ts
313
- declare module 'vite' {
314
- interface Plugin {
315
- devtools?: DevToolsPluginOptions;
316
- }
317
- interface UserConfig {
318
- devtools?: ViteConfigDevtoolsOptions;
319
- }
320
- }
321
- interface ViteConfigDevtoolsOptions {
322
- /**
323
- * Disable client authentication.
324
- *
325
- * Beware that if you disable client authentication,
326
- * any browsers can connect to the devtools and access to your server and filesystem.
327
- * (including other devices, if you open server `host` option to LAN or WAN)
328
- *
329
- * @default true
330
- */
331
- clientAuth?: boolean;
332
- }
333
- interface PluginWithDevTools extends Plugin {
334
- devtools?: DevToolsPluginOptions;
335
- }
336
- //#endregion
337
- //#region src/utils/define.d.ts
338
- 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>;
339
- //#endregion
340
- //#region ../core/src/client/webcomponents/state/dock-settings.d.ts
341
- type DevToolsDockEntriesGrouped = [category: string, entries: DevToolsDockEntry[]][];
342
- //#endregion
343
- //#region ../rpc/src/presets/ws/client.d.ts
344
- interface WebSocketRpcClientOptions {
345
- url: string;
346
- onConnected?: (e: Event) => void;
347
- onError?: (e: Error) => void;
348
- onDisconnected?: (e: CloseEvent) => void;
349
- authId?: string;
350
- }
351
- //#endregion
352
- //#region src/client/rpc.d.ts
353
- interface DevToolsRpcClientOptions {
354
- connectionMeta?: ConnectionMeta;
355
- baseURL?: string[];
356
- /**
357
- * The auth id to use for the client
358
- */
359
- authId?: string;
360
- wsOptions?: Partial<WebSocketRpcClientOptions>;
361
- rpcOptions?: Partial<BirpcOptions<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions, boolean>>;
362
- }
363
- interface DevToolsRpcClient {
364
- /**
365
- * The events of the client
366
- */
367
- events: EventEmitter<RpcClientEvents>;
368
- /**
369
- * Whether the client is trusted
370
- */
371
- readonly isTrusted: boolean | null;
372
- /**
373
- * The connection meta
374
- */
375
- readonly connectionMeta: ConnectionMeta;
376
- /**
377
- * Return a promise that resolves when the client is trusted
378
- *
379
- * Rejects with an error if the timeout is reached
380
- *
381
- * @param timeout - The timeout in milliseconds, default to 60 seconds
382
- */
383
- ensureTrusted: (timeout?: number) => Promise<boolean>;
384
- /**
385
- * Request trust from the server
386
- */
387
- requestTrust: () => Promise<boolean>;
388
- /**
389
- * Call a RPC function on the server
390
- */
391
- call: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$call'];
392
- /**
393
- * Call a RPC event on the server, and does not expect a response
394
- */
395
- callEvent: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callEvent'];
396
- /**
397
- * Call a RPC optional function on the server
398
- */
399
- callOptional: BirpcReturn<DevToolsRpcServerFunctions, DevToolsRpcClientFunctions>['$callOptional'];
400
- /**
401
- * The client RPC host
402
- */
403
- client: DevToolsClientRpcHost;
404
- /**
405
- * The shared state host
406
- */
407
- sharedState: RpcSharedStateHost;
408
- }
409
- declare function getDevToolsRpcClient(options?: DevToolsRpcClientOptions): Promise<DevToolsRpcClient>;
410
- //#endregion
411
- //#region src/client/docks.d.ts
412
- interface DockPanelStorage {
413
- width: number;
414
- height: number;
415
- top: number;
416
- left: number;
417
- position: 'left' | 'right' | 'bottom' | 'top';
418
- open: boolean;
419
- inactiveTimeout: number;
420
- }
421
- type DockClientType = 'embedded' | 'standalone';
422
- interface DevToolsClientContext {
423
- /**
424
- * The RPC client to interact with the server
425
- */
426
- readonly rpc: DevToolsRpcClient;
427
- }
428
- interface DocksContext extends DevToolsClientContext {
429
- /**
430
- * Type of the client environment
431
- *
432
- * 'embedded' - running inside an embedded floating panel
433
- * 'standalone' - running inside a standalone window (no user app)
434
- */
435
- readonly clientType: 'embedded' | 'standalone';
436
- /**
437
- * The panel context
438
- */
439
- readonly panel: DocksPanelContext;
440
- /**
441
- * The docks entries context
442
- */
443
- readonly docks: DocksEntriesContext;
444
- }
445
- type DevToolsClientRpcHost = RpcFunctionsCollector<DevToolsRpcClientFunctions, DevToolsClientContext>;
446
- interface DocksPanelContext {
447
- store: DockPanelStorage;
448
- isDragging: boolean;
449
- isResizing: boolean;
450
- readonly isVertical: boolean;
451
- }
452
- interface DocksEntriesContext {
453
- selectedId: string | null;
454
- readonly selected: DevToolsDockEntry | null;
455
- entries: DevToolsDockEntry[];
456
- entryToStateMap: Map<string, DockEntryState>;
457
- groupedEntries: DevToolsDockEntriesGrouped;
458
- settings: SharedState<DevToolsDocksUserSettings>;
459
- /**
460
- * Get the state of a dock entry by its ID
461
- */
462
- getStateById: (id: string) => DockEntryState | undefined;
463
- /**
464
- * Switch to the selected dock entry, pass `null` to clear the selection
465
- *
466
- * @returns Whether the selection was changed successfully
467
- */
468
- switchEntry: (id?: string | null) => Promise<boolean>;
469
- /**
470
- * Toggle the selected dock entry
471
- *
472
- * @returns Whether the selection was changed successfully
473
- */
474
- toggleEntry: (id: string) => Promise<boolean>;
475
- }
476
- interface DockEntryState {
477
- entryMeta: DevToolsDockEntry;
478
- readonly isActive: boolean;
479
- domElements: {
480
- iframe?: HTMLIFrameElement | null;
481
- panel?: HTMLDivElement | null;
482
- };
483
- events: Raw<EventEmitter<DockEntryStateEvents>>;
484
- }
485
- interface DockEntryStateEvents {
486
- 'entry:activated': () => void;
487
- 'entry:deactivated': () => void;
488
- 'entry:updated': (newMeta: DevToolsDockUserEntry) => void;
489
- 'dom:panel:mounted': (panel: HTMLDivElement) => void;
490
- 'dom:iframe:mounted': (iframe: HTMLIFrameElement) => void;
491
- }
492
- interface RpcClientEvents {
493
- 'rpc:is-trusted:updated': (isTrusted: boolean) => void;
494
- }
495
- //#endregion
496
- //#region src/client/client-script.d.ts
497
- /**
498
- * Context for client scripts running in dock entries
499
- */
500
- interface DockClientScriptContext extends DocksContext {
501
- /**
502
- * The state of the current dock entry
503
- */
504
- current: DockEntryState;
505
- }
506
- //#endregion
507
- export { DevToolsViewAction as $, DevToolsCapabilities as A, DevToolsTerminalSessionStreamChunkEvent as B, DevToolsDocksUserSettings as C, RpcSharedStateGetOptions as D, RpcFunctionsHost as E, DevToolsChildProcessExecuteOptions as F, DevToolsNodeRpcSessionMeta as G, DevToolsRpcClientFunctions as H, DevToolsChildProcessTerminalSession as I, DevToolsDockEntryBase as J, ClientScriptEntry as K, DevToolsTerminalHost as L, DevToolsNodeUtils as M, DevToolsPluginOptions as N, RpcSharedStateHost as O, DevToolsViewHost as P, DevToolsDockUserEntry as Q, DevToolsTerminalSession as R, Thenable as S, RpcBroadcastOptions as T, DevToolsRpcServerFunctions as U, DevToolsTerminalStatus as V, DevToolsRpcSharedStates as W, DevToolsDockEntryIcon as X, DevToolsDockEntryCategory as Y, DevToolsDockHost as Z, RpcDefinitionsToFunctions as _, DockEntryState as a, EntriesToObject as b, DocksContext as c, RpcClientEvents as d, DevToolsViewBuiltin as et, DevToolsRpcClient as f, RpcDefinitionsFilter as g, defineRpcFunction as h, DockClientType as i, DevToolsViewLauncherStatus as it, DevToolsNodeContext as j, ConnectionMeta as k, DocksEntriesContext as l, getDevToolsRpcClient as m, DevToolsClientContext as n, DevToolsViewIframe as nt, DockEntryStateEvents as o, DevToolsRpcClientOptions as p, DevToolsDockEntry as q, DevToolsClientRpcHost as r, DevToolsViewLauncher as rt, DockPanelStorage as s, DockClientScriptContext as t, DevToolsViewCustomRender as tt, DocksPanelContext as u, PluginWithDevTools as v, DevToolsNodeRpcSession as w, PartialWithoutId as x, ViteConfigDevtoolsOptions as y, DevToolsTerminalSessionBase as z };
@@ -1,11 +0,0 @@
1
- //#region src/utils/nanoid.ts
2
- const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
3
- function nanoid(size = 21) {
4
- let id = "";
5
- let i = size;
6
- while (i--) id += urlAlphabet[Math.random() * 64 | 0];
7
- return id;
8
- }
9
-
10
- //#endregion
11
- export { nanoid as t };
@@ -1,53 +0,0 @@
1
- import { t as EventEmitter } from "./events-C3OiqHBC.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, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
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 };
@@ -1,38 +0,0 @@
1
- import { t as createEventEmitter } from "./events-Cjs2Ve7T.mjs";
2
- import { t as nanoid } from "./nanoid-CVty-meb.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 };