@histoire/plugin-vue-devtools 0.0.0-stage → 1.0.0-beta.2
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/LICENSE +21 -0
- package/README.md +18 -2
- package/dist/frame.d.ts +3 -0
- package/dist/frame.js +3 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +39 -0
- package/dist/sandbox.d.ts +3 -0
- package/dist/sandbox.js +51 -0
- package/dist/workbench/panel.d.ts +6 -0
- package/dist/workbench/panel.js +67 -0
- package/dist/workbench/relay.d.ts +3 -0
- package/dist/workbench/relay.js +38 -0
- package/dist/workbench.d.ts +3 -0
- package/dist/workbench.js +18 -0
- package/package.json +92 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Guillaume Chau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Vue DevTools plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@histoire/plugin-vue-devtools` adds the Devframe-based Vue DevTools to the right inspector in development. Select a story variant and open the **Vue DevTools** tab to inspect its Vue component tree and state. The floating Devframe toolbar is disabled. The inspector frames the upstream UI using `degradedVisualIntegration`. It requires Vue 3.5.26 or later, Vite 8.3 or later, and `@vitejs/devtools` 0.8.0. Vue DevTools is pinned to 9.0.0-rc.2.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { HstVue } from '@histoire/plugin-vue'
|
|
7
|
+
import { HstVueDevtools } from '@histoire/plugin-vue-devtools'
|
|
8
|
+
import { defineConfig } from 'histoire'
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
plugins: [HstVue(), HstVueDevtools()],
|
|
12
|
+
})
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The plugin respects an explicit `devtools: false` Vite configuration. It is inactive during builds, collection and browser test runtimes. Vue DevTools' own MCP endpoint is disabled; the separately authenticated `@histoire/devframe` adapter can expose Histoire live inspection.
|
|
16
|
+
|
|
17
|
+
The inspector connects to the selected same-origin story frame. Embedded story-only surfaces have no workbench inspector and do not show the toolbar. For a controlled local host, `clientAuthToken` can provide a pre-approved secret of 32–512 printable ASCII characters with no spaces for DevTools server access. The plugin embeds that secret in served documents and therefore rejects requests unless the actual source listener is bound to loopback; it also pins the DevTools host to loopback. Only supply a fresh secret in a trusted local development environment, and do not use this option with a public server. `enabled: false` disables the plugin.
|
|
18
|
+
|
|
19
|
+
See the [Vue 3 Devframe example](../../examples/vue3/devframe/README.md) for a runnable host and browser test. The example is local-only and is not a production authentication design.
|
package/dist/frame.d.ts
ADDED
package/dist/frame.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Plugin } from '@histoire/shared';
|
|
2
|
+
/** Options for the development-only Vue DevTools integration. */
|
|
3
|
+
export interface VueDevtoolsOptions {
|
|
4
|
+
/** Enable the integration; defaults to true. */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
/** Pre-approved local token. Only use with a loopback-only development server. */
|
|
7
|
+
clientAuthToken?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Install Devframe-based Vue DevTools for interactive Histoire story frames. */
|
|
10
|
+
export declare function HstVueDevtools(options?: VueDevtoolsOptions): Plugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { sandboxDevtools } from './sandbox.js';
|
|
3
|
+
/** Install Devframe-based Vue DevTools for interactive Histoire story frames. */
|
|
4
|
+
export function HstVueDevtools(options = {}) {
|
|
5
|
+
const token = options.clientAuthToken;
|
|
6
|
+
if (token !== undefined && (token.length < 32 || token.length > 512 || [...token].some(character => character.charCodeAt(0) < 33 || character.charCodeAt(0) > 126)))
|
|
7
|
+
throw new Error('Invalid Vue DevTools token');
|
|
8
|
+
return {
|
|
9
|
+
name: '@histoire/plugin-vue-devtools',
|
|
10
|
+
metadata: { displayName: 'Vue DevTools', description: 'Vue DevTools for story frames', icon: 'logo-vue', docsUrl: 'https://histoire.dev/guide/devframe.html', repoUrl: 'https://github.com/histoire-dev/histoire/tree/main/packages/histoire-plugin-vue-devtools' },
|
|
11
|
+
workbench: options.enabled === false
|
|
12
|
+
? undefined
|
|
13
|
+
: {
|
|
14
|
+
id: 'vue-devtools',
|
|
15
|
+
apiVersion: 1,
|
|
16
|
+
client: fileURLToPath(new URL('./workbench.js', import.meta.url)),
|
|
17
|
+
frame: fileURLToPath(new URL('./frame.js', import.meta.url)),
|
|
18
|
+
devOnly: true,
|
|
19
|
+
},
|
|
20
|
+
async viteConfig(config, context) {
|
|
21
|
+
if (options.enabled === false || context.mode !== 'dev' || context.isServer || context.browserRuntime || context.collecting || config.devtools === false)
|
|
22
|
+
return;
|
|
23
|
+
const vueDevTools = (await import('vite-plugin-vue-devtools')).default;
|
|
24
|
+
const current = typeof config.devtools === 'object' ? config.devtools : {};
|
|
25
|
+
return {
|
|
26
|
+
define: { __HISTOIRE_VUE_DEVTOOLS_ACTIVE__: true },
|
|
27
|
+
devtools: {
|
|
28
|
+
...current,
|
|
29
|
+
apply: 'serve',
|
|
30
|
+
host: '127.0.0.1',
|
|
31
|
+
mcp: false,
|
|
32
|
+
...(token ? { clientAuthTokens: [...(current.clientAuthTokens ?? []), token] } : {}),
|
|
33
|
+
},
|
|
34
|
+
...(token ? { server: { host: '127.0.0.1', hmr: { host: '127.0.0.1' } } } : {}),
|
|
35
|
+
plugins: [vueDevTools(), sandboxDevtools(token)],
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
package/dist/sandbox.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Keep the DevTools client in story documents and suppress the floating dock. */
|
|
2
|
+
export function sandboxDevtools(token) {
|
|
3
|
+
return {
|
|
4
|
+
name: 'histoire:vue-devtools-sandbox',
|
|
5
|
+
apply: 'serve',
|
|
6
|
+
configResolved(config) {
|
|
7
|
+
if (token && !['127.0.0.1', 'localhost', '::1'].includes(String(config.server.host)))
|
|
8
|
+
throw new Error('Vue DevTools automatic authentication requires a loopback-only development server');
|
|
9
|
+
},
|
|
10
|
+
configureServer(server) {
|
|
11
|
+
if (!token)
|
|
12
|
+
return;
|
|
13
|
+
// Managed and middleware hosts can override Vite's configured host.
|
|
14
|
+
// Check the real listener before serving any pre-approved credential.
|
|
15
|
+
const hmr = server.config.server.hmr;
|
|
16
|
+
const listener = (typeof hmr === 'object' && hmr?.server) || server.httpServer;
|
|
17
|
+
server.middlewares.use((_request, response, next) => {
|
|
18
|
+
const address = listener?.address();
|
|
19
|
+
if (!address || typeof address === 'string' || !['127.0.0.1', '::1'].includes(address.address)) {
|
|
20
|
+
response.statusCode = 403;
|
|
21
|
+
response.end('Vue DevTools requires a loopback-only listener');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
next();
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
transform(code, id) {
|
|
28
|
+
if (!id.includes('html-proxy'))
|
|
29
|
+
return;
|
|
30
|
+
// The DevTools panel discovers ancestor clients, so shell clients compete
|
|
31
|
+
// with the actual story's in-page channel.
|
|
32
|
+
if (!id.includes('__sandbox') && code.includes('virtual:vue-devtools-client'))
|
|
33
|
+
return 'export {}';
|
|
34
|
+
// The stock loader runs before Histoire clears the sandbox body.
|
|
35
|
+
if (code.includes('const s = document.createElement(\'script\'); s.type = \'module\'; s.src =') && code.includes('__devtools/embedded.js'))
|
|
36
|
+
return 'export {}';
|
|
37
|
+
},
|
|
38
|
+
transformIndexHtml: {
|
|
39
|
+
order: 'pre',
|
|
40
|
+
handler() {
|
|
41
|
+
const tags = [];
|
|
42
|
+
if (token) {
|
|
43
|
+
// A caller-supplied token must not terminate the inline script element.
|
|
44
|
+
const safeToken = JSON.stringify(token).replaceAll('<', '\\u003c');
|
|
45
|
+
tags.push({ tag: 'script', injectTo: 'head-prepend', children: `globalThis.__DEVFRAME_CONNECTION_AUTH_TOKEN__ = ${safeToken}` });
|
|
46
|
+
}
|
|
47
|
+
return tags;
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FrameScopedContext, ViewHost, WorkbenchPluginApi } from '@histoire/plugin-kit';
|
|
2
|
+
/** Mount upstream Vue DevTools and retire its connection whenever frame ownership changes. */
|
|
3
|
+
export declare function mountVueDevtools(api: WorkbenchPluginApi, container: HTMLElement, initial: FrameScopedContext, host: ViewHost): {
|
|
4
|
+
update(next: FrameScopedContext): void;
|
|
5
|
+
dispose(): void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { connectVueDevtools } from './relay.js';
|
|
2
|
+
/** Mount upstream Vue DevTools and retire its connection whenever frame ownership changes. */
|
|
3
|
+
export function mountVueDevtools(api, container, initial, host) {
|
|
4
|
+
let context = initial;
|
|
5
|
+
let actor;
|
|
6
|
+
let target;
|
|
7
|
+
let release;
|
|
8
|
+
/** Dispose the panel and its connection before changing owners. */
|
|
9
|
+
function clear() {
|
|
10
|
+
release?.();
|
|
11
|
+
release = undefined;
|
|
12
|
+
actor = undefined;
|
|
13
|
+
target = undefined;
|
|
14
|
+
host.renderState(container, null);
|
|
15
|
+
container.replaceChildren();
|
|
16
|
+
}
|
|
17
|
+
/** Reconcile the panel with the selected, attached actor. */
|
|
18
|
+
function update() {
|
|
19
|
+
const selected = context.selection.target;
|
|
20
|
+
const frame = context.frame;
|
|
21
|
+
const next = selected?.storyId === frame.target.storyId && selected.variantId === frame.target.variantId
|
|
22
|
+
? api.frames.list().find(item => item.key === frame.key && item.target.storyId === frame.target.storyId && item.target.variantId === frame.target.variantId)
|
|
23
|
+
: undefined;
|
|
24
|
+
const window = next && api.frames.window(next);
|
|
25
|
+
if (next && window && actor?.actorId === next.actorId && target?.documentId === window.documentId && target.window === window.window)
|
|
26
|
+
return;
|
|
27
|
+
clear();
|
|
28
|
+
if (next && !window) {
|
|
29
|
+
host.renderState(container, { kind: 'empty', icon: 'code', title: 'Vue DevTools unavailable', detail: 'This host cannot connect to the story frame.' });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!next || !window) {
|
|
33
|
+
host.renderState(container, { kind: 'loading', title: 'Connecting Vue DevTools' });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
actor = next;
|
|
37
|
+
target = window;
|
|
38
|
+
const iframe = document.createElement('iframe');
|
|
39
|
+
iframe.title = 'Vue DevTools';
|
|
40
|
+
iframe.style.width = '100%';
|
|
41
|
+
iframe.style.height = '100%';
|
|
42
|
+
iframe.style.display = 'block';
|
|
43
|
+
iframe.style.border = '0';
|
|
44
|
+
iframe.src = new URL(`${import.meta.env.BASE_URL}__devtools__/`, document.baseURI).href;
|
|
45
|
+
release = connectVueDevtools(iframe, window, () => {
|
|
46
|
+
const current = api.frames.window(next);
|
|
47
|
+
const selected = context.selection.target;
|
|
48
|
+
return !host.signal.aborted && current?.documentId === window.documentId && current.window === window.window && selected?.storyId === frame.target.storyId && selected.variantId === frame.target.variantId;
|
|
49
|
+
});
|
|
50
|
+
host.renderState(container, null);
|
|
51
|
+
container.append(iframe);
|
|
52
|
+
}
|
|
53
|
+
const stopFrames = api.frames.subscribe(update);
|
|
54
|
+
const stopContext = api.context.subscribe(update);
|
|
55
|
+
update();
|
|
56
|
+
return {
|
|
57
|
+
update(next) {
|
|
58
|
+
context = next;
|
|
59
|
+
update();
|
|
60
|
+
},
|
|
61
|
+
dispose() {
|
|
62
|
+
stopFrames();
|
|
63
|
+
stopContext();
|
|
64
|
+
clear();
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PluginFrameWindow } from '@histoire/plugin-kit';
|
|
2
|
+
/** Relay only the upstream Vue DevTools handshake between the panel and its selected actor. */
|
|
3
|
+
export declare function connectVueDevtools(panel: HTMLIFrameElement, frame: PluginFrameWindow, active: () => boolean): () => void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Relay only the upstream Vue DevTools handshake between the panel and its selected actor. */
|
|
2
|
+
export function connectVueDevtools(panel, frame, active) {
|
|
3
|
+
const owner = panel.ownerDocument.defaultView;
|
|
4
|
+
let pending;
|
|
5
|
+
/** Forward same-origin handshakes only from the exact panel and selected frame windows. */
|
|
6
|
+
function receive(event) {
|
|
7
|
+
const data = event.data;
|
|
8
|
+
if (!data || data.channel !== 'devframe:in-page-channel' || data.v !== 2 || data.name !== 'vue-devtools' || typeof data.panelId !== 'string')
|
|
9
|
+
return;
|
|
10
|
+
if (event.source !== panel.contentWindow && event.source !== frame.window)
|
|
11
|
+
return;
|
|
12
|
+
if (event.origin !== frame.origin || !active()) {
|
|
13
|
+
if (data.kind === 'grant' && event.source === frame.window && data.panelId === pending) {
|
|
14
|
+
for (const port of event.ports)
|
|
15
|
+
port.close();
|
|
16
|
+
}
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (data.kind === 'hello' && event.source === panel.contentWindow) {
|
|
20
|
+
pending = data.panelId;
|
|
21
|
+
frame.window.postMessage(data, frame.origin);
|
|
22
|
+
}
|
|
23
|
+
else if (data.kind === 'grant' && event.source === frame.window && pending === data.panelId) {
|
|
24
|
+
pending = undefined;
|
|
25
|
+
const port = event.ports[0];
|
|
26
|
+
if (port && panel.contentWindow)
|
|
27
|
+
panel.contentWindow.postMessage(data, frame.origin, [port]);
|
|
28
|
+
else
|
|
29
|
+
port?.close();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
owner.addEventListener('message', receive);
|
|
33
|
+
return () => {
|
|
34
|
+
owner.removeEventListener('message', receive);
|
|
35
|
+
pending = undefined;
|
|
36
|
+
panel.remove();
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineWorkbenchPlugin } from '@histoire/plugin-kit';
|
|
2
|
+
import { mountVueDevtools } from './workbench/panel.js';
|
|
3
|
+
/** Show the upstream Vue DevTools client for the selected story frame. */
|
|
4
|
+
export default defineWorkbenchPlugin({
|
|
5
|
+
id: 'vue-devtools',
|
|
6
|
+
apiVersion: 1,
|
|
7
|
+
setup(api) {
|
|
8
|
+
if (typeof __HISTOIRE_VUE_DEVTOOLS_ACTIVE__ === 'undefined' || !__HISTOIRE_VUE_DEVTOOLS_ACTIVE__)
|
|
9
|
+
return;
|
|
10
|
+
api.inspector.addTab({
|
|
11
|
+
id: 'vue',
|
|
12
|
+
label: 'Vue DevTools',
|
|
13
|
+
icon: 'code',
|
|
14
|
+
degradedVisualIntegration: true,
|
|
15
|
+
mount: (container, context, host) => mountVueDevtools(api, container, context, host),
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,95 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@histoire/plugin-vue-devtools",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-beta.2",
|
|
5
|
+
"description": "Vue DevTools for Histoire story frames",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/Akryum/histoire.git",
|
|
10
|
+
"directory": "packages/histoire-plugin-vue-devtools"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"histoire-plugin"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.12.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@vitejs/devtools": "0.8.0",
|
|
32
|
+
"vite": "^8.3.0",
|
|
33
|
+
"vue": "^3.5.26",
|
|
34
|
+
"histoire": "^1.0.0-beta.2"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"vite-plugin-vue-devtools": "9.0.0-rc.2",
|
|
38
|
+
"@histoire/plugin-kit": "^1.0.0-beta.2",
|
|
39
|
+
"@histoire/shared": "^1.0.0-beta.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^22.10.1",
|
|
43
|
+
"@vitejs/devtools": "0.8.0",
|
|
44
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
45
|
+
"vite": "^8.3.5",
|
|
46
|
+
"vue": "^3.5.26",
|
|
47
|
+
"histoire": "1.0.0-beta.2"
|
|
48
|
+
},
|
|
49
|
+
"histoire": {
|
|
50
|
+
"marketplace": {
|
|
51
|
+
"displayName": "Vue DevTools",
|
|
52
|
+
"summary": "Inspect Vue component trees and state in the development inspector.",
|
|
53
|
+
"category": "inspection",
|
|
54
|
+
"frameworks": [
|
|
55
|
+
"vue"
|
|
56
|
+
],
|
|
57
|
+
"monogram": "Vd",
|
|
58
|
+
"tint": "green",
|
|
59
|
+
"adds": [
|
|
60
|
+
{
|
|
61
|
+
"kind": "inspector-tab",
|
|
62
|
+
"contribution": "vue",
|
|
63
|
+
"text": "Vue DevTools"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"access": [
|
|
67
|
+
"story-frames",
|
|
68
|
+
"story-dom",
|
|
69
|
+
"network"
|
|
70
|
+
],
|
|
71
|
+
"config": {
|
|
72
|
+
"import": "HstVueDevtools",
|
|
73
|
+
"options": [
|
|
74
|
+
{
|
|
75
|
+
"key": "enabled",
|
|
76
|
+
"label": "Enable Vue DevTools",
|
|
77
|
+
"type": "boolean",
|
|
78
|
+
"default": true
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"requires": {
|
|
83
|
+
"histoire": "^1.0.0-beta.1",
|
|
84
|
+
"@vitejs/devtools": "0.8.0",
|
|
85
|
+
"vite": "^8.3.0",
|
|
86
|
+
"vue": "^3.5.26"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"scripts": {
|
|
91
|
+
"build": "rimraf dist && tsc",
|
|
92
|
+
"watch": "tsc --watch",
|
|
93
|
+
"test": "node --test test/*.test.mjs"
|
|
94
|
+
}
|
|
6
95
|
}
|