@vscode/component-explorer 0.1.1-2 → 0.1.1-20

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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/SECURITY.md +14 -0
  3. package/dist/component-explorer.css +1 -0
  4. package/dist/components/Explorer.d.ts +9 -4
  5. package/dist/components/Explorer.d.ts.map +1 -1
  6. package/dist/components/ExplorerModel.d.ts +45 -3
  7. package/dist/components/ExplorerModel.d.ts.map +1 -1
  8. package/dist/components/FixturePreviewItem.d.ts +1 -1
  9. package/dist/components/FixturePreviewItem.d.ts.map +1 -1
  10. package/dist/components/FixtureScreenshotView.d.ts +12 -0
  11. package/dist/components/FixtureScreenshotView.d.ts.map +1 -0
  12. package/dist/components/LeftSidebar.d.ts.map +1 -1
  13. package/dist/components/PreviewArea.d.ts.map +1 -1
  14. package/dist/components/ReportComparisonRow.d.ts +16 -0
  15. package/dist/components/ReportComparisonRow.d.ts.map +1 -0
  16. package/dist/components/ScreenshotComparisonRow.d.ts +12 -0
  17. package/dist/components/ScreenshotComparisonRow.d.ts.map +1 -0
  18. package/dist/components/SearchInput.d.ts +6 -0
  19. package/dist/components/SearchInput.d.ts.map +1 -0
  20. package/dist/components/TitleBar.d.ts.map +1 -1
  21. package/dist/components/TreeView.d.ts.map +1 -1
  22. package/dist/components/index.d.ts +6 -2
  23. package/dist/components/index.d.ts.map +1 -1
  24. package/dist/components/treeFilter.d.ts +3 -0
  25. package/dist/components/treeFilter.d.ts.map +1 -0
  26. package/dist/components/types.d.ts +1 -0
  27. package/dist/components/types.d.ts.map +1 -1
  28. package/dist/core/CliRuntime.d.ts +50 -0
  29. package/dist/core/CliRuntime.d.ts.map +1 -0
  30. package/dist/core/ComponentRenderer.d.ts +14 -0
  31. package/dist/core/ComponentRenderer.d.ts.map +1 -0
  32. package/dist/core/ErrorInfo.d.ts +29 -0
  33. package/dist/core/ErrorInfo.d.ts.map +1 -0
  34. package/dist/core/FixtureNode.d.ts +4 -1
  35. package/dist/core/FixtureNode.d.ts.map +1 -1
  36. package/dist/core/FixtureRegistry.d.ts +2 -1
  37. package/dist/core/FixtureRegistry.d.ts.map +1 -1
  38. package/dist/core/fixtureApi.d.ts +353 -0
  39. package/dist/core/fixtureApi.d.ts.map +1 -0
  40. package/dist/core/fixtureApiConsumer.d.ts +85 -0
  41. package/dist/core/fixtureApiConsumer.d.ts.map +1 -0
  42. package/dist/core/index.d.ts +7 -6
  43. package/dist/core/index.d.ts.map +1 -1
  44. package/dist/daemon/DaemonConfig.d.ts +19 -0
  45. package/dist/daemon/DaemonConfig.d.ts.map +1 -0
  46. package/dist/daemon/DaemonModel.d.ts +59 -0
  47. package/dist/daemon/DaemonModel.d.ts.map +1 -0
  48. package/dist/daemon/index.d.ts +5 -0
  49. package/dist/daemon/index.d.ts.map +1 -0
  50. package/dist/index-BsQr630j.js +80 -0
  51. package/dist/index-BsQr630j.js.map +1 -0
  52. package/dist/index.d.ts +8 -28
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +7 -8693
  55. package/dist/index.js.map +1 -1
  56. package/dist/lib/fixtureFocusTrap.d.ts +2 -0
  57. package/dist/lib/fixtureFocusTrap.d.ts.map +1 -0
  58. package/dist/lib/fixtureSizeCache.d.ts +1 -10
  59. package/dist/lib/fixtureSizeCache.d.ts.map +1 -1
  60. package/dist/lib/queryParamObservable.d.ts +4 -0
  61. package/dist/lib/queryParamObservable.d.ts.map +1 -0
  62. package/dist/report/ReportModel.d.ts +23 -0
  63. package/dist/report/ReportModel.d.ts.map +1 -0
  64. package/dist/report/ScreenshotReport.d.ts +25 -0
  65. package/dist/report/ScreenshotReport.d.ts.map +1 -0
  66. package/dist/report/index.d.ts +3 -0
  67. package/dist/report/index.d.ts.map +1 -0
  68. package/dist/viewer.d.ts +52 -0
  69. package/dist/viewer.d.ts.map +1 -0
  70. package/dist/viewer.js +3903 -0
  71. package/dist/viewer.js.map +1 -0
  72. package/package.json +25 -4
  73. package/dist/core/ComponentDefinition.d.ts +0 -70
  74. package/dist/core/ComponentDefinition.d.ts.map +0 -1
  75. package/dist/core/defineFixture.d.ts +0 -109
  76. package/dist/core/defineFixture.d.ts.map +0 -1
  77. package/dist/index.css +0 -1
@@ -0,0 +1,59 @@
1
+ import { IObservable } from '@vscode/observables';
2
+ import { DaemonApiType } from '@vscode/component-explorer-cli/daemon-types';
3
+ import { DaemonConfig } from './DaemonConfig.js';
4
+ /** Screenshot result from the daemon */
5
+ export type DaemonScreenshotResult = DaemonApiType['screenshots']['take']['TResult'];
6
+ /** Comparison result from the daemon */
7
+ export type DaemonCompareResult = DaemonApiType['screenshots']['compare']['TResult'];
8
+ /** Fixture info from the daemon */
9
+ export type DaemonFixtureInfo = DaemonApiType['fixtures']['list']['TResult'][number];
10
+ export interface DaemonSession {
11
+ readonly name: string;
12
+ readonly serverUrl: string;
13
+ readonly sourceKind: 'current' | 'worktree';
14
+ }
15
+ /**
16
+ * Client-side model for interacting with the daemon.
17
+ * Manages source tree IDs, screenshot caching, and the event stream.
18
+ */
19
+ export declare class DaemonModel {
20
+ readonly config: DaemonConfig;
21
+ private readonly _sourceTreeIds;
22
+ private readonly _sessions;
23
+ private readonly _screenshotCache;
24
+ private readonly _client;
25
+ private _eventStreamAbort;
26
+ readonly sessionName: string;
27
+ /** Observable map of sessionName → current sourceTreeId */
28
+ readonly sourceTreeIds: IObservable<ReadonlyMap<string, string>>;
29
+ /** Observable list of sessions from the daemon */
30
+ readonly sessions: IObservable<readonly DaemonSession[]>;
31
+ constructor(config: DaemonConfig);
32
+ /**
33
+ * Initializes the model: fetches initial session info and starts listening to events.
34
+ * Call this once after construction.
35
+ */
36
+ initialize(): Promise<void>;
37
+ /**
38
+ * Get a screenshot for a fixture in a session, using cache when available.
39
+ * Cache is keyed on sessionName + fixtureId and invalidated when sourceTreeId changes.
40
+ */
41
+ getScreenshot(sessionName: string, fixtureId: string): Promise<DaemonScreenshotResult>;
42
+ /**
43
+ * Compare a fixture across two sessions. Returns match status and hashes (no images).
44
+ */
45
+ compare(fixtureId: string, baselineSessionName: string, currentSessionName: string): Promise<DaemonCompareResult>;
46
+ /**
47
+ * List fixtures from a session.
48
+ */
49
+ listFixtures(sessionName: string): Promise<readonly DaemonFixtureInfo[]>;
50
+ /**
51
+ * Get the explorer URL for a different session (for session switching via full navigation).
52
+ */
53
+ getSessionExplorerUrl(sessionName: string): string | undefined;
54
+ dispose(): void;
55
+ private _fetchSessionInfos;
56
+ private _startEventStream;
57
+ private _handleEvent;
58
+ }
59
+ //# sourceMappingURL=DaemonModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DaemonModel.d.ts","sourceRoot":"","sources":["../../src/daemon/DaemonModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAExE,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,6CAA6C,CAAC;AAC9F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,wCAAwC;AACxC,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC;AAErF,wCAAwC;AACxC,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC;AAErF,mCAAmC;AACnC,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAErF,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,SAAS,GAAG,UAAU,CAAC;CAC5C;AAOD;;;GAGG;AACH,qBAAa,WAAW;IAeX,QAAQ,CAAC,MAAM,EAAE,YAAY;IAdzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiE;IAChG,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuD;IACjF,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAuC;IACxE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IACxD,OAAO,CAAC,iBAAiB,CAAgC;IAEzD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,2DAA2D;IAC3D,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAuB;IAEvF,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,SAAS,aAAa,EAAE,CAAC,CAAkB;gBAErD,MAAM,EAAE,YAAY;IAKzC;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC;;;OAGG;IACG,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAuB5F;;OAEG;IACG,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAgBvH;;OAEG;IACG,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC;IAQ9E;;OAEG;IACH,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAM9D,OAAO,IAAI,IAAI;YASD,kBAAkB;YAYlB,iBAAiB;IAuB/B,OAAO,CAAC,YAAY;CAepB"}
@@ -0,0 +1,5 @@
1
+ export { DaemonModel } from './DaemonModel.js';
2
+ export type { DaemonScreenshotResult, DaemonCompareResult, DaemonFixtureInfo, DaemonSession } from './DaemonModel.js';
3
+ export { getDaemonConfig } from './DaemonConfig.js';
4
+ export type { DaemonConfig } from './DaemonConfig.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/daemon/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,80 @@
1
+ const f = Symbol.for("@vscode/component-explorer/singleFixture/v1"), i = Symbol.for("@vscode/component-explorer/fixtureGroup/v1"), u = Symbol.for("@vscode/component-explorer/fixtureVariants/v1");
2
+ function d(t) {
3
+ return {
4
+ [f]: !0,
5
+ _options: t,
6
+ _path: t.path
7
+ };
8
+ }
9
+ function p(t, e) {
10
+ if (e !== void 0) {
11
+ const r = t;
12
+ return {
13
+ [i]: !0,
14
+ _entries: e,
15
+ _path: r.path,
16
+ _labels: r.labels
17
+ };
18
+ }
19
+ return {
20
+ [i]: !0,
21
+ _entries: t
22
+ };
23
+ }
24
+ function l(t, e) {
25
+ if (e !== void 0) {
26
+ const r = t;
27
+ return {
28
+ [u]: !0,
29
+ _variants: e,
30
+ _path: r.path,
31
+ _labels: r.labels
32
+ };
33
+ }
34
+ return {
35
+ [u]: !0,
36
+ _variants: t
37
+ };
38
+ }
39
+ const c = Promise.resolve();
40
+ function x(t) {
41
+ const e = t();
42
+ return {
43
+ ready: c,
44
+ dispose: () => {
45
+ typeof e == "function" ? e() : e && typeof e.dispose == "function" && e.dispose();
46
+ }
47
+ };
48
+ }
49
+ function v(t, e) {
50
+ let r, n = !1;
51
+ function o() {
52
+ return t.aborted;
53
+ }
54
+ const a = (async () => {
55
+ if (o())
56
+ throw new DOMException("Render aborted", "AbortError");
57
+ if (r = await e(), (o() || n) && (s(), o()))
58
+ throw new DOMException("Render aborted", "AbortError");
59
+ })();
60
+ function s() {
61
+ typeof r == "function" ? r() : r && typeof r.dispose == "function" && r.dispose(), r = void 0;
62
+ }
63
+ return {
64
+ ready: a,
65
+ dispose: () => {
66
+ n = !0, s();
67
+ }
68
+ };
69
+ }
70
+ export {
71
+ u as a,
72
+ v as b,
73
+ p as c,
74
+ d,
75
+ l as e,
76
+ i as f,
77
+ x as g,
78
+ f as s
79
+ };
80
+ //# sourceMappingURL=index-BsQr630j.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BsQr630j.js","sources":["../src/core/fixtureApi.ts"],"sourcesContent":["/**\n * Public Fixture API\n * \n * This module is the public API for defining fixtures.\n * It's designed to be stable across versions - projects can use a different\n * @vscode/component-explorer version than the explorer viewer uses.\n * \n * Use Symbol.for() instead of Symbol() so the same symbol is shared across\n * different versions of this package.\n *\n * @module fixtureApi\n */\n\n// ============================================================================\n// Types for fixture definition (re-exported for convenience)\n// ============================================================================\n\n/**\n * Disposable resource that can be cleaned up.\n */\nexport interface IDisposable {\n dispose(): void;\n}\n\n/** @deprecated Use IDisposable instead */\nexport type Disposable = IDisposable;\n\n/**\n * Result of a render operation.\n * Supports both sync and async rendering with cancellation.\n * All fields are optional for simple use cases.\n */\nexport interface RenderResult {\n /**\n * Resolves when the component is fully rendered and ready.\n * For sync renders, this can be omitted (treated as immediately ready).\n * Rejects if the render is aborted via the AbortSignal.\n */\n readonly ready?: Promise<void>;\n \n /**\n * Cleanup function. Called when the fixture is unmounted.\n * Can be omitted if no cleanup is needed.\n */\n dispose?(): void;\n}\n\n/**\n * What the render function can return.\n * - undefined: no cleanup needed, immediately ready\n * - RenderResult: object with optional ready/dispose\n * - Promise<...>: async render that resolves to undefined or RenderResult\n */\nexport type RenderReturn = RenderResult | undefined | void | Promise<RenderResult | undefined | void>;\n\n/**\n * Context passed to the render function.\n */\nexport interface RenderContext {\n /** Property values based on the property schema */\n readonly props: Record<string, unknown>;\n /** AbortSignal for cancellation; check signal.aborted or listen to 'abort' event */\n readonly signal: AbortSignal;\n}\n\n/**\n * Style definition for shadow DOM injection.\n */\nexport type StyleDefinition =\n | { readonly type: 'css'; readonly content: string }\n | { readonly type: 'url'; readonly href: string }\n | { readonly type: 'adopted'; readonly sheet: CSSStyleSheet };\n\n/**\n * Display mode for a component.\n */\nexport type DisplayMode = PageMode | ComponentMode;\n\n/**\n * Page mode - component fills a viewport with device presets.\n */\nexport interface PageMode {\n readonly type: 'page';\n readonly viewports: ViewportPreset[];\n}\n\n/**\n * Component mode - renders at natural size.\n */\nexport interface ComponentMode {\n readonly type: 'component';\n}\n\n/**\n * Viewport preset - either a named preset or custom dimensions.\n */\nexport type ViewportPreset =\n | ViewportPresetName\n | { readonly name: string; readonly width: number; readonly height: number };\n\nexport type ViewportPresetName = 'mobile' | 'tablet' | 'desktop';\n\n/**\n * Schema for a component property.\n */\nexport type PropertySchema =\n | BooleanProperty\n | StringProperty\n | NumberProperty\n | EnumProperty;\n\nexport interface BooleanProperty {\n readonly type: 'boolean';\n readonly name: string;\n readonly defaultValue: boolean;\n readonly description?: string;\n}\n\nexport interface StringProperty {\n readonly type: 'string';\n readonly name: string;\n readonly defaultValue: string;\n readonly description?: string;\n readonly multiline?: boolean;\n}\n\nexport interface NumberProperty {\n readonly type: 'number';\n readonly name: string;\n readonly defaultValue: number;\n readonly description?: string;\n readonly min?: number;\n readonly max?: number;\n readonly step?: number;\n}\n\nexport interface EnumProperty {\n readonly type: 'enum';\n readonly name: string;\n readonly defaultValue: string;\n readonly description?: string;\n readonly options: readonly string[];\n}\n\n// ============================================================================\n// Brand symbols - use Symbol.for() for cross-version compatibility\n// ============================================================================\n\n/** Brand symbol to identify single fixtures */\nexport const singleFixtureBrand = Symbol.for('@vscode/component-explorer/singleFixture/v1');\n\n/** Brand symbol to identify fixture groups */\nexport const fixtureGroupBrand = Symbol.for('@vscode/component-explorer/fixtureGroup/v1');\n\n/** Brand symbol to identify fixture variants */\nexport const fixtureVariantsBrand = Symbol.for('@vscode/component-explorer/fixtureVariants/v1');\n\n// ============================================================================\n// Define fixture options\n// ============================================================================\n\n/**\n * Options for defining a single component fixture.\n */\nexport interface DefineFixtureOptions {\n /**\n * Path in the explorer tree.\n * - `undefined` (default): use fixture filename only\n * - `'Foo/Bar'`: exact path (fixture filename NOT appended)\n * - `'Foo/Bar/'`: prefix (fixture filename IS appended → Foo/Bar/{filename})\n * \n * @throws Error if path contains empty segments (e.g., '/foo', 'foo//bar')\n */\n path?: string;\n\n /** Optional description for documentation */\n description?: string;\n\n /** How to isolate: 'iframe' for full isolation, 'shadow-dom' (default) for lighter isolation */\n isolation?: 'iframe' | 'shadow-dom';\n\n /** Display mode: defaults to { type: 'component' } */\n displayMode?: DisplayMode;\n\n /** Styles to inject (for shadow-dom isolation) */\n styles?: StyleDefinition[];\n\n /** Background pattern for the preview canvas: 'light' (default) or 'dark' for dark transparent pattern */\n background?: 'light' | 'dark';\n\n /** Labels for categorization and filtering (e.g. 'animation', 'blocks-ci') */\n labels?: readonly string[];\n\n /** Property definitions */\n properties?: PropertySchema[];\n\n /**\n * Render the component into the container.\n * \n * @param container - The DOM element to render into\n * @param context - Render context containing props and abort signal\n * @returns Optional RenderResult, or a Promise that resolves to one\n */\n render: (container: HTMLElement, context: RenderContext) => RenderReturn;\n}\n\n/** @deprecated Use DefineFixtureOptions instead */\nexport type DefineComponentOptions = DefineFixtureOptions;\n\n// ============================================================================\n// Fixture export types (opaque to the user, consumed by fixtureApiConsumer)\n// ============================================================================\n\n/**\n * A single fixture export created by defineFixture().\n */\nexport interface SingleFixtureExport {\n readonly [singleFixtureBrand]: true;\n readonly _options: DefineFixtureOptions;\n readonly _path?: string;\n}\n\n/**\n * Group entry: either a single fixture, a nested group, or variants.\n */\nexport type FixtureGroupEntry = SingleFixtureExport | FixtureGroupExport | FixtureVariantsExport;\n\n/**\n * A fixture group export created by defineFixtureGroup().\n */\nexport interface FixtureGroupExport {\n readonly [fixtureGroupBrand]: true;\n readonly _entries: { [key: string]: FixtureGroupEntry };\n readonly _path?: string;\n readonly _labels?: readonly string[];\n}\n\n/**\n * A fixture variants export created by defineFixtureVariants().\n */\nexport interface FixtureVariantsExport {\n readonly [fixtureVariantsBrand]: true;\n readonly _variants: { [key: string]: SingleFixtureExport };\n readonly _path?: string;\n readonly _labels?: readonly string[];\n}\n\n/**\n * Fixture export type - a single fixture, a group, or variants.\n */\nexport type FixtureExport = SingleFixtureExport | FixtureGroupExport | FixtureVariantsExport;\n\n/**\n * Input for defineFixtureGroup.\n */\nexport type FixtureGroupInput = { [key: string]: FixtureGroupEntry };\n\n/**\n * Options for defineFixtureGroup with optional path.\n */\nexport interface DefineFixtureGroupOptions {\n /**\n * Path in the explorer tree.\n * - `undefined` (default): use fixture filename only\n * - `'Foo/Bar'`: exact path (fixture filename NOT appended)\n * - `'Foo/Bar/'`: prefix (fixture filename IS appended → Foo/Bar/{filename})\n */\n path?: string;\n\n /** Labels for categorization and filtering (e.g. 'animation', 'blocks-ci') */\n labels?: readonly string[];\n}\n\n/**\n * Input for defineFixtureVariants (only single fixtures, no nesting).\n */\nexport type FixtureVariantsInput = { [key: string]: SingleFixtureExport };\n\n/**\n * Options for defineFixtureVariants with optional path.\n */\nexport interface DefineFixtureVariantsOptions {\n /**\n * Path in the explorer tree.\n * - `undefined` (default): use fixture filename only \n * - `'Foo/Bar'`: exact path (fixture filename NOT appended)\n * - `'Foo/Bar/'`: prefix (fixture filename IS appended → Foo/Bar/{filename})\n */\n path?: string;\n\n /** Labels for categorization and filtering (e.g. 'animation', 'blocks-ci') */\n labels?: readonly string[];\n}\n\n// ============================================================================\n// Define fixture functions\n// ============================================================================\n\n/**\n * Defines a single fixture.\n * \n * @example\n * ```ts\n * // Simple - no cleanup needed\n * export default defineFixture({\n * render: (container, { props }) => {\n * container.innerHTML = `<button>${props.label}</button>`;\n * },\n * });\n * \n * // With cleanup\n * export default defineFixture({\n * render: (container, { props }) => {\n * const root = createRoot(container);\n * root.render(<Button label={props.label} />);\n * return { dispose: () => root.unmount() };\n * },\n * });\n * \n * // Async render\n * export default defineFixture({\n * render: async (container, { props, signal }) => {\n * const data = await fetch(props.url, { signal });\n * container.innerHTML = await data.text();\n * return { dispose: () => { container.innerHTML = ''; } };\n * },\n * });\n * ```\n */\nexport function defineFixture(options: DefineFixtureOptions): SingleFixtureExport {\n return {\n [singleFixtureBrand]: true,\n _options: options,\n _path: options.path,\n };\n}\n\n/**\n * Defines a group of fixtures with support for nesting.\n * \n * @example\n * ```ts\n * export default defineFixtureGroup({\n * Primary: defineFixture({\n * render: (container) => { ... },\n * }),\n * Variants: defineFixtureGroup({\n * Small: defineFixture({ ... }),\n * Large: defineFixture({ ... }),\n * }),\n * });\n * ```\n */\nexport function defineFixtureGroup(entries: FixtureGroupInput): FixtureGroupExport;\nexport function defineFixtureGroup(options: DefineFixtureGroupOptions, entries: FixtureGroupInput): FixtureGroupExport;\nexport function defineFixtureGroup(optionsOrEntries: DefineFixtureGroupOptions | FixtureGroupInput, maybeEntries?: FixtureGroupInput): FixtureGroupExport {\n if (maybeEntries !== undefined) {\n const opts = optionsOrEntries as DefineFixtureGroupOptions;\n return {\n [fixtureGroupBrand]: true,\n _entries: maybeEntries,\n _path: opts.path,\n _labels: opts.labels,\n };\n }\n return {\n [fixtureGroupBrand]: true,\n _entries: optionsOrEntries as FixtureGroupInput,\n };\n}\n\n/**\n * Defines a group of fixture variants (no nesting allowed).\n * Variants are rendered horizontally by default and have a distinct icon in the tree.\n * \n * @example\n * ```ts\n * export default defineFixtureGroup({\n * Button: defineFixtureVariants({\n * Small: defineFixture({ ... }),\n * Medium: defineFixture({ ... }),\n * Large: defineFixture({ ... }),\n * }),\n * });\n * ```\n */\nexport function defineFixtureVariants(variants: FixtureVariantsInput): FixtureVariantsExport;\nexport function defineFixtureVariants(options: DefineFixtureVariantsOptions, variants: FixtureVariantsInput): FixtureVariantsExport;\nexport function defineFixtureVariants(optionsOrVariants: DefineFixtureVariantsOptions | FixtureVariantsInput, maybeVariants?: FixtureVariantsInput): FixtureVariantsExport {\n if (maybeVariants !== undefined) {\n const opts = optionsOrVariants as DefineFixtureVariantsOptions;\n return {\n [fixtureVariantsBrand]: true,\n _variants: maybeVariants,\n _path: opts.path,\n _labels: opts.labels,\n };\n }\n return {\n [fixtureVariantsBrand]: true,\n _variants: optionsOrVariants as FixtureVariantsInput,\n };\n}\n\n// ============================================================================\n// Render helpers\n// ============================================================================\n\n/** Already-resolved promise, reused for efficiency */\nconst resolvedPromise = Promise.resolve();\n\n/**\n * Helper for synchronous renders.\n * Executes the render function immediately and wraps the cleanup in a RenderResult.\n * \n * @param doRender - Function that renders synchronously and returns a cleanup function\n * @returns A RenderResult with an already-resolved ready promise\n * \n * @example\n * ```ts\n * render: (container, { props }) => syncRender(() => {\n * const el = document.createElement('button');\n * el.textContent = props.label;\n * container.appendChild(el);\n * return () => el.remove();\n * })\n * ```\n */\nexport function syncRender(doRender: () => (() => void) | IDisposable | void): RenderResult {\n const cleanup = doRender();\n return {\n ready: resolvedPromise,\n dispose: () => {\n if (typeof cleanup === 'function') {\n cleanup();\n } else if (cleanup && typeof cleanup.dispose === 'function') {\n cleanup.dispose();\n }\n },\n };\n}\n\n/**\n * Helper for asynchronous renders with cancellation support.\n * \n * @param signal - AbortSignal for cancellation\n * @param doRender - Async function that renders and returns a cleanup function.\n * Should check signal.aborted periodically for long operations.\n * @returns A RenderResult whose ready promise rejects with AbortError if cancelled\n * \n * @example\n * ```ts\n * render: (container, { props, signal }) => asyncRender(signal, async () => {\n * const data = await fetchData(props.url, { signal });\n * if (signal.aborted) return;\n * container.innerHTML = data;\n * return () => { container.innerHTML = ''; };\n * })\n * ```\n */\nexport function asyncRender(\n signal: AbortSignal,\n doRender: () => Promise<(() => void) | IDisposable | void>\n): RenderResult {\n let cleanup: (() => void) | IDisposable | void;\n let disposed = false;\n\n function isAborted(): boolean {\n return signal.aborted;\n }\n\n const ready = (async () => {\n if (isAborted()) {\n throw new DOMException('Render aborted', 'AbortError');\n }\n cleanup = await doRender();\n if (isAborted() || disposed) {\n // Cleanup immediately if aborted/disposed during render\n doCleanup();\n if (isAborted()) {\n throw new DOMException('Render aborted', 'AbortError');\n }\n }\n })();\n\n function doCleanup(): void {\n if (typeof cleanup === 'function') {\n cleanup();\n } else if (cleanup && typeof cleanup.dispose === 'function') {\n cleanup.dispose();\n }\n cleanup = undefined;\n }\n\n return {\n ready,\n dispose: () => {\n disposed = true;\n doCleanup();\n },\n };\n}\n"],"names":["singleFixtureBrand","fixtureGroupBrand","fixtureVariantsBrand","defineFixture","options","defineFixtureGroup","optionsOrEntries","maybeEntries","opts","defineFixtureVariants","optionsOrVariants","maybeVariants","resolvedPromise","syncRender","doRender","cleanup","asyncRender","signal","disposed","isAborted","ready","doCleanup"],"mappings":"AAqJO,MAAMA,IAAqB,OAAO,IAAI,6CAA6C,GAG7EC,IAAoB,OAAO,IAAI,4CAA4C,GAG3EC,IAAuB,OAAO,IAAI,+CAA+C;AA8KvF,SAASC,EAAcC,GAAoD;AAChF,SAAO;AAAA,IACL,CAACJ,CAAkB,GAAG;AAAA,IACtB,UAAUI;AAAA,IACV,OAAOA,EAAQ;AAAA,EAAA;AAEnB;AAoBO,SAASC,EAAmBC,GAAiEC,GAAsD;AACxJ,MAAIA,MAAiB,QAAW;AAC9B,UAAMC,IAAOF;AACb,WAAO;AAAA,MACL,CAACL,CAAiB,GAAG;AAAA,MACrB,UAAUM;AAAA,MACV,OAAOC,EAAK;AAAA,MACZ,SAASA,EAAK;AAAA,IAAA;AAAA,EAElB;AACA,SAAO;AAAA,IACL,CAACP,CAAiB,GAAG;AAAA,IACrB,UAAUK;AAAA,EAAA;AAEd;AAmBO,SAASG,EAAsBC,GAAwEC,GAA6D;AACzK,MAAIA,MAAkB,QAAW;AAC/B,UAAMH,IAAOE;AACb,WAAO;AAAA,MACL,CAACR,CAAoB,GAAG;AAAA,MACxB,WAAWS;AAAA,MACX,OAAOH,EAAK;AAAA,MACZ,SAASA,EAAK;AAAA,IAAA;AAAA,EAElB;AACA,SAAO;AAAA,IACL,CAACN,CAAoB,GAAG;AAAA,IACxB,WAAWQ;AAAA,EAAA;AAEf;AAOA,MAAME,IAAkB,QAAQ,QAAA;AAmBzB,SAASC,EAAWC,GAAiE;AAC1F,QAAMC,IAAUD,EAAA;AAChB,SAAO;AAAA,IACL,OAAOF;AAAA,IACP,SAAS,MAAM;AACb,MAAI,OAAOG,KAAY,aACrBA,EAAA,IACSA,KAAW,OAAOA,EAAQ,WAAY,cAC/CA,EAAQ,QAAA;AAAA,IAEZ;AAAA,EAAA;AAEJ;AAoBO,SAASC,EACdC,GACAH,GACc;AACd,MAAIC,GACAG,IAAW;AAEf,WAASC,IAAqB;AAC5B,WAAOF,EAAO;AAAA,EAChB;AAEA,QAAMG,KAAS,YAAY;AACzB,QAAID;AACF,YAAM,IAAI,aAAa,kBAAkB,YAAY;AAGvD,QADAJ,IAAU,MAAMD,EAAA,IACZK,EAAA,KAAeD,OAEjBG,EAAA,GACIF;AACF,YAAM,IAAI,aAAa,kBAAkB,YAAY;AAAA,EAG3D,GAAA;AAEA,WAASE,IAAkB;AACzB,IAAI,OAAON,KAAY,aACrBA,EAAA,IACSA,KAAW,OAAOA,EAAQ,WAAY,cAC/CA,EAAQ,QAAA,GAEVA,IAAU;AAAA,EACZ;AAEA,SAAO;AAAA,IACL,OAAAK;AAAA,IACA,SAAS,MAAM;AACb,MAAAF,IAAW,IACXG,EAAA;AAAA,IACF;AAAA,EAAA;AAEJ;"}
package/dist/index.d.ts CHANGED
@@ -1,31 +1,11 @@
1
- export * from './core/index.js';
2
- export { Explorer, ExplorerWithDefaults, ExplorerModel } from './components/index.js';
3
- export type { ExplorerTreeNode } from './components/index.js';
4
- export { toExplorerTree } from './components/index.js';
5
- export { TitleBar, TitleBarButton, LeftSidebar, RightSidebar, TreeView, TreeItem, } from './components/index.js';
6
- export * from './components/icons.js';
7
- export { styles, mergeStyles } from './components/index.js';
8
- export interface FixtureModules {
9
- [path: string]: {
10
- default?: unknown;
11
- };
12
- }
13
1
  /**
14
- * The main Component Explorer application.
15
- * Create with `new ExplorerApp(element, fixtureModules)`.
2
+ * @vscode/component-explorer
3
+ *
4
+ * This is the public API for defining fixtures.
5
+ * Projects import from this module to define their fixtures.
6
+ *
7
+ * For the viewer/explorer UI, import from '@vscode/component-explorer/viewer' instead.
16
8
  */
17
- export declare class ExplorerApp {
18
- private readonly _root;
19
- private readonly _registry;
20
- constructor(element: HTMLElement, fixtureModules: FixtureModules);
21
- private _populateRegistry;
22
- /**
23
- * Updates the fixtures. The UI will update automatically since the registry is observable.
24
- */
25
- updateFixtures(fixtureModules: FixtureModules): void;
26
- /**
27
- * Unmounts the explorer and cleans up resources.
28
- */
29
- dispose(): void;
30
- }
9
+ export { defineFixture, defineFixtureGroup, defineFixtureVariants, singleFixtureBrand, fixtureGroupBrand, fixtureVariantsBrand, } from './core/fixtureApi.js';
10
+ export type { DefineFixtureOptions, DefineComponentOptions, FixtureExport, SingleFixtureExport, FixtureGroupExport, FixtureVariantsExport, FixtureGroupEntry, FixtureGroupInput, FixtureVariantsInput, IDisposable, Disposable, StyleDefinition, DisplayMode, PageMode, ComponentMode, ViewportPreset, ViewportPresetName, PropertySchema, BooleanProperty, StringProperty, NumberProperty, EnumProperty, } from './core/fixtureApi.js';
31
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAGhC,OAAO,cAAc,CAAC;AAEtB,OAAO,uCAAuC,CAAC;AAC/C,OAAO,wCAAwC,CAAC;AAMhD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtF,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,OAAO,EACL,QAAQ,EACR,cAAc,EACd,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAG/B,cAAc,uBAAuB,CAAC;AAGtC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACvC;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;gBAEvC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc;IAMhE,OAAO,CAAC,iBAAiB;IAUzB;;OAEG;IACH,cAAc,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI;IAIpD;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAEL,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EAGrB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAEV,oBAAoB,EACpB,sBAAsB,EAGtB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EAGpB,WAAW,EACX,UAAU,EACV,eAAe,EACf,WAAW,EACX,QAAQ,EACR,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,YAAY,GACb,MAAM,sBAAsB,CAAC"}