@vitejs/devtools-kit 0.1.2 → 0.1.4
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.ts +2 -2
- package/dist/client.js +59 -274
- package/dist/constants.d.ts +2 -1
- package/dist/human-id-BSiGlZOw.js +803 -0
- package/dist/{index-WxzZW3L-.d.ts → index-BSLgRVfr.d.ts} +19 -5
- package/dist/index.d.ts +2 -2
- package/dist/shared-state-CCNEYlbv.js +928 -0
- package/dist/{shared-state-BFKKxNt1.d.ts → shared-state-NxkOZ3u0.d.ts} +17 -3
- package/dist/utils/events.d.ts +1 -1
- package/dist/utils/human-id.d.ts +10 -0
- package/dist/utils/human-id.js +2 -0
- package/dist/utils/shared-state.d.ts +2 -2
- package/dist/utils/shared-state.js +1 -35
- package/package.json +10 -6
- package/skills/vite-devtools-kit/SKILL.md +13 -0
- package/skills/vite-devtools-kit/references/project-structure.md +9 -0
- package/skills/vite-devtools-kit/references/rpc-patterns.md +15 -0
- package/skills/vite-devtools-kit/references/shared-state-patterns.md +12 -1
- /package/dist/{events-B41U-zeg.d.ts → events-BTCXlxeC.d.ts} +0 -0
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import { t as EventEmitter } from "./events-
|
|
2
|
-
import { Objectish, Patch, Patch as SharedStatePatch } from "immer";
|
|
1
|
+
import { t as EventEmitter } from "./events-BTCXlxeC.js";
|
|
3
2
|
|
|
3
|
+
//#region ../../node_modules/.pnpm/immer@11.1.4/node_modules/immer/dist/immer.d.ts
|
|
4
|
+
interface Patch {
|
|
5
|
+
op: "replace" | "remove" | "add";
|
|
6
|
+
path: (string | number)[];
|
|
7
|
+
value?: any;
|
|
8
|
+
}
|
|
9
|
+
type Objectish = AnyObject | AnyArray | AnyMap | AnySet;
|
|
10
|
+
type AnyObject = {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
};
|
|
13
|
+
type AnyArray = Array<any>;
|
|
14
|
+
type AnySet = Set<any>;
|
|
15
|
+
type AnyMap = Map<any, any>;
|
|
16
|
+
/** Returns true if the given value is an Immer draft */
|
|
17
|
+
//#endregion
|
|
4
18
|
//#region src/utils/shared-state.d.ts
|
|
5
19
|
type ImmutablePrimitive = undefined | null | boolean | string | number | Function;
|
|
6
20
|
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>;
|
|
@@ -50,4 +64,4 @@ interface SharedStateOptions<T> {
|
|
|
50
64
|
}
|
|
51
65
|
declare function createSharedState<T extends Objectish>(options: SharedStateOptions<T>): SharedState<T>;
|
|
52
66
|
//#endregion
|
|
53
|
-
export { ImmutableSet as a, SharedStateOptions as c, ImmutableObject as i,
|
|
67
|
+
export { ImmutableSet as a, SharedStateOptions as c, ImmutableObject as i, createSharedState as l, ImmutableArray as n, SharedState as o, ImmutableMap as r, SharedStateEvents as s, Immutable as t, Patch as u };
|
package/dist/utils/events.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/human-id@4.1.3/node_modules/human-id/dist/index.d.ts
|
|
2
|
+
interface Options {
|
|
3
|
+
separator?: string;
|
|
4
|
+
capitalize?: boolean;
|
|
5
|
+
adjectiveCount?: number;
|
|
6
|
+
addAdverb?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare function humanId(options?: Options | string | boolean): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { humanId };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ImmutableSet, c as SharedStateOptions, i as ImmutableObject, l as
|
|
2
|
-
export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, SharedStatePatch, createSharedState };
|
|
1
|
+
import { a as ImmutableSet, c as SharedStateOptions, i as ImmutableObject, l as createSharedState, n as ImmutableArray, o as SharedState, r as ImmutableMap, s as SharedStateEvents, t as Immutable, u as Patch } from "../shared-state-NxkOZ3u0.js";
|
|
2
|
+
export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, Patch as SharedStatePatch, createSharedState };
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { nanoid } from "./nanoid.js";
|
|
3
|
-
import { applyPatches, enablePatches, produce, produceWithPatches } from "immer";
|
|
4
|
-
//#region src/utils/shared-state.ts
|
|
5
|
-
function createSharedState(options) {
|
|
6
|
-
const { enablePatches: enablePatches$1 = false } = options;
|
|
7
|
-
const events = createEventEmitter();
|
|
8
|
-
let state = options.initialValue;
|
|
9
|
-
const syncIds = /* @__PURE__ */ new Set();
|
|
10
|
-
return {
|
|
11
|
-
on: events.on,
|
|
12
|
-
value: () => state,
|
|
13
|
-
patch: (patches, syncId = nanoid()) => {
|
|
14
|
-
if (syncIds.has(syncId)) return;
|
|
15
|
-
enablePatches();
|
|
16
|
-
state = applyPatches(state, patches);
|
|
17
|
-
syncIds.add(syncId);
|
|
18
|
-
events.emit("updated", state, void 0, syncId);
|
|
19
|
-
},
|
|
20
|
-
mutate: (fn, syncId = nanoid()) => {
|
|
21
|
-
if (syncIds.has(syncId)) return;
|
|
22
|
-
syncIds.add(syncId);
|
|
23
|
-
if (enablePatches$1) {
|
|
24
|
-
const [newState, patches] = produceWithPatches(state, fn);
|
|
25
|
-
state = newState;
|
|
26
|
-
events.emit("updated", state, patches, syncId);
|
|
27
|
-
} else {
|
|
28
|
-
state = produce(state, fn);
|
|
29
|
-
events.emit("updated", state, void 0, syncId);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
syncIds
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
1
|
+
import { t as createSharedState } from "../shared-state-CCNEYlbv.js";
|
|
36
2
|
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.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "Vite DevTools Kit",
|
|
6
6
|
"author": "VoidZero Inc.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"./client": "./dist/client.js",
|
|
24
24
|
"./constants": "./dist/constants.js",
|
|
25
25
|
"./utils/events": "./dist/utils/events.js",
|
|
26
|
+
"./utils/human-id": "./dist/utils/human-id.js",
|
|
26
27
|
"./utils/nanoid": "./dist/utils/nanoid.js",
|
|
27
28
|
"./utils/shared-state": "./dist/utils/shared-state.js",
|
|
28
29
|
"./package.json": "./package.json"
|
|
@@ -37,16 +38,19 @@
|
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"birpc": "^4.0.0",
|
|
40
|
-
"
|
|
41
|
-
"@vitejs/devtools-rpc": "0.1.
|
|
41
|
+
"ohash": "^2.0.11",
|
|
42
|
+
"@vitejs/devtools-rpc": "0.1.4"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
+
"human-id": "^4.1.3",
|
|
46
|
+
"immer": "^11.1.4",
|
|
47
|
+
"tsdown": "^0.21.4",
|
|
45
48
|
"ua-parser-modern": "^0.1.1",
|
|
46
|
-
"vite": "^8.0.
|
|
49
|
+
"vite": "^8.0.1"
|
|
47
50
|
},
|
|
48
51
|
"inlinedDependencies": {
|
|
49
|
-
"
|
|
52
|
+
"human-id": "4.1.3",
|
|
53
|
+
"immer": "11.1.4",
|
|
50
54
|
"ua-parser-modern": "0.1.1"
|
|
51
55
|
},
|
|
52
56
|
"scripts": {
|
|
@@ -360,6 +360,19 @@ export default function setup(ctx: DevToolsClientScriptContext) {
|
|
|
360
360
|
}
|
|
361
361
|
```
|
|
362
362
|
|
|
363
|
+
## Client Context
|
|
364
|
+
|
|
365
|
+
The global client context (`DevToolsClientContext`) provides access to the RPC client and is set automatically when DevTools initializes (embedded or standalone). Use `getDevToolsClientContext()` to access it from anywhere on the client side:
|
|
366
|
+
|
|
367
|
+
```ts
|
|
368
|
+
import { getDevToolsClientContext } from '@vitejs/devtools-kit/client'
|
|
369
|
+
|
|
370
|
+
const ctx = getDevToolsClientContext()
|
|
371
|
+
if (ctx) {
|
|
372
|
+
const modules = await ctx.rpc.call('my-plugin:get-modules')
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
363
376
|
### Broadcasting to Clients
|
|
364
377
|
|
|
365
378
|
```ts
|
|
@@ -187,6 +187,15 @@ export function useRpc() {
|
|
|
187
187
|
}
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
+
Alternatively, use `getDevToolsClientContext()` to access the global client context synchronously (returns `undefined` if not yet initialized):
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { getDevToolsClientContext } from '@vitejs/devtools-kit/client'
|
|
194
|
+
|
|
195
|
+
const ctx = getDevToolsClientContext()
|
|
196
|
+
// ctx?.rpc is the DevToolsRpcClient
|
|
197
|
+
```
|
|
198
|
+
|
|
190
199
|
## Client App Component (src/client/App.vue)
|
|
191
200
|
|
|
192
201
|
```vue
|
|
@@ -119,6 +119,21 @@ ctx.rpc.broadcast({
|
|
|
119
119
|
})
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
+
## Global Client Context
|
|
123
|
+
|
|
124
|
+
Use `getDevToolsClientContext()` to access the client context (`DevToolsClientContext`) globally. Returns `undefined` if the context has not been initialized yet.
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { getDevToolsClientContext } from '@vitejs/devtools-kit/client'
|
|
128
|
+
|
|
129
|
+
const ctx = getDevToolsClientContext()
|
|
130
|
+
if (ctx) {
|
|
131
|
+
await ctx.rpc.call('my-plugin:get-modules')
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
This is set automatically when DevTools initializes in embedded or standalone mode. For iframe pages, `getDevToolsRpcClient()` is still the recommended way to get the RPC client directly.
|
|
136
|
+
|
|
122
137
|
## Client Function Registration
|
|
123
138
|
|
|
124
139
|
```ts
|
|
@@ -33,7 +33,7 @@ state.mutate((draft) => {
|
|
|
33
33
|
import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
|
|
34
34
|
|
|
35
35
|
const client = await getDevToolsRpcClient()
|
|
36
|
-
const state = await client.
|
|
36
|
+
const state = await client.sharedState.get('my-plugin:state')
|
|
37
37
|
|
|
38
38
|
// Read
|
|
39
39
|
console.log(state.value())
|
|
@@ -44,6 +44,17 @@ state.on('updated', (newState) => {
|
|
|
44
44
|
})
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
You can also access shared state through the global client context:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { getDevToolsClientContext } from '@vitejs/devtools-kit/client'
|
|
51
|
+
|
|
52
|
+
const ctx = getDevToolsClientContext()
|
|
53
|
+
if (ctx) {
|
|
54
|
+
const state = await ctx.rpc.sharedState.get('my-plugin:state')
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
47
58
|
## Type-Safe Shared State
|
|
48
59
|
|
|
49
60
|
```ts
|
|
File without changes
|