Shadow CSF's ProjectAnnotations with our own.

Also clean up sub types
This commit is contained in:
Tom Coleman 2022-11-01 13:37:05 +11:00
parent 2c92e6e02b
commit 16559308b1
11 changed files with 32 additions and 44 deletions

View File

@ -10,7 +10,7 @@ import {
STORY_THREW_EXCEPTION,
} from '@storybook/core-events';
import type { Store_StoryIndex, Store_TeardownrenderToRoot } from '@storybook/types';
import type { Store_StoryIndex, TeardownRenderToRoot } from '@storybook/types';
export type RenderPhase =
| 'preparing'
@ -67,7 +67,7 @@ export const docsRenderer = {
render: jest.fn().mockImplementation((context, parameters, element, cb) => cb()),
unmount: jest.fn(),
};
export const teardownrenderToRoot: jest.Mock<Store_TeardownrenderToRoot> = jest.fn();
export const teardownrenderToRoot: jest.Mock<TeardownRenderToRoot> = jest.fn();
export const projectAnnotations = {
globals: { a: 'b' },
globalTypes: {},

View File

@ -7,7 +7,7 @@ import type {
ArgsStoryFn,
Loadable,
Path,
Store_WebProjectAnnotations,
ProjectAnnotations,
} from '@storybook/types';
import { createChannel } from '@storybook/channel-postmessage';
import { addons } from '@storybook/addons';
@ -22,7 +22,7 @@ const removedApi = (name: string) => () => {
};
interface CoreClient_RendererImplementation<TFramework extends AnyFramework> {
decorateStory?: Store_WebProjectAnnotations<TFramework>['applyDecorators'];
decorateStory?: ProjectAnnotations<TFramework>['applyDecorators'];
render?: ArgsStoryFn<TFramework>;
}
@ -43,7 +43,7 @@ interface CoreClient_StartReturnValue<TFramework extends AnyFramework> {
}
export function start<TFramework extends AnyFramework>(
renderToRoot: Store_WebProjectAnnotations<TFramework>['renderToRoot'],
renderToRoot: ProjectAnnotations<TFramework>['renderToRoot'],
{ decorateStory, render }: CoreClient_RendererImplementation<TFramework> = {}
): CoreClient_StartReturnValue<TFramework> {
if (globalWindow) {

View File

@ -20,13 +20,12 @@ import type {
AnyFramework,
Args,
Globals,
ProjectAnnotations,
Store_ModuleImportFn,
Store_PromiseLike,
Store_renderToRoot,
RenderToRoot,
Store_Story,
Store_StoryIndex,
Store_WebProjectAnnotations,
ProjectAnnotations,
StoryId,
} from '@storybook/types';
import { StoryStore } from '@storybook/store';
@ -54,7 +53,7 @@ export class Preview<TFramework extends AnyFramework, TStorybookRoot = HTMLEleme
importFn?: Store_ModuleImportFn;
renderToRoot?: Store_renderToRoot<TFramework, TStorybookRoot>;
renderToRoot?: RenderToRoot<TFramework, TStorybookRoot>;
storyRenders: StoryRender<TFramework, TStorybookRoot>[] = [];
@ -84,9 +83,7 @@ export class Preview<TFramework extends AnyFramework, TStorybookRoot = HTMLEleme
// getProjectAnnotations has been run, thus this slightly awkward approach
getStoryIndex?: () => Store_StoryIndex;
importFn: Store_ModuleImportFn;
getProjectAnnotations: () => MaybePromise<
Store_WebProjectAnnotations<TFramework, TStorybookRoot>
>;
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework, TStorybookRoot>>;
}) {
// We save these two on initialization in case `getProjectAnnotations` errors,
// in which case we may need them later when we recover.
@ -111,9 +108,7 @@ export class Preview<TFramework extends AnyFramework, TStorybookRoot = HTMLEleme
}
getProjectAnnotationsOrRenderError(
getProjectAnnotations: () => MaybePromise<
Store_WebProjectAnnotations<TFramework, TStorybookRoot>
>
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework, TStorybookRoot>>
): Store_PromiseLike<ProjectAnnotations<TFramework>> {
return SynchronousPromise.resolve()
.then(getProjectAnnotations)
@ -142,7 +137,7 @@ export class Preview<TFramework extends AnyFramework, TStorybookRoot = HTMLEleme
// If initialization gets as far as project annotations, this function runs.
initializeWithProjectAnnotations(
projectAnnotations: Store_WebProjectAnnotations<TFramework, TStorybookRoot>
projectAnnotations: ProjectAnnotations<TFramework, TStorybookRoot>
) {
this.storyStore.setProjectAnnotations(projectAnnotations);

View File

@ -10,7 +10,7 @@ import {
STORY_THREW_EXCEPTION,
} from '@storybook/core-events';
import type { Store_StoryIndex, Store_TeardownrenderToRoot } from '@storybook/types';
import type { Store_StoryIndex, TeardownRenderToRoot } from '@storybook/types';
import type { RenderPhase } from './render/StoryRender';
export const componentOneExports = {
@ -58,7 +58,7 @@ export const docsRenderer = {
render: jest.fn().mockImplementation((context, parameters, element, cb) => cb()),
unmount: jest.fn(),
};
export const teardownrenderToRoot: jest.Mock<Store_TeardownrenderToRoot> = jest.fn();
export const teardownrenderToRoot: jest.Mock<TeardownRenderToRoot> = jest.fn();
export const projectAnnotations = {
globals: { a: 'b' },
globalTypes: {},

View File

@ -22,12 +22,11 @@ import type {
AnyFramework,
Args,
Globals,
ProjectAnnotations,
Store_ModuleImportFn,
Store_Selection,
Store_StoryIndex,
Store_StorySpecifier,
Store_WebProjectAnnotations,
ProjectAnnotations,
StoryId,
ViewMode,
} from '@storybook/types';
@ -101,7 +100,7 @@ export class PreviewWeb<
}
initializeWithProjectAnnotations(
projectAnnotations: Store_WebProjectAnnotations<TFramework, TStorybookRoot>
projectAnnotations: ProjectAnnotations<TFramework, TStorybookRoot>
) {
return super
.initializeWithProjectAnnotations(projectAnnotations)

View File

@ -1,6 +1,6 @@
// FIXME: breaks builder-vite, remove this in 7.0
export { composeConfigs } from '@storybook/store';
export type { Store_WebProjectAnnotations as WebProjectAnnotations } from '@storybook/types';
export type { ProjectAnnotations as WebProjectAnnotations } from '@storybook/types';
export { Preview } from './Preview';
export { PreviewWeb } from './PreviewWeb';

View File

@ -2,9 +2,9 @@ import global from 'global';
import type {
AnyFramework,
Store_RenderContext,
Store_renderToRoot,
RenderToRoot,
Store_Story,
Store_TeardownrenderToRoot,
TeardownRenderToRoot,
StoryContext,
StoryContextForLoaders,
StoryId,
@ -64,14 +64,14 @@ export class StoryRender<TFramework extends AnyFramework, TStorybookRoot = HTMLE
public disableKeyListeners = false;
private teardownRender: Store_TeardownrenderToRoot = () => {};
private teardownRender: TeardownRenderToRoot = () => {};
public torndown = false;
constructor(
public channel: Channel,
public store: StoryStore<TFramework>,
private renderToScreen: Store_renderToRoot<TFramework, TStorybookRoot>,
private renderToScreen: RenderToRoot<TFramework, TStorybookRoot>,
private callbacks: RenderContextCallbacks<TFramework>,
public id: StoryId,
public viewMode: ViewMode,

View File

@ -1,8 +1,4 @@
import type {
AnyFramework,
Store_ModuleExports,
Store_WebProjectAnnotations,
} from '@storybook/types';
import type { AnyFramework, Store_ModuleExports, ProjectAnnotations } from '@storybook/types';
import { combineParameters } from '../parameters';
import { composeStepRunners } from './stepRunners';
@ -37,7 +33,7 @@ export function getSingletonField<TFieldType = any>(
export function composeConfigs<TFramework extends AnyFramework>(
moduleExportList: Store_ModuleExports[]
): Store_WebProjectAnnotations<TFramework> {
): ProjectAnnotations<TFramework> {
const allArgTypeEnhancers = getArrayField(moduleExportList, 'argTypesEnhancers');
const stepRunners = getField(moduleExportList, 'runStep');

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { Store_RenderContext } from './store';
// import { Store_RenderContext, Store_WebProjectAnnotations } from './store';
// import { Store_RenderContext, ProjectAnnotations } from './store';
// import { ArgsStoryFn } from './csf';
export interface CoreClient_PreviewError {

View File

@ -28,7 +28,6 @@ import type {
PartialStoryFn,
PlayFunction,
PlayFunctionContext,
ProjectAnnotations,
SBArrayType,
SBEnumType,
SBIntersectionType,
@ -87,7 +86,6 @@ export type {
PartialStoryFn,
PlayFunction,
PlayFunctionContext,
ProjectAnnotations,
SBArrayType,
SBEnumType,
SBIntersectionType,

View File

@ -1,5 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { SynchronousPromise } from 'synchronous-promise';
import type { ProjectAnnotations as CsfProjectAnnotations } from '@storybook/csf';
import type { Addon_IndexEntry, Addon_StoryIndexEntry } from './addons';
import type {
AnnotatedStoryFn,
@ -13,7 +15,6 @@ import type {
Parameters,
PartialStoryFn,
Path,
ProjectAnnotations,
StoryAnnotations,
StoryContext,
StoryContextForEnhancers,
@ -34,21 +35,20 @@ export type Store_ModuleImportFn = (path: Path) => Store_PromiseLike<Store_Modul
type Store_MaybePromise<T> = Promise<T> | T;
export type Store_TeardownrenderToRoot = () => Store_MaybePromise<void>;
// We should consider renaming this to `RenderToRootElement` or similar
export type Store_renderToRoot<TFramework extends AnyFramework, TStorybookRoot = HTMLElement> = (
export type TeardownRenderToRoot = () => Store_MaybePromise<void>;
export type RenderToRoot<TFramework extends AnyFramework, TStorybookRoot = HTMLElement> = (
context: Store_RenderContext<TFramework>,
element: TStorybookRoot
) => Store_MaybePromise<void | Store_TeardownrenderToRoot>;
) => Store_MaybePromise<void | TeardownRenderToRoot>;
export type Store_WebProjectAnnotations<
export type ProjectAnnotations<
TFramework extends AnyFramework,
TStorybookRoot = HTMLElement
> = ProjectAnnotations<TFramework> & {
renderToRoot?: Store_renderToRoot<TFramework, TStorybookRoot>;
> = CsfProjectAnnotations<TFramework> & {
renderToRoot?: RenderToRoot<TFramework, TStorybookRoot>;
/* @deprecated use renderToRoot */
renderToDOM?: Store_renderToRoot<TFramework, TStorybookRoot>;
renderToDOM?: RenderToRoot<TFramework, TStorybookRoot>;
};
export type Store_NormalizedProjectAnnotations<TFramework extends AnyFramework = AnyFramework> =