@gjsify/adwaita-storybook 0.35.0 → 0.37.0

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.
@@ -29,18 +29,14 @@ export declare class StorybookWebApp implements StorybookView<StoryElement> {
29
29
  /** Build the UI, instantiate stories, and select the first one. */
30
30
  mount(): void;
31
31
  /**
32
- * Adapt the two split views to the available width, the way a desktop
33
- * Adwaita window sheds panes as it narrows. There are two thresholds:
34
- *
35
- * - below {@link CONTROLS_BREAKPOINT} the controls panel folds away into an
36
- * on-demand overlay, so the sidebar + preview keep their room (this is
37
- * what a medium embed — e.g. the docs page — wants);
38
- * - below {@link NAV_BREAKPOINT} there isn't room for the sidebar either,
39
- * so the whole thing goes single-pane and navigates one column at a time.
32
+ * Adapt the two split views to the available width, the way a desktop Adwaita
33
+ * window sheds panes as it narrows: below {@link CONTROLS_BREAKPOINT} the controls
34
+ * panel folds into an on-demand overlay so sidebar + preview keep their room, and
35
+ * below {@link NAV_BREAKPOINT} the sidebar goes too and nav is single-pane.
40
36
  */
41
37
  private _observeBreakpoint;
42
38
  private _applyBreakpoint;
43
- /** The currently-displayed story, or null. */
39
+ /** The currently-displayed story, or null. Also the MCP surface via `window.__storybook`. */
44
40
  get activeStory(): StoryElement | null;
45
41
  /** Every story flattened to a summary. */
46
42
  listStories(): StorySummary[];
@@ -5,24 +5,17 @@ export type StoryArgsListener = (args: StoryArgs) => void;
5
5
  /**
6
6
  * Base class for browser story elements.
7
7
  *
8
- * Provides default chrome — a clamped boxed group with a title + description
9
- * above a centered, dashed-framed preview stage — built programmatically. Simple
10
- * stories compose their preview by calling {@link addContent}; a subclass that
11
- * needs a bespoke layout passes its own root element to the constructor (then
12
- * {@link addContent} is a no-op).
8
+ * Provides default chrome — a clamped boxed group with a title + description above a
9
+ * centered, dashed-framed preview stage. Simple stories compose their preview by
10
+ * calling {@link addContent}; a subclass needing a bespoke layout passes its own root
11
+ * element to the constructor, and {@link addContent} is then a no-op.
13
12
  */
14
13
  export declare class StoryElement extends StoryViewBase<HTMLElement> {
15
14
  /**
16
- * @param meta The story's metadata (the same renderer-agnostic object
17
- * its GTK twin uses).
18
- * @param story Variant name (defaults to "Default").
19
15
  * @param customRoot Opt out of the default chrome by supplying a root element.
20
16
  */
21
17
  constructor(meta: StoryMeta, story?: string, customRoot?: HTMLElement);
22
- /**
23
- * The root node inserted into the storybook's preview area. Alias for the
24
- * base's {@link root} getter — kept because consumers reference `.element`.
25
- */
18
+ /** Alias for the base's {@link root} getter — kept because consumers use `.element`. */
26
19
  get element(): HTMLElement;
27
20
  /** Build the @gjsify/adwaita-web DOM chrome — the single renderer seam. */
28
21
  protected createChrome(_meta: StoryMeta, customRoot?: HTMLElement): StoryChrome<HTMLElement>;
@@ -8,11 +8,7 @@ export interface WebStoryConstructor {
8
8
  }
9
9
  /** Wraps a story's content-build step (e.g. to install a shared environment). */
10
10
  export type WebStoryDecorator = (build: () => void, story: StoryElement) => void;
11
- /**
12
- * A group of related web stories, optionally wrapped by module-level decorators.
13
- * The DOM binding of {@link StoryModuleLike} over {@link StoryElement} +
14
- * {@link WebStoryConstructor}.
15
- */
11
+ /** A group of related web stories, optionally wrapped by module-level decorators. */
16
12
  export interface WebStoryModule extends StoryModuleLike<StoryElement, WebStoryConstructor> {
17
13
  stories: WebStoryConstructor[];
18
14
  /** Populated by {@link StoryRegistry.createStoryInstances}. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/adwaita-storybook",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "description": "Browser renderer for the @gjsify/stories contract — the web counterpart of @gjsify/storybook, built on @gjsify/adwaita-web",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -29,12 +29,12 @@
29
29
  "browser"
30
30
  ],
31
31
  "dependencies": {
32
- "@gjsify/adwaita-web": "^0.35.0",
33
- "@gjsify/stories": "^0.35.0",
34
- "@gjsify/storybook-core": "^0.35.0"
32
+ "@gjsify/adwaita-web": "^0.37.0",
33
+ "@gjsify/stories": "^0.37.0",
34
+ "@gjsify/storybook-core": "^0.37.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@gjsify/cli": "^0.35.0",
37
+ "@gjsify/cli": "^0.37.0",
38
38
  "typescript": "^6.0.3"
39
39
  },
40
40
  "gjsify": {
package/src/app.ts CHANGED
@@ -1,15 +1,11 @@
1
- // StorybookWebApp — the browser component browser: a sidebar of stories grouped
2
- // by category, a preview pane, and a controls panel that renders live-bound
3
- // adwaita-web rows from each story's controls. The web counterpart of
4
- // @gjsify/storybook's StorybookWindow, built from @gjsify/adwaita-web custom
5
- // elements so it looks and behaves like the native GTK storybook.
1
+ // The browser component browser — sidebar of stories by category, preview pane, and a
2
+ // controls panel of live-bound adwaita-web rows; the web counterpart of
3
+ // `@gjsify/storybook`'s `StorybookWindow`.
6
4
  //
7
- // The app state machine (register/instantiate, category grouping, show + wire
8
- // controls, the MCP control surface) lives in @gjsify/storybook-core's
9
- // StorybookController. This class is the browser StorybookView<StoryElement>:
10
- // it owns ONLY the adwaita-web split-views chrome (_buildUI), the browser-only
11
- // responsive breakpoint fold (_observeBreakpoint/_applyBreakpoint), and the
12
- // window.__storybook MCP bridge (_exposeGlobal, delegating to the controller).
5
+ // `StorybookController` in `@gjsify/storybook-core` owns the app state machine. This
6
+ // class is the browser `StorybookView<StoryElement>` and owns ONLY the split-views
7
+ // chrome (`_buildUI`), the browser-only responsive fold (`_observeBreakpoint` /
8
+ // `_applyBreakpoint`) and the `window.__storybook` MCP bridge (`_exposeGlobal`).
13
9
 
14
10
  import '@gjsify/adwaita-web'; // registers the custom elements + self-injects the adwaita stylesheet
15
11
  import type { StoryArgValue } from '@gjsify/stories';
@@ -87,14 +83,10 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
87
83
  }
88
84
 
89
85
  /**
90
- * Adapt the two split views to the available width, the way a desktop
91
- * Adwaita window sheds panes as it narrows. There are two thresholds:
92
- *
93
- * - below {@link CONTROLS_BREAKPOINT} the controls panel folds away into an
94
- * on-demand overlay, so the sidebar + preview keep their room (this is
95
- * what a medium embed — e.g. the docs page — wants);
96
- * - below {@link NAV_BREAKPOINT} there isn't room for the sidebar either,
97
- * so the whole thing goes single-pane and navigates one column at a time.
86
+ * Adapt the two split views to the available width, the way a desktop Adwaita
87
+ * window sheds panes as it narrows: below {@link CONTROLS_BREAKPOINT} the controls
88
+ * panel folds into an on-demand overlay so sidebar + preview keep their room, and
89
+ * below {@link NAV_BREAKPOINT} the sidebar goes too and nav is single-pane.
98
90
  */
99
91
  private _observeBreakpoint(): void {
100
92
  const apply = (): void => this._applyBreakpoint();
@@ -115,18 +107,14 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
115
107
  const osv = this._controlsSplit as HTMLElement & { collapsed: boolean; showSidebar: boolean };
116
108
  if (nav.collapsed !== navCollapsed) nav.collapsed = navCollapsed;
117
109
  if (osv.collapsed !== controlsCollapsed) osv.collapsed = controlsCollapsed;
118
- // Single-pane nav shows the story list first (like native); the back
119
- // button only appears once a story is pushed onto the content pane.
110
+ // Single-pane nav shows the story list first, as native does; the back button
111
+ // only appears once a story is pushed onto the content pane.
120
112
  this._navSplit.removeAttribute('show-content');
121
113
  this._backBtn.hidden = true;
122
- // The controls panel docks only when there's room; otherwise it's an
123
- // on-demand overlay so the sidebar + preview keep their space.
124
114
  osv.showSidebar = !controlsCollapsed;
125
115
  }
126
116
 
127
- // --- control surface (delegates to the controller; driven by host-level MCP via window.__storybook) ---
128
-
129
- /** The currently-displayed story, or null. */
117
+ /** The currently-displayed story, or null. Also the MCP surface via `window.__storybook`. */
130
118
  get activeStory(): StoryElement | null {
131
119
  return this._controller.activeStory;
132
120
  }
@@ -151,8 +139,6 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
151
139
  return this._controller.setActiveArg(name, value);
152
140
  }
153
141
 
154
- // --- StorybookView<StoryElement> render seams (driven by the controller) ---
155
-
156
142
  renderSidebar(groups: Array<CategoryGroup<StoryElement>>, onSelect: (instance: StoryElement) => void): void {
157
143
  this._listEl.replaceChildren();
158
144
  this._rowByTitle.clear();
@@ -217,7 +203,6 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
217
203
  }
218
204
 
219
205
  private _buildUI(): void {
220
- // --- Sidebar pane: header + scrollable story list ---
221
206
  this._listEl = h('div', { class: 'sb-sidebar-list navigation-sidebar' });
222
207
  const sidebarScroll = h('div', { class: 'sb-sidebar-scroll' }, [this._listEl]);
223
208
  const sidebarHeader = h('adw-header-bar', { slot: 'top' }, [
@@ -227,7 +212,6 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
227
212
  h('adw-toolbar-view', {}, [sidebarHeader, sidebarScroll]),
228
213
  ]);
229
214
 
230
- // --- Content pane: preview header + (preview | controls) split ---
231
215
  this._previewEl = h('div', { class: 'sb-preview-scroll' });
232
216
 
233
217
  this._controlsGroup = h('adw-preferences-group', { title: 'Controls' });
@@ -249,7 +233,6 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
249
233
 
250
234
  this._controlsSplit = controlsSplit;
251
235
 
252
- // Back button — only shown when collapsed, returns to the story list.
253
236
  this._backBtn = h('button', {
254
237
  class: 'adw-header-btn sb-back-btn',
255
238
  slot: 'start',
@@ -279,7 +262,6 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
279
262
  h('adw-toolbar-view', {}, [previewHeader, controlsSplit]),
280
263
  ]);
281
264
 
282
- // --- Outer split + window ---
283
265
  this._navSplit = h('adw-navigation-split-view', { 'min-sidebar-width': '220', 'max-sidebar-width': '320' }, [
284
266
  sidebarPane,
285
267
  contentPane,
@@ -289,8 +271,8 @@ export class StorybookWebApp implements StorybookView<StoryElement> {
289
271
  }
290
272
 
291
273
  private _exposeGlobal(): void {
292
- // Expose a tiny control surface so the host browser's MCP `eval_js` can
293
- // drive stories without an in-page devtools channel.
274
+ // A control surface for the host browser's MCP `eval_js`, so stories can be
275
+ // driven without an in-page devtools channel.
294
276
  (globalThis as unknown as { __storybook?: unknown }).__storybook = {
295
277
  listStories: () => this.listStories(),
296
278
  openStory: (title: string) => this.openStoryByTitle(title),
package/src/controls.ts CHANGED
@@ -1,11 +1,8 @@
1
- // Control-row builders — render each @gjsify/stories ControlType as an
2
- // @gjsify/adwaita-web row, wired two-way to a StoryElement's args. The web
3
- // counterpart of StorybookWindow's _createControlRow family.
4
- //
5
- // All the per-kind value coercion (initial-value seeding, SELECT index↔value,
6
- // RANGE/NUMBER formatting + type guards, the refresh "set only if differs"
7
- // guard) now lives in @gjsify/storybook-core's bindControl. This file supplies
8
- // ONLY the adwaita-web leaf-widget factory — the single renderer seam.
1
+ // Renders each `@gjsify/stories` ControlType as an `@gjsify/adwaita-web` row, wired
2
+ // two-way to a StoryElement's args. Per-kind value coercion (initial-value seeding,
3
+ // SELECT index↔value, RANGE/NUMBER formatting + guards, the refresh "set only if
4
+ // differs" guard) belongs to `bindControl` in `@gjsify/storybook-core`; this file
5
+ // supplies ONLY the adwaita-web leaf-widget factory, the single renderer seam.
9
6
 
10
7
  import type { StoryControl, StoryNumberControl, StorySelectControl } from '@gjsify/stories';
11
8
  import {
@@ -25,9 +22,8 @@ export function createControlRow(story: StoryElement, control: StoryControl): Co
25
22
  }
26
23
 
27
24
  /**
28
- * The @gjsify/adwaita-web leaf-widget factory — builds one `adw-*` (or range/
29
- * color) element per control kind with get/set/onChange over the DOM events the
30
- * widgets emit. The only renderer-specific seam; all coercion is in bindControl.
25
+ * One `adw-*` (or range/color) element per control kind, with get/set/onChange over the
26
+ * DOM events those widgets emit. The only renderer-specific seam.
31
27
  */
32
28
  const ADWAITA_WEB_FACTORY: ControlWidgetFactory<HTMLElement> = {
33
29
  text(label: string): ControlWidget<HTMLElement, string> {
package/src/index.ts CHANGED
@@ -1,21 +1,16 @@
1
- // @gjsify/adwaita-storybook — browser renderer for the @gjsify/stories contract.
2
- // The web counterpart of @gjsify/storybook: author *.web.ts files as
3
- // StoryElement subclasses and render them in a generic Adwaita component browser
4
- // built from @gjsify/adwaita-web, looking and behaving like the native GTK
5
- // storybook.
1
+ // Browser renderer for the `@gjsify/stories` contract, the web counterpart of
2
+ // `@gjsify/storybook`: `*.web.ts` files author `StoryElement` subclasses, rendered in
3
+ // an Adwaita component browser built from `@gjsify/adwaita-web`.
6
4
  //
7
- // A screenshot harness comparing the renderers is NOT implemented (#1052). What
8
- // holds their behaviour together is the @gjsify/adwaita-core/conformance vector
9
- // tables, which both renderer suites assert their real widgets against.
10
- //
11
- // A thin DOM adapter over @gjsify/storybook-core — the renderer-agnostic logic
12
- // (story base, registry, control binding, app controller) lives in core; this
13
- // package keeps only the @gjsify/adwaita-web view layer.
5
+ // A thin DOM adapter over `@gjsify/storybook-core`, which owns the renderer-agnostic
6
+ // logic (story base, registry, control binding, app controller) — this package is only
7
+ // the view layer. Nothing compares the two renderers by screenshot (#1052); what holds
8
+ // their behaviour together is the `@gjsify/adwaita-core/conformance` vector tables both
9
+ // renderer suites assert their real widgets against.
14
10
 
15
- // Re-export the renderer-agnostic authoring contract so a story only needs one
16
- // import (`@gjsify/adwaita-storybook`). The web-specific WebStoryModule /
17
- // WebStoryDecorator (which reference StoryElement) intentionally shadow the
18
- // generic ones from @gjsify/stories.
11
+ // The authoring contract is re-exported so a story needs one import only. The
12
+ // web-specific WebStoryModule / WebStoryDecorator intentionally shadow the generic
13
+ // ones from `@gjsify/stories`, because they reference `StoryElement`.
19
14
  export {
20
15
  ControlType,
21
16
  argsFromControls,
package/src/registry.ts CHANGED
@@ -1,8 +1,4 @@
1
- // StoryRegistry — collects web story modules and instantiates their elements.
2
- //
3
- // The registration/instantiation logic (validate, filter, decorator reduceRight
4
- // fold over initialize()) is renderer-agnostic and now lives in
5
- // @gjsify/storybook-core. This file just re-exports the generic class; callers
6
- // type it as `StoryRegistry<StoryElement>`.
1
+ // Re-export of the renderer-agnostic registry; web callers type it as
2
+ // `StoryRegistry<StoryElement>`.
7
3
 
8
4
  export { StoryRegistry } from '@gjsify/storybook-core';
@@ -1,15 +1,9 @@
1
- // StoryElement — base class for browser story implementations. The web
2
- // counterpart of @gjsify/storybook's StoryWidget (which extends Adw.Bin): it
3
- // builds DOM with @gjsify/adwaita-web components instead of GTK widgets, but
4
- // exposes the same authoring surface (getMetadata, initialize, updateArgs,
5
- // teardown, addContent, meta/story/args) so a story is a near-1:1 port of its
6
- // GTK twin. That is a claim about the story SOURCE, which is readable here; that
7
- // the two then render identically is not measured anywhere (#1052).
1
+ // The web counterpart of `@gjsify/storybook`'s `StoryWidget` (an `Adw.Bin`): same
2
+ // authoring surface, DOM instead of GTK widgets, so a story is a near-1:1 port of its
3
+ // GTK twin in SOURCE. Whether the two then render identically is not measured (#1052).
8
4
  //
9
- // Thin DOM adapter over @gjsify/storybook-core's StoryViewBase: the
10
- // renderer-agnostic state (meta/story/args, onArgsChanged/setArg, the
11
- // initialize/updateArgs/teardown/addContent surface) lives in the base; this
12
- // class supplies ONLY the @gjsify/adwaita-web DOM chrome via createChrome().
5
+ // Thin DOM adapter over `StoryViewBase`, which owns the renderer-agnostic state; this
6
+ // class supplies ONLY the `@gjsify/adwaita-web` DOM chrome, via `createChrome()`.
13
7
 
14
8
  import type { StoryArgs, StoryMeta } from '@gjsify/stories';
15
9
  import { type StoryChrome, StoryViewBase } from '@gjsify/storybook-core';
@@ -20,17 +14,13 @@ export type StoryArgsListener = (args: StoryArgs) => void;
20
14
  /**
21
15
  * Base class for browser story elements.
22
16
  *
23
- * Provides default chrome — a clamped boxed group with a title + description
24
- * above a centered, dashed-framed preview stage — built programmatically. Simple
25
- * stories compose their preview by calling {@link addContent}; a subclass that
26
- * needs a bespoke layout passes its own root element to the constructor (then
27
- * {@link addContent} is a no-op).
17
+ * Provides default chrome — a clamped boxed group with a title + description above a
18
+ * centered, dashed-framed preview stage. Simple stories compose their preview by
19
+ * calling {@link addContent}; a subclass needing a bespoke layout passes its own root
20
+ * element to the constructor, and {@link addContent} is then a no-op.
28
21
  */
29
22
  export class StoryElement extends StoryViewBase<HTMLElement> {
30
23
  /**
31
- * @param meta The story's metadata (the same renderer-agnostic object
32
- * its GTK twin uses).
33
- * @param story Variant name (defaults to "Default").
34
24
  * @param customRoot Opt out of the default chrome by supplying a root element.
35
25
  */
36
26
  constructor(meta: StoryMeta, story = 'Default', customRoot?: HTMLElement) {
@@ -38,10 +28,7 @@ export class StoryElement extends StoryViewBase<HTMLElement> {
38
28
  this.initBase(meta, story, customRoot);
39
29
  }
40
30
 
41
- /**
42
- * The root node inserted into the storybook's preview area. Alias for the
43
- * base's {@link root} getter — kept because consumers reference `.element`.
44
- */
31
+ /** Alias for the base's {@link root} getter — kept because consumers use `.element`. */
45
32
  get element(): HTMLElement {
46
33
  return this.root;
47
34
  }
@@ -77,9 +64,8 @@ export class StoryElement extends StoryViewBase<HTMLElement> {
77
64
  descEl.className = 'sb-story-group-description';
78
65
  header.append(titleEl, descEl);
79
66
 
80
- // Subtle dashed frame so the preview's bounds stay locatable even when
81
- // the widget is transparent or in an empty state (mirrors the native
82
- // .story-stage in @gjsify/storybook).
67
+ // Dashed frame so the preview's bounds stay locatable even when the widget is
68
+ // transparent or empty (mirrors the native `.story-stage`).
83
69
  const stage = document.createElement('div');
84
70
  stage.className = 'story-stage';
85
71
 
package/src/styles.ts CHANGED
@@ -1,7 +1,6 @@
1
- // Built-in storybook-web chrome styles, shipped as a string and injected once on
2
- // mount (mirrors @gjsify/adwaita-web's self-applied stylesheet and the native
3
- // renderer's STORYBOOK_CSS). Everything is driven by the adwaita-web CSS custom
4
- // properties so it follows the active light/dark theme.
1
+ // Chrome styles, shipped as a string and injected once on mount (as adwaita-web's own
2
+ // stylesheet and the native renderer's STORYBOOK_CSS are). Driven entirely by the
3
+ // adwaita-web CSS custom properties, so it follows the active light/dark theme.
5
4
 
6
5
  export const STORYBOOK_WEB_CSS = `
7
6
  .sb-window {
package/src/types.ts CHANGED
@@ -14,11 +14,7 @@ export interface WebStoryConstructor {
14
14
  /** Wraps a story's content-build step (e.g. to install a shared environment). */
15
15
  export type WebStoryDecorator = (build: () => void, story: StoryElement) => void;
16
16
 
17
- /**
18
- * A group of related web stories, optionally wrapped by module-level decorators.
19
- * The DOM binding of {@link StoryModuleLike} over {@link StoryElement} +
20
- * {@link WebStoryConstructor}.
21
- */
17
+ /** A group of related web stories, optionally wrapped by module-level decorators. */
22
18
  export interface WebStoryModule extends StoryModuleLike<StoryElement, WebStoryConstructor> {
23
19
  stories: WebStoryConstructor[];
24
20
  /** Populated by {@link StoryRegistry.createStoryInstances}. */