Skip to main content

Crate gpui_storybook

Crate gpui_storybook 

Source
Expand description

Public facade for building GPUI storybook binaries. Most applications should depend on this crate rather than the lower-level runtime, macro, or TOML crates. It re-exports the standard runtime shell, typed controls and workbench state, story traits, locale helpers, the gallery window, and, with the default macros feature, the story registration macros. The Inspect workbench tab always shows the active story key and source. Enable the opt-in inspector feature for its GPUI Component Inspector button and StoryInspectorState story-root metadata.

Story registration flows through inventory: #[story] and #[derive(ComponentStory)] submit story entries, #[derive(Substory)] derives stable capture keys for styled section or custom StorySectionBase regions inside a story, and #[story_init] submits one-time setup hooks. The hidden __registry and __inventory re-exports are the stable expansion path used by those macros.

#[derive(StoryControls)] and field-level #[storybook(control...)] metadata connect an exact Entity<S> to the Controls tab and MCP automation. Only marked fields are registered. #[derive(ComponentStory)] accepts the same field metadata and derives reset defaults from its configured example. Explicit stories declare reusable workflows with Story::scenarios; a component derive accepts scenarios = .... Workbench and automation runs recreate the concrete story before applying scenario controls, presentation, named steps, exact postconditions, and optional capture. StorybookElementExt associates route-local automation targets and JSON state with rendered children. MCP clients can read semantic values after a fresh frame without requiring a screenshot; capture remains the visual-presentation assertion surface.

init and generate_stories load crate-local storybook.toml files for discovered story crates and select a runtime config by matching the running binary name against registered story crate names. Initialization applies launch-only preference overrides; story generation applies allow and disable_story filtering, then materializes sorted StoryContainer values. A story crate config’s group becomes the sidebar’s outer group; a story’s declared section remains the nested label.

Macro-generated stories carry stable StoryKey values in the form {crate-package-name}-{registered-story-name}. These keys are copied into generated StoryContainer values as typed RegisteredStoryMetadata for automation and capture routes.

static_story_catalog and static_story_catalog_json expose the registration catalog without opening a window or constructing live stories. The static records include Rustdoc and control shape metadata; localized titles, descriptions, and control defaults remain runtime values.

Feature boundaries:

  • macros: re-exports proc macros from gpui-storybook-macros
  • inspector: adds GPUI Inspector activation and story-root metadata; the Inspect tab’s story key and source remain part of the base workbench
  • mcp: serves the live controller installed by init over MCP and re-exports automation and capture helpers. Generic remote input tools are advertised only when GPUI_STORYBOOK_MCP_ALLOW_INTERACTION=1; typed controls remain available without that capability. This feature is supported on Linux and macOS; enabling it on Windows or another target produces a compile-time error.
  • performance: enables GPUI window profiler histograms and the debug frame overlay in the Perf workbench tab

Applications with embedded locale assets should call es_fluent_build::track_i18n_assets() from build.rs. Define the embedded i18n module and typed language enum in library-reachable code, then pass typed StorybookOptions to init and await readiness before creating a story window.

PreferenceState::saved retains durable user intent, including System choices and independent light/dark theme slots. Choosing a named theme also activates its matching appearance while preserving the opposite slot. PreferenceState::resolved reports effective values and their sources after live system detection, registry fallback, and deterministic overrides. PersistenceStatus is storage-only; locale-adapter failures are reported as diagnostics and are retried on later window activation without falsifying storage state.

Re-exports§

pub use preferences::LocaleApplicationError;
pub use preferences::PreferenceOverrides;
pub use preferences::StorybookInitError;
pub use preferences::StorybookOptions;

Modules§

preferences
Public initialization and preference-state contract for Storybook consumers.
tokio_bridge
Tokio runtime shared by one Storybook GPUI app context.

Structs§

Assets
ColorSchemeResolution
Effective light/dark scheme and source.
ConsumerId
Stable identifier that isolates one Storybook consumer’s preference document.
ControlBounds
Numeric limits applied before a value reaches a story instance.
ControlColor
A serializable color used by story controls and automation.
ControlSnapshot
A current control value paired with its metadata.
ControlSpec
Metadata and default value for one story control.
CurrentLanguage
GPUI global wrapper for a typed current-language value.
Gallery
Searchable gallery host with independently toggled navigation and workbench sidebars around a story canvas centered within the available main pane.
LanguageResolution
Effective supported language and source.
LanguageTag
Validated and canonically formatted BCP 47 language tag.
PreferenceState
Saved intent and effective values used by Storybook menus and windows.
RecoveryDiagnostic
Structured record of invalid-JSON recovery.
RegisteredStoryMetadata
Typed registration metadata copied from the inventory registry into runtime story containers.
ResolvedPreferences
Fully resolved Storybook preferences and structured diagnostics.
StaticControlSpec
Static metadata for one marked story control.
StoryActionSnapshot
Runtime-visible GPUI action metadata.
StoryAutodoc
Documentation and control metadata captured at story registration time.
StoryCaptureSnapshot
StoryCatalog
Deterministic static catalog of all inventory-registered stories.
StoryCatalogEntry
One story entry exported by the static catalog.
StoryCatalogSource
Source provenance included in a static story catalog entry.
StoryContainer
StoryInteractionCaptureRequest
Optional PNG capture performed after the final interaction step.
StoryInteractionObservation
Dispatch observations for one completed interaction step.
StoryInteractionPostcondition
Exact semantic-value assertion evaluated after all interaction steps.
StoryInteractionPostconditionSnapshot
Successful result for one exact semantic-value postcondition.
StoryInteractionRequest
One exclusive interaction batch.
StoryInteractionSnapshot
Result of an interaction batch executed by the live GPUI host.
StoryInteractionTargetBounds
Logical bounds of a semantic interaction target relative to its story route.
StoryInteractionTargetSnapshot
One stable semantic interaction target rendered by a story route.
StoryInteractionTargetsSnapshot
Semantic interaction targets currently rendered by the selected route.
StoryKey
Stable runtime key for a registered story.
StoryModifiers
Modifier keys held while dispatching a pointer step.
StoryName
Story-local identity for a registered story.
StoryPoint
A point relative to the active story or substory capture region.
StoryPresentation
Viewport and canvas background applied to the selected story entity.
StoryScenario
A reusable story-owned interaction workflow.
StoryScenarioRunSnapshot
Completed result for one story-owned interaction scenario.
StoryScenarioStep
One named operation in a story-owned scenario.
StoryScenariosSnapshot
Scenario descriptors available for one selected story.
StorySection
StorySectionBase
Base capture metadata for a user-defined story section component.
StorySectionName
Stable identity for a declared story section.
StorySectionTitle
Input accepted by section and StorySectionBase::new for visible titles and stable capture keys.
StorySemanticValueSnapshot
One stable machine-readable value rendered by a story route.
StorySemanticValuesSnapshot
Machine-readable values currently rendered by the selected story route.
StoryWorkbench
Right-side developer workbench for controls, themes, inspection, actions, fresh story scenarios, and opt-in performance telemetry.
StorybookPreferences
One typed Storybook preference aggregate.
StorybookReady
Readiness result returned after initial load and foreground resolution.
StorybookWindow
Stories and window-level presentation used by create_storybook_window.
StorybookWindowUi
ThemeColorRow
One deterministic editable row from ThemeColor.
ThemeDraft
A session draft layered over the selected base theme.
ThemeDraftError
Theme draft serialization or field update failure.
ThemeId
Normalized theme registry identifier.
ThemeResolution
Effective named theme and source.
WorkbenchState
Per-window active story and variant selection.

Enums§

ColorSchemeSource
Explanation for the effective light/dark scheme.
ConsumerIdError
Failure to validate a stable Storybook consumer identifier.
ControlError
Structured failures produced while reading or editing story controls.
ControlKind
The editor presented for a control.
ControlValue
A value that can be edited by the Storybook workbench.
LanguageSource
Explanation for the effective language.
PersistenceMode
Local persistence behavior selected by a Storybook consumer.
PersistenceStatus
Current state of local preference storage.
PreferenceDiagnostic
Structured, observable startup or preference-application diagnostic.
PreferredColorScheme
Saved appearance intent.
PreferredLanguage
Saved language intent.
PreferredLanguageMode
Stable persisted language-mode token.
PreferredScrollbar
Saved scrollbar visibility policy.
RecoveryReason
Reason a persistent JSON document was archived.
ResolutionDiagnostic
Non-fatal resolution diagnostic retained for the later public facade.
StaticControlKind
The editor kind captured for a control without constructing its story.
StoryCanvasBackground
Background applied behind the active story preview.
StoryCatalogExportError
Errors returned while rendering or writing a static story catalog.
StoryInteractionDispatch
Dispatch information reported directly by GPUI.
StoryInteractionStep
One ordered interaction operation.
StoryModifier
Keyboard modifiers supported by pointer interaction.
StoryMouseButton
Mouse buttons supported by in-process story interaction.
StoryPointSpace
Coordinate space for a point inside the active story route.
StoryViewportPreset
Named viewport sizes available in the workbench and capture automation.
StorybookAutomationError
Structured live-host, validation, control, interaction, and capture errors.
SystemColorScheme
Generic light/dark device appearance supplied by the GPUI facade.
ThemeIdError
Failure to validate a theme registry identifier.
ThemeSource
Explanation for the effective named theme.
UnsupportedValueSource
Origin of an unsupported named value retained for diagnostics.
WorkbenchTab
Tabs available in the Storybook workbench.

Constants§

STORYBOOK_THEME_DIR_ENV
Native debug environment variable selecting the complete consumer theme directory.

Traits§

ControlTarget
Object-safe runtime boundary used by the workbench and MCP automation.
Language
Bounds used by generated language enums that can be stored in GPUI globals.
Story
StoryControls
Typed access generated for a story’s controllable fields.
StorybookElementExt
Fluent Storybook automation metadata for GPUI elements.
Substory
Stable descriptor for a capture-addressable section inside a story.

Functions§

capture_route_slug
Convert a section title into the slug used by sub-story capture routes.
capture_substory
Wrap a section inside a story so it can be captured as story-key/section-slug.
capture_substory_route_id
Build the capture route id for a story section title.
capture_substory_route_id_with_key
Build the capture route id for an explicit sub-story key.
capture_substory_with_key
Wrap a section inside a story with an explicit stable capture key.
create_storybook_window
Opens the standard Storybook window.
export_static_catalog_json
Renders the process-wide static story catalog as compact JSON.
export_static_catalog_json_pretty
Renders the process-wide static story catalog as pretty JSON.
generate_stories
Discovers registered stories, applies storybook.toml filtering, and returns runtime story containers.
init
Initializes Storybook and starts loading one consumer’s local preferences.
section
static_story_catalog
Collects all statically registered story metadata without constructing a live GPUI story.
static_story_catalog_json
Exports all statically registered story metadata as compact JSON.
static_story_catalog_json_pretty
Exports all statically registered story metadata as pretty JSON.
theme_color_rows
Serialize every upstream color field into deterministic workbench rows.
try_localize_message
Attempts to localize message with the installed I18n global.
try_preference_state
Returns the read-only saved and resolved preference snapshot after initialization has begun.
write_static_catalog_json
Writes the process-wide static story catalog as compact JSON to a file.
write_static_catalog_json_pretty
Writes the process-wide static story catalog as pretty JSON to a file.

Type Aliases§

StoryScenarioSnapshot
Snapshot alias used by automation and MCP list/run results.

Attribute Macros§

story
Attribute macro to register a story struct
story_init
Attribute macro to register an init function

Derive Macros§

ComponentStory
Derive macro that registers a component by generating an internal story wrapper.
StoryControls
Derives typed access to fields marked with #[storybook(control...)].
Substory
Derive stable capture metadata for sub-story sections.