@vscode/component-explorer 0.2.1-6 → 0.2.1-60
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/README.md +39 -27
- package/dist/components/ExplorerModel.d.ts +5 -1
- package/dist/components/ExplorerModel.d.ts.map +1 -1
- package/dist/components/FixturePreviewItem.d.ts +2 -0
- package/dist/components/FixturePreviewItem.d.ts.map +1 -1
- package/dist/components/PreviewArea.d.ts.map +1 -1
- package/dist/components/RightSidebar.d.ts +8 -2
- package/dist/components/RightSidebar.d.ts.map +1 -1
- package/dist/core/ComponentRenderer.d.ts +8 -10
- package/dist/core/ComponentRenderer.d.ts.map +1 -1
- package/dist/core/ErrorInfo.d.ts +21 -1
- package/dist/core/ErrorInfo.d.ts.map +1 -1
- package/dist/core/FixtureInputStore.d.ts +32 -0
- package/dist/core/FixtureInputStore.d.ts.map +1 -0
- package/dist/core/FixtureNode.d.ts.map +1 -1
- package/dist/core/fixtureApi.d.ts +149 -34
- package/dist/core/fixtureApi.d.ts.map +1 -1
- package/dist/core/fixtureApiConsumer.d.ts +18 -2
- package/dist/core/fixtureApiConsumer.d.ts.map +1 -1
- package/dist/core/index.d.ts +6 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/inputAggregation.d.ts +31 -0
- package/dist/core/inputAggregation.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/explorerQueryParams.d.ts +2 -2
- package/dist/lib/explorerQueryParams.d.ts.map +1 -1
- package/dist/lib/fixtureSizeCache.d.ts +2 -0
- package/dist/lib/fixtureSizeCache.d.ts.map +1 -1
- package/dist/modes/EmbeddedMode.d.ts.map +1 -1
- package/dist/modes/HeadlessMode.d.ts +12 -3
- package/dist/modes/HeadlessMode.d.ts.map +1 -1
- package/dist/{runtimeVersion-BpYdhxdg.js → runtimeVersion-CainDMbI.js} +47 -39
- package/dist/runtimeVersion-CainDMbI.js.map +1 -0
- package/dist/viewer.js +1819 -1390
- package/dist/viewer.js.map +1 -1
- package/package.json +15 -14
- package/dist/core/PropertySchema.d.ts +0 -40
- package/dist/core/PropertySchema.d.ts.map +0 -1
- package/dist/runtimeVersion-BpYdhxdg.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vscode/component-explorer
|
|
2
2
|
|
|
3
|
-
Core library for the [Component Explorer](../../README.md). Contains the fixture API,
|
|
3
|
+
Core library for the [Component Explorer](../../README.md). Contains the fixture API, input schemas, fixture registry, and the Explorer React UI.
|
|
4
4
|
|
|
5
5
|
## Fixture API
|
|
6
6
|
|
|
@@ -10,46 +10,54 @@ Defines a single component fixture.
|
|
|
10
10
|
|
|
11
11
|
```tsx
|
|
12
12
|
import { defineFixture } from '@vscode/component-explorer';
|
|
13
|
+
import { z } from 'zod';
|
|
13
14
|
|
|
14
15
|
export default defineFixture({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
render: (container,
|
|
16
|
+
inputSchema: z.object({
|
|
17
|
+
label: z.string().default('Click me'),
|
|
18
|
+
disabled: z.boolean().default(false),
|
|
19
|
+
}),
|
|
20
|
+
render: (container, { input }) => {
|
|
20
21
|
const root = createRoot(container);
|
|
21
|
-
root.render(<Button label={
|
|
22
|
+
root.render(<Button label={input.label} disabled={input.disabled} />);
|
|
22
23
|
return { dispose: () => root.unmount() };
|
|
23
24
|
},
|
|
24
25
|
});
|
|
25
26
|
```
|
|
26
27
|
|
|
28
|
+
The `inputSchema` is a [zod](https://zod.dev) schema. It is converted to JSON Schema at define
|
|
29
|
+
time, and `input` (typed as `z.infer<typeof schema>`) is populated with the schema's defaults
|
|
30
|
+
plus any overrides set in the explorer's properties panel.
|
|
31
|
+
|
|
27
32
|
Options:
|
|
28
33
|
|
|
29
34
|
| Option | Type | Default | Description |
|
|
30
35
|
|---|---|---|---|
|
|
31
|
-
| `render` | `(container,
|
|
32
|
-
| `
|
|
36
|
+
| `render` | `(container, context) => Disposable` | **(required)** | Renders the component. Must return `{ dispose() }` for cleanup. |
|
|
37
|
+
| `inputSchema` | `z.ZodType` | — | Zod schema describing `input`. Drives the properties panel controls. |
|
|
33
38
|
| `isolation` | `'shadow-dom' \| 'iframe'` | `'shadow-dom'` | Component isolation strategy. |
|
|
34
39
|
| `displayMode` | `DisplayMode` | `{ type: 'component' }` | `'component'` for natural size, or `'page'` with viewport presets. |
|
|
35
40
|
| `styles` | `StyleDefinition[]` | — | Stylesheets injected into the shadow root (shadow-dom isolation only). |
|
|
36
41
|
| `background` | `'light' \| 'dark'` | `'light'` | Preview canvas background pattern. |
|
|
37
42
|
| `description` | `string` | — | Documentation description. |
|
|
38
43
|
|
|
39
|
-
### `defineFixtureGroup(entries)`
|
|
44
|
+
### `defineFixtureGroup(entries)` / `defineFixtureGroup(options, entries)`
|
|
40
45
|
|
|
41
|
-
Groups multiple fixtures (supports nesting)
|
|
46
|
+
Groups multiple fixtures (supports nesting). An optional first argument can declare an
|
|
47
|
+
`inputSchema` shared by — and merged into — every descendant fixture, so common input (e.g. a
|
|
48
|
+
`theme` switch) is declared once for the whole group:
|
|
42
49
|
|
|
43
50
|
```tsx
|
|
44
51
|
import { defineFixture, defineFixtureGroup } from '@vscode/component-explorer';
|
|
52
|
+
import { z } from 'zod';
|
|
45
53
|
|
|
46
|
-
export default defineFixtureGroup(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
54
|
+
export default defineFixtureGroup(
|
|
55
|
+
{ inputSchema: z.object({ theme: z.enum(['light', 'dark']).default('dark') }) },
|
|
56
|
+
{
|
|
57
|
+
Primary: defineFixture({ render: (c) => { /* ... */ } }),
|
|
58
|
+
Secondary: defineFixture({ render: (c) => { /* ... */ } }),
|
|
59
|
+
},
|
|
60
|
+
);
|
|
53
61
|
```
|
|
54
62
|
|
|
55
63
|
### `defineFixtureVariants(variants)`
|
|
@@ -66,16 +74,21 @@ defineFixtureVariants({
|
|
|
66
74
|
});
|
|
67
75
|
```
|
|
68
76
|
|
|
69
|
-
##
|
|
77
|
+
## Input Schemas
|
|
78
|
+
|
|
79
|
+
Fixture `input` is described with a [zod](https://zod.dev) schema (`inputSchema`). The explorer
|
|
80
|
+
converts it to JSON Schema and renders a control per property in the properties panel:
|
|
70
81
|
|
|
71
|
-
|
|
|
72
|
-
|
|
73
|
-
| `boolean` |
|
|
74
|
-
| `string` |
|
|
75
|
-
| `number`
|
|
76
|
-
| `enum` |
|
|
82
|
+
| Zod type | Control |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `z.boolean()` | Toggle checkbox |
|
|
85
|
+
| `z.string()` | Text input |
|
|
86
|
+
| `z.number()` / `z.int()` | Number input |
|
|
87
|
+
| `z.enum([...])` | Dropdown select |
|
|
77
88
|
|
|
78
|
-
|
|
89
|
+
Use `.default(...)` to set the initial value and `.describe(...)` to document a property. When
|
|
90
|
+
multiple rendered fixtures share a property of the same name and schema, the panel exposes a
|
|
91
|
+
single control that edits them all at once.
|
|
79
92
|
|
|
80
93
|
## Explorer UI Components
|
|
81
94
|
|
|
@@ -96,7 +109,6 @@ The package exports the full Explorer UI as React components:
|
|
|
96
109
|
|---|---|
|
|
97
110
|
| `FixtureRegistry` | Observable registry of discovered fixtures. |
|
|
98
111
|
| `createFixtureTree` | Builds a `FixtureNode` tree from registered fixtures. |
|
|
99
|
-
| `getDefaultPropertyValues` | Extracts default values from a `PropertySchema[]`. |
|
|
100
112
|
| `VIEWPORT_SIZES` | Built-in viewport preset dimensions (`mobile`, `tablet`, `desktop`). |
|
|
101
113
|
|
|
102
114
|
## Styles
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IReader } from '@vscode/observables';
|
|
2
|
-
import { FixtureRegistry, ComponentDefinition } from '../core/index.js';
|
|
2
|
+
import { FixtureRegistry, ComponentDefinition, FixtureInputStore } from '../core/index.js';
|
|
3
3
|
import { ExplorerTreeNode } from './types.js';
|
|
4
4
|
import { DaemonModel } from '../daemon/index.js';
|
|
5
5
|
import { ReportModel } from '../report/ReportModel.js';
|
|
@@ -72,6 +72,10 @@ export declare class ExplorerModel extends ExplorerModel_base {
|
|
|
72
72
|
readonly selectedNode: import('@vscode/observables').IObservableWithChange<ExplorerTreeNode | undefined, void>;
|
|
73
73
|
/** List of preview rows to render based on current selection and view mode */
|
|
74
74
|
readonly selectedFixtures: import('@vscode/observables').IObservableWithChange<readonly PreviewRow[], void>;
|
|
75
|
+
/** Shared store of per-fixture `input` overrides, edited via the properties panel. */
|
|
76
|
+
readonly inputStore: FixtureInputStore;
|
|
77
|
+
/** Flattened list of the live fixtures currently shown in the preview area. */
|
|
78
|
+
readonly renderedFixtures: import('@vscode/observables').IObservableWithChange<readonly FixtureItem[], void>;
|
|
75
79
|
setViewMode: (mode: ViewMode) => void;
|
|
76
80
|
navigateToSession: (sessionName: string) => void;
|
|
77
81
|
toggleLeftSidebar: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExplorerModel.d.ts","sourceRoot":"","sources":["../../src/components/ExplorerModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ExplorerModel.d.ts","sourceRoot":"","sources":["../../src/components/ExplorerModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,KAAK,gBAAgB,EAAkB,MAAM,YAAY,CAAC;AAInE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD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AQ,MAAM,KAAG,IAAI,CAEjC;IAEF,kBAAkB,GAAI,QAAQ,MAAM,KAAG,IAAI,CASzC;IAEF,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAKxD,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,mBAAmB;IA8C3B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA8CxB,OAAO,CAAC,kBAAkB;CA6B3B"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { FixtureInputStore } from '../core/index.js';
|
|
1
2
|
import { FixtureItem } from './ExplorerModel.js';
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
export declare const FixturePreviewItem: React.ComponentType<{
|
|
4
5
|
fixture: FixtureItem;
|
|
5
6
|
compact: boolean | undefined;
|
|
6
7
|
onSelect: ((nodeId: string) => void) | undefined;
|
|
8
|
+
inputStore: FixtureInputStore | undefined;
|
|
7
9
|
} & {} & {} & {}>;
|
|
8
10
|
//# sourceMappingURL=FixturePreviewItem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FixturePreviewItem.d.ts","sourceRoot":"","sources":["../../src/components/FixturePreviewItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"FixturePreviewItem.d.ts","sourceRoot":"","sources":["../../src/components/FixturePreviewItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA6HtD,eAAO,MAAM,kBAAkB;;;wBA1GE,MAAM,KAAK,IAAI;;iBA0J/C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreviewArea.d.ts","sourceRoot":"","sources":["../../src/components/PreviewArea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"PreviewArea.d.ts","sourceRoot":"","sources":["../../src/components/PreviewArea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,oBAAoB,CAAC;AAsbpE,eAAO,MAAM,WAAW;;iBAmGvB,CAAC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExplorerModel } from './ExplorerModel.js';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Properties panel: aggregates the input schemas of every fixture currently rendered in the
|
|
5
|
+
* preview area and presents one control per shared property. Editing a control updates the
|
|
6
|
+
* `input` of all fixtures that declare that property (same name + schema), so common values
|
|
7
|
+
* like a theme can be switched across the whole view at once.
|
|
8
|
+
*/
|
|
3
9
|
export declare const RightSidebar: React.ComponentType<import('@vscode/observables-react').PropsIn<{
|
|
4
|
-
|
|
10
|
+
model: import('@vscode/observables-react').IPropertyTransformerFactory<ExplorerModel, ExplorerModel>;
|
|
5
11
|
}>>;
|
|
6
12
|
//# sourceMappingURL=RightSidebar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RightSidebar.d.ts","sourceRoot":"","sources":["../../src/components/RightSidebar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"RightSidebar.d.ts","sourceRoot":"","sources":["../../src/components/RightSidebar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAiJxD;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;GAqCxB,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ComponentDefinition } from './fixtureApiConsumer.js';
|
|
2
|
-
import { RenderResult } from './fixtureApi.js';
|
|
2
|
+
import { RenderHost, RenderResult } from './fixtureApi.js';
|
|
3
3
|
import { ExceptionError } from './ErrorInfo.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
/** Maximum time a fixture render may take before it is reported as failed. */
|
|
5
|
+
export declare const RENDER_TIMEOUT_MS = 3000;
|
|
7
6
|
export declare class ComponentRendering {
|
|
8
7
|
readonly component: ComponentDefinition;
|
|
8
|
+
private readonly _renderHost;
|
|
9
|
+
private readonly _input?;
|
|
9
10
|
readonly renderTarget: HTMLElement;
|
|
10
11
|
readonly iframe: HTMLIFrameElement | null;
|
|
11
12
|
private readonly _abortController;
|
|
@@ -13,13 +14,10 @@ export declare class ComponentRendering {
|
|
|
13
14
|
private _injectedElements;
|
|
14
15
|
private _adoptedSheets;
|
|
15
16
|
private _styleTarget;
|
|
17
|
+
private readonly _disposables;
|
|
16
18
|
private readonly _rendered;
|
|
17
|
-
|
|
18
|
-
private _errorReported;
|
|
19
|
-
error: ExceptionError | undefined;
|
|
20
|
-
constructor(host: HTMLElement, component: ComponentDefinition, options?: ComponentRenderingOptions);
|
|
21
|
-
private _reportError;
|
|
19
|
+
constructor(host: HTMLElement, component: ComponentDefinition, _renderHost?: RenderHost, _input?: unknown | undefined);
|
|
22
20
|
waitForRendering(): Promise<RenderResult | undefined>;
|
|
23
|
-
dispose():
|
|
21
|
+
dispose(): Promise<readonly ExceptionError[]>;
|
|
24
22
|
}
|
|
25
23
|
//# sourceMappingURL=ComponentRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentRenderer.d.ts","sourceRoot":"","sources":["../../src/core/ComponentRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ComponentRenderer.d.ts","sourceRoot":"","sources":["../../src/core/ComponentRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAsB,MAAM,yBAAyB,CAAC;AAClF,OAAO,KAAK,EAAe,UAAU,EAAE,YAAY,EAAmB,MAAM,iBAAiB,CAAC;AAC9F,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,gBAAgB,CAAC;AAItE,8EAA8E;AAC9E,eAAO,MAAM,iBAAiB,OAAO,CAAC;AA8CtC,qBAAa,kBAAkB;IAa7B,QAAQ,CAAC,SAAS,EAAE,mBAAmB;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAdzB,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAQ;IACjD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAyB;IAC1D,OAAO,CAAC,eAAe,CAAuD;IAC9E,OAAO,CAAC,iBAAiB,CAAqB;IAC9C,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,YAAY,CAAmC;IACvD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoC;gBAG7D,IAAI,EAAE,WAAW,EACR,SAAS,EAAE,mBAAmB,EACtB,WAAW,GAAE,UAAqD,EAClE,MAAM,CAAC,EAAE,OAAO,YAAA;IA8H5B,gBAAgB,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAmB3D,OAAO,IAAI,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC;CA8C7C"}
|
package/dist/core/ErrorInfo.d.ts
CHANGED
|
@@ -6,15 +6,35 @@ export type RenderEventType = 'console.error' | 'console.warn' | 'console.log' |
|
|
|
6
6
|
export interface RenderEvent {
|
|
7
7
|
readonly type: RenderEventType;
|
|
8
8
|
readonly message: string;
|
|
9
|
+
readonly stack?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Errors and events captured while disposing a fixture (the implicit dispose
|
|
13
|
+
* that runs before a new render, or the explicit one triggered by
|
|
14
|
+
* `disposeAfter` / `disposeCurrentFixture()`).
|
|
15
|
+
*/
|
|
16
|
+
export interface DisposeReport {
|
|
17
|
+
readonly hasError: boolean;
|
|
18
|
+
/** Errors thrown by `dispose()` calls (RenderResult.dispose, addDisposable disposables). */
|
|
19
|
+
readonly errors: readonly ExceptionError[];
|
|
20
|
+
/** Console / window error events fired during the dispose call. */
|
|
21
|
+
readonly events: readonly RenderEvent[];
|
|
9
22
|
}
|
|
10
23
|
export interface RenderReport {
|
|
11
24
|
readonly hasError: boolean;
|
|
12
25
|
readonly error?: ExceptionError;
|
|
13
26
|
readonly events: RenderEvent[];
|
|
14
|
-
|
|
27
|
+
/** Output data the fixture provided via `RenderResult.output` (counterpart of `RenderContext.input`). */
|
|
28
|
+
readonly output?: unknown;
|
|
15
29
|
readonly renderTimeMs: {
|
|
16
30
|
readonly sync: number;
|
|
17
31
|
readonly total: number;
|
|
18
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Errors / events captured while disposing the previous fixture (the implicit
|
|
35
|
+
* dispose that runs at the start of `renderFixture`). Present only if the
|
|
36
|
+
* dispose actually surfaced something.
|
|
37
|
+
*/
|
|
38
|
+
readonly previousDispose?: DisposeReport;
|
|
19
39
|
}
|
|
20
40
|
//# sourceMappingURL=ErrorInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorInfo.d.ts","sourceRoot":"","sources":["../../src/core/ErrorInfo.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAA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EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzE;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC;CACzC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IObservable, IReader } from '@vscode/observables';
|
|
2
|
+
import { IJsonSchema } from './fixtureApi.js';
|
|
3
|
+
/** A fixture's input override object (only the keys the user explicitly changed). */
|
|
4
|
+
export type FixtureInputOverride = Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* Central store of `input` overrides for the explorer UI.
|
|
7
|
+
*
|
|
8
|
+
* Values are keyed by **property identity** (name + structural schema), not by fixture, so a
|
|
9
|
+
* value chosen on one fixture is automatically reused by every other fixture that declares the
|
|
10
|
+
* same input — navigating between fixtures keeps the shared value instead of resetting it.
|
|
11
|
+
* The whole map is persisted to `localStorage` so choices survive reloads. Schema defaults are
|
|
12
|
+
* applied at render time (see `applyInputDefaults`); only explicit overrides are stored here.
|
|
13
|
+
*/
|
|
14
|
+
export declare class FixtureInputStore {
|
|
15
|
+
/** Shared values keyed by `inputPropertyKey(name, schema)`. */
|
|
16
|
+
private readonly _values;
|
|
17
|
+
/** Cache of derived per-fixture override observables. */
|
|
18
|
+
private readonly _byFixture;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Returns a derived observable of `fixtureId`'s input overrides, mapped from the shared
|
|
22
|
+
* per-property store. Only properties the user explicitly set (across any fixture) appear.
|
|
23
|
+
*/
|
|
24
|
+
getInput(fixtureId: string, schema: IJsonSchema | undefined): IObservable<FixtureInputOverride>;
|
|
25
|
+
/** The currently effective value of a shared property: explicit override, else schema default. */
|
|
26
|
+
readValue(reader: IReader, name: string, schema: IJsonSchema): unknown;
|
|
27
|
+
/** Sets a shared input property (applies to every fixture that declares it) and persists. */
|
|
28
|
+
setValue(name: string, schema: IJsonSchema, value: unknown): void;
|
|
29
|
+
private _load;
|
|
30
|
+
private _persist;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=FixtureInputStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FixtureInputStore.d.ts","sourceRoot":"","sources":["../../src/core/FixtureInputStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsD,KAAK,WAAW,EAAE,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACzH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,qFAAqF;AACrF,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAI3D;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAC1B,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+C;IACvE,yDAAyD;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwD;;IAMnF;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC,oBAAoB,CAAC;IAuB/F,kGAAkG;IAClG,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO;IAStE,6FAA6F;IAC7F,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAOjE,OAAO,CAAC,KAAK;IAeb,OAAO,CAAC,QAAQ;CAOnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FixtureNode.d.ts","sourceRoot":"","sources":["../../src/core/FixtureNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"FixtureNode.d.ts","sourceRoot":"","sources":["../../src/core/FixtureNode.ts"],"names":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@@ -1,23 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
* Public Fixture API
|
|
3
|
-
*
|
|
4
|
-
* This module is the public API for defining fixtures.
|
|
5
|
-
* It's designed to be stable across versions - projects can use a different
|
|
6
|
-
* @vscode/component-explorer version than the explorer viewer uses.
|
|
7
|
-
*
|
|
8
|
-
* Use Symbol.for() instead of Symbol() so the same symbol is shared across
|
|
9
|
-
* different versions of this package.
|
|
10
|
-
*
|
|
11
|
-
* @module fixtureApi
|
|
12
|
-
*/
|
|
1
|
+
import { z } from 'zod';
|
|
13
2
|
/**
|
|
14
3
|
* Disposable resource that can be cleaned up.
|
|
4
|
+
* `dispose` may be sync or async; the framework awaits the returned promise (if any)
|
|
5
|
+
* and captures any thrown errors.
|
|
15
6
|
*/
|
|
16
7
|
export interface IDisposable {
|
|
17
|
-
dispose(): void
|
|
8
|
+
dispose(): void | Promise<void>;
|
|
18
9
|
}
|
|
19
|
-
/** @deprecated Use IDisposable instead */
|
|
20
|
-
export type Disposable = IDisposable;
|
|
21
10
|
/**
|
|
22
11
|
* Result of a render operation.
|
|
23
12
|
* Supports both sync and async rendering with cancellation.
|
|
@@ -32,14 +21,20 @@ export interface RenderResult {
|
|
|
32
21
|
readonly ready?: Promise<void>;
|
|
33
22
|
/**
|
|
34
23
|
* Cleanup function. Called when the fixture is unmounted.
|
|
24
|
+
* May be sync or async; the framework awaits the returned promise (if any).
|
|
25
|
+
* Errors thrown (sync or async) are captured and surfaced via the
|
|
26
|
+
* `previousDispose` field of the next render report (or `currentDispose`
|
|
27
|
+
* if `disposeAfter` was requested).
|
|
35
28
|
* Can be omitted if no cleanup is needed.
|
|
36
29
|
*/
|
|
37
|
-
dispose?(): void
|
|
30
|
+
dispose?(): void | Promise<void>;
|
|
38
31
|
/**
|
|
39
32
|
* Arbitrary data to include in the render report.
|
|
40
|
-
* Visible to the CLI and MCP tools.
|
|
33
|
+
* Visible to the CLI and MCP tools (surfaced as `output`).
|
|
34
|
+
*
|
|
35
|
+
* Symmetric counterpart of `RenderContext.input`: input flows in, output flows out.
|
|
41
36
|
*/
|
|
42
|
-
readonly
|
|
37
|
+
readonly output?: unknown;
|
|
43
38
|
}
|
|
44
39
|
/**
|
|
45
40
|
* What the render function can return.
|
|
@@ -50,11 +45,57 @@ export interface RenderResult {
|
|
|
50
45
|
export type RenderReturn = RenderResult | undefined | void | Promise<RenderResult | undefined | void>;
|
|
51
46
|
/**
|
|
52
47
|
* Context passed to the render function.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam TInput - Shape of `input`, inferred from the fixture's zod `inputSchema`
|
|
50
|
+
* (defaults to `unknown` when no schema is declared).
|
|
53
51
|
*/
|
|
54
|
-
export interface RenderContext {
|
|
52
|
+
export interface RenderContext<TInput = unknown> {
|
|
53
|
+
/**
|
|
54
|
+
* Unique identifier of the fixture being rendered.
|
|
55
|
+
* Stable across renders of the same fixture; useful for keying caches,
|
|
56
|
+
* logging, or distinguishing between sibling fixtures sharing a render function.
|
|
57
|
+
*/
|
|
58
|
+
readonly fixtureId: string;
|
|
55
59
|
/** AbortSignal for cancellation; check signal.aborted or listen to 'abort' event */
|
|
56
60
|
readonly signal: AbortSignal;
|
|
61
|
+
/** Register a disposable to be cleaned up when the fixture is unmounted. Returns the same disposable for chaining. */
|
|
62
|
+
addDisposable<T extends IDisposable>(disposable: T): T;
|
|
63
|
+
/**
|
|
64
|
+
* Describes where this fixture is being rendered. Use this to enable dev-only affordances
|
|
65
|
+
* (e.g. extra controls, logging) without affecting screenshots or embedded views.
|
|
66
|
+
*/
|
|
67
|
+
readonly host: RenderHost;
|
|
68
|
+
/**
|
|
69
|
+
* Data passed in by the caller (CLI/MCP screenshot tool, explorer UI). Use this to
|
|
70
|
+
* parameterize the fixture: e.g. switch theme, vary props, select a scenario.
|
|
71
|
+
*
|
|
72
|
+
* When the fixture declares a zod `inputSchema`, this is typed as `z.infer<typeof schema>`
|
|
73
|
+
* and populated with the schema's defaults for any keys the caller omitted. Without a
|
|
74
|
+
* schema it is `unknown` (and `undefined` when no input was provided).
|
|
75
|
+
*
|
|
76
|
+
* Symmetric with `RenderResult.output` (which flows back out to the caller).
|
|
77
|
+
*/
|
|
78
|
+
readonly input: TInput;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Describes the environment a fixture is rendered in.
|
|
82
|
+
*/
|
|
83
|
+
export type RenderHost =
|
|
84
|
+
/** Rendered in the Component Explorer UI (visible to a human). */
|
|
85
|
+
{
|
|
86
|
+
readonly kind: 'explorer-ui';
|
|
87
|
+
readonly interactive: true;
|
|
57
88
|
}
|
|
89
|
+
/** Headless render for CLI/MCP screenshots. */
|
|
90
|
+
| {
|
|
91
|
+
readonly kind: 'headless';
|
|
92
|
+
readonly interactive: false;
|
|
93
|
+
}
|
|
94
|
+
/** Rendered inside an isolation iframe (user-facing standalone view). */
|
|
95
|
+
| {
|
|
96
|
+
readonly kind: 'embedded';
|
|
97
|
+
readonly interactive: false;
|
|
98
|
+
};
|
|
58
99
|
/**
|
|
59
100
|
* Style definition for shadow DOM injection.
|
|
60
101
|
*/
|
|
@@ -94,6 +135,36 @@ export type ViewportPreset = ViewportPresetName | {
|
|
|
94
135
|
readonly height: number;
|
|
95
136
|
};
|
|
96
137
|
export type ViewportPresetName = 'mobile' | 'tablet' | 'desktop';
|
|
138
|
+
/**
|
|
139
|
+
* Minimal JSON Schema interface used to describe a fixture's expected `input` shape.
|
|
140
|
+
*
|
|
141
|
+
* This is the *derived* form: fixtures declare their input with a zod schema
|
|
142
|
+
* (`DefineFixtureOptions.inputSchema`) and the framework converts it to this JSON Schema
|
|
143
|
+
* at define time. Tools (CLI/MCP/explorer UI) read it for validation, autocompletion, or
|
|
144
|
+
* to generate input-editing controls.
|
|
145
|
+
*
|
|
146
|
+
* Intentionally a structural, recursive type covering the subset of JSON Schema we
|
|
147
|
+
* actually surface to tools — the index signature lets any additional standard JSON Schema
|
|
148
|
+
* keywords (`format`, `pattern`, `oneOf`, `$ref`, …) flow through without changing this interface.
|
|
149
|
+
*/
|
|
150
|
+
export interface IJsonSchema {
|
|
151
|
+
readonly type?: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
|
|
152
|
+
readonly properties?: {
|
|
153
|
+
readonly [key: string]: IJsonSchema;
|
|
154
|
+
};
|
|
155
|
+
readonly required?: readonly string[];
|
|
156
|
+
readonly items?: IJsonSchema;
|
|
157
|
+
readonly enum?: readonly unknown[];
|
|
158
|
+
readonly const?: unknown;
|
|
159
|
+
readonly default?: unknown;
|
|
160
|
+
readonly description?: string;
|
|
161
|
+
readonly title?: string;
|
|
162
|
+
readonly additionalProperties?: boolean | IJsonSchema;
|
|
163
|
+
readonly anyOf?: readonly IJsonSchema[];
|
|
164
|
+
readonly oneOf?: readonly IJsonSchema[];
|
|
165
|
+
readonly allOf?: readonly IJsonSchema[];
|
|
166
|
+
readonly [key: string]: unknown;
|
|
167
|
+
}
|
|
97
168
|
/** Brand symbol to identify single fixtures */
|
|
98
169
|
export declare const singleFixtureBrand: unique symbol;
|
|
99
170
|
/** Brand symbol to identify fixture groups */
|
|
@@ -102,8 +173,10 @@ export declare const fixtureGroupBrand: unique symbol;
|
|
|
102
173
|
export declare const fixtureVariantsBrand: unique symbol;
|
|
103
174
|
/**
|
|
104
175
|
* Options for defining a single component fixture.
|
|
176
|
+
*
|
|
177
|
+
* @typeParam TInput - Shape of the fixture's `input`, inferred from `inputSchema`.
|
|
105
178
|
*/
|
|
106
|
-
export interface DefineFixtureOptions {
|
|
179
|
+
export interface DefineFixtureOptions<TInput = unknown> {
|
|
107
180
|
/**
|
|
108
181
|
* Path in the explorer tree.
|
|
109
182
|
* - `undefined` (default): use fixture filename only
|
|
@@ -127,14 +200,35 @@ export interface DefineFixtureOptions {
|
|
|
127
200
|
labels?: readonly string[];
|
|
128
201
|
/** Human/AI-readable description(s) of expected visual appearance. Inherited from parent group/variants and accumulated into a string[]. */
|
|
129
202
|
expectedVisualDescriptions?: string | readonly string[];
|
|
203
|
+
/**
|
|
204
|
+
* Zod schema describing the expected shape of `RenderContext.input`.
|
|
205
|
+
*
|
|
206
|
+
* Declaring it gives two things:
|
|
207
|
+
* 1. **Type safety** — `render`'s `context.input` is typed as `z.infer<typeof schema>`.
|
|
208
|
+
* 2. **Tooling** — the framework converts the schema to JSON Schema at define time so the
|
|
209
|
+
* CLI/MCP/explorer UI can validate, autocomplete, or render input-editing controls.
|
|
210
|
+
*
|
|
211
|
+
* The schema must describe an object (`z.object({...})`) — `input` is always a JSON object
|
|
212
|
+
* (or `undefined`). Property-level `.default(...)` values are surfaced to tooling and used
|
|
213
|
+
* to populate omitted keys before `render` runs.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* inputSchema: z.object({
|
|
218
|
+
* theme: z.enum(['light', 'dark']).default('light'),
|
|
219
|
+
* count: z.number().int().default(1),
|
|
220
|
+
* })
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
inputSchema?: z.ZodType<TInput>;
|
|
130
224
|
/**
|
|
131
225
|
* Render the component into the container.
|
|
132
226
|
*
|
|
133
227
|
* @param container - The DOM element to render into
|
|
134
|
-
* @param context - Render context containing
|
|
228
|
+
* @param context - Render context containing input and abort signal
|
|
135
229
|
* @returns Optional RenderResult, or a Promise that resolves to one
|
|
136
230
|
*/
|
|
137
|
-
render: (container: HTMLElement, context: RenderContext) => RenderReturn;
|
|
231
|
+
render: (container: HTMLElement, context: RenderContext<TInput>) => RenderReturn;
|
|
138
232
|
}
|
|
139
233
|
/** @deprecated Use DefineFixtureOptions instead */
|
|
140
234
|
export type DefineComponentOptions = DefineFixtureOptions;
|
|
@@ -145,6 +239,8 @@ export interface SingleFixtureExport {
|
|
|
145
239
|
readonly [singleFixtureBrand]: true;
|
|
146
240
|
readonly _options: DefineFixtureOptions;
|
|
147
241
|
readonly _path?: string;
|
|
242
|
+
/** JSON Schema derived from `_options.inputSchema` at define time (cross-version safe). */
|
|
243
|
+
readonly _inputSchemaJson?: IJsonSchema;
|
|
148
244
|
}
|
|
149
245
|
/**
|
|
150
246
|
* Group entry: either a single fixture, a nested group, or variants.
|
|
@@ -161,6 +257,8 @@ export interface FixtureGroupExport {
|
|
|
161
257
|
readonly _path?: string;
|
|
162
258
|
readonly _labels?: readonly string[];
|
|
163
259
|
readonly _expectedVisualDescriptions?: string | readonly string[];
|
|
260
|
+
/** JSON Schema derived from the group's `inputSchema`; merged into every descendant fixture. */
|
|
261
|
+
readonly _inputSchemaJson?: IJsonSchema;
|
|
164
262
|
}
|
|
165
263
|
/**
|
|
166
264
|
* A fixture variants export created by defineFixtureVariants().
|
|
@@ -173,6 +271,8 @@ export interface FixtureVariantsExport {
|
|
|
173
271
|
readonly _path?: string;
|
|
174
272
|
readonly _labels?: readonly string[];
|
|
175
273
|
readonly _expectedVisualDescriptions?: string | readonly string[];
|
|
274
|
+
/** JSON Schema derived from the variants group's `inputSchema`; merged into every variant. */
|
|
275
|
+
readonly _inputSchemaJson?: IJsonSchema;
|
|
176
276
|
}
|
|
177
277
|
/**
|
|
178
278
|
* Fixture export type - a single fixture, a group, or variants.
|
|
@@ -199,6 +299,13 @@ export interface DefineFixtureGroupOptions {
|
|
|
199
299
|
labels?: readonly string[];
|
|
200
300
|
/** Human/AI-readable description(s) of expected visual appearance. Inherited by nested fixtures. */
|
|
201
301
|
expectedVisualDescriptions?: string | readonly string[];
|
|
302
|
+
/**
|
|
303
|
+
* Zod schema describing `input` shared by every fixture in this group. It is converted to
|
|
304
|
+
* JSON Schema at define time and merged into each descendant fixture's own schema (the
|
|
305
|
+
* descendant's properties win on conflict). Use it to declare common input — e.g. a `theme`
|
|
306
|
+
* switch — once for a whole group instead of repeating it on each fixture.
|
|
307
|
+
*/
|
|
308
|
+
inputSchema?: z.ZodType;
|
|
202
309
|
}
|
|
203
310
|
/**
|
|
204
311
|
* Input for defineFixtureVariants (only single fixtures, no nesting).
|
|
@@ -221,6 +328,12 @@ export interface DefineFixtureVariantsOptions {
|
|
|
221
328
|
labels?: readonly string[];
|
|
222
329
|
/** Human/AI-readable description(s) of expected visual appearance. Inherited by nested fixtures. */
|
|
223
330
|
expectedVisualDescriptions?: string | readonly string[];
|
|
331
|
+
/**
|
|
332
|
+
* Zod schema describing `input` shared by every variant in this group. Converted to JSON
|
|
333
|
+
* Schema at define time and merged into each variant's own schema (the variant's properties
|
|
334
|
+
* win on conflict).
|
|
335
|
+
*/
|
|
336
|
+
inputSchema?: z.ZodType;
|
|
224
337
|
}
|
|
225
338
|
/**
|
|
226
339
|
* Defines a single fixture.
|
|
@@ -229,31 +342,33 @@ export interface DefineFixtureVariantsOptions {
|
|
|
229
342
|
* ```ts
|
|
230
343
|
* // Simple - no cleanup needed
|
|
231
344
|
* export default defineFixture({
|
|
232
|
-
* render: (container
|
|
233
|
-
* container.innerHTML = `<button
|
|
345
|
+
* render: (container) => {
|
|
346
|
+
* container.innerHTML = `<button>Click me</button>`;
|
|
234
347
|
* },
|
|
235
348
|
* });
|
|
236
349
|
*
|
|
237
|
-
* //
|
|
350
|
+
* // Typed, parameterizable input via a zod schema
|
|
238
351
|
* export default defineFixture({
|
|
239
|
-
*
|
|
352
|
+
* inputSchema: z.object({ label: z.string().default('Click me') }),
|
|
353
|
+
* render: (container, { input }) => {
|
|
240
354
|
* const root = createRoot(container);
|
|
241
|
-
* root.render(<Button label={
|
|
355
|
+
* root.render(<Button label={input.label} />);
|
|
242
356
|
* return { dispose: () => root.unmount() };
|
|
243
357
|
* },
|
|
244
358
|
* });
|
|
245
359
|
*
|
|
246
360
|
* // Async render
|
|
247
361
|
* export default defineFixture({
|
|
248
|
-
*
|
|
249
|
-
*
|
|
362
|
+
* inputSchema: z.object({ url: z.string() }),
|
|
363
|
+
* render: async (container, { input, signal }) => {
|
|
364
|
+
* const data = await fetch(input.url, { signal });
|
|
250
365
|
* container.innerHTML = await data.text();
|
|
251
366
|
* return { dispose: () => { container.innerHTML = ''; } };
|
|
252
367
|
* },
|
|
253
368
|
* });
|
|
254
369
|
* ```
|
|
255
370
|
*/
|
|
256
|
-
export declare function defineFixture(options: DefineFixtureOptions): SingleFixtureExport;
|
|
371
|
+
export declare function defineFixture<TInput = unknown>(options: DefineFixtureOptions<TInput>): SingleFixtureExport;
|
|
257
372
|
/**
|
|
258
373
|
* Defines a group of fixtures with support for nesting.
|
|
259
374
|
*
|
|
@@ -298,9 +413,9 @@ export declare function defineFixtureVariants(options: DefineFixtureVariantsOpti
|
|
|
298
413
|
*
|
|
299
414
|
* @example
|
|
300
415
|
* ```ts
|
|
301
|
-
* render: (container, {
|
|
416
|
+
* render: (container, { input }) => syncRender(() => {
|
|
302
417
|
* const el = document.createElement('button');
|
|
303
|
-
* el.textContent =
|
|
418
|
+
* el.textContent = input.label;
|
|
304
419
|
* container.appendChild(el);
|
|
305
420
|
* return () => el.remove();
|
|
306
421
|
* })
|
|
@@ -317,8 +432,8 @@ export declare function syncRender(doRender: () => (() => void) | IDisposable |
|
|
|
317
432
|
*
|
|
318
433
|
* @example
|
|
319
434
|
* ```ts
|
|
320
|
-
* render: (container, {
|
|
321
|
-
* const data = await fetchData(
|
|
435
|
+
* render: (container, { input, signal }) => asyncRender(signal, async () => {
|
|
436
|
+
* const data = await fetchData(input.url, { signal });
|
|
322
437
|
* if (signal.aborted) return;
|
|
323
438
|
* container.innerHTML = data;
|
|
324
439
|
* return () => { container.innerHTML = ''; };
|