-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
types.ts
121 lines (105 loc) · 3.19 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
DecoratorFunction,
Args,
StoryContextForEnhancers,
StoryId,
StoryName,
StoryIdentifier,
ViewMode,
LegacyStoryFn,
StoryContextForLoaders,
StoryContext,
ComponentTitle,
AnyFramework,
ProjectAnnotations,
ComponentAnnotations,
StoryAnnotations,
StoryFn,
StrictArgTypes,
StrictGlobalTypes,
ComponentId,
PartialStoryFn,
} from '@storybook/csf';
export type Path = string;
export type ModuleExports = Record<string, any>;
export type ModuleImportFn = (path: Path) => Promise<ModuleExports> | ModuleExports;
export type NormalizedProjectAnnotations<
TFramework extends AnyFramework
> = ProjectAnnotations<TFramework> & {
argTypes?: StrictArgTypes;
globalTypes?: StrictGlobalTypes;
};
export type NormalizedComponentAnnotations<
TFramework extends AnyFramework
> = ComponentAnnotations<TFramework> & {
// Useful to guarantee that id exists
id: ComponentId;
argTypes?: StrictArgTypes;
};
export type NormalizedStoryAnnotations<TFramework extends AnyFramework> = Omit<
StoryAnnotations<TFramework>,
'storyName' | 'story'
> & {
// You cannot actually set id on story annotations, but we normalize it to be there for convience
id: StoryId;
argTypes?: StrictArgTypes;
userStoryFn?: StoryFn<TFramework>;
};
export type CSFFile<TFramework extends AnyFramework> = {
meta: NormalizedComponentAnnotations<TFramework>;
stories: Record<StoryId, NormalizedStoryAnnotations<TFramework>>;
};
export type Story<TFramework extends AnyFramework> = StoryContextForEnhancers<TFramework> & {
originalStoryFn: StoryFn<TFramework>;
undecoratedStoryFn: LegacyStoryFn<TFramework>;
unboundStoryFn: LegacyStoryFn<TFramework>;
applyLoaders: (context: StoryContextForLoaders<TFramework>) => Promise<StoryContext<TFramework>>;
runPlayFunction: () => Promise<void>;
};
export type BoundStory<TFramework extends AnyFramework> = Story<TFramework> & {
storyFn: PartialStoryFn<TFramework>;
};
export declare type RenderContext<TFramework extends AnyFramework> = StoryIdentifier & {
showMain: () => void;
showError: (error: { title: string; description: string }) => void;
showException: (err: Error) => void;
forceRemount: boolean;
storyContext: StoryContext<TFramework>;
storyFn: PartialStoryFn<TFramework>;
unboundStoryFn: LegacyStoryFn<TFramework>;
};
export interface StoryIndexEntry {
name: StoryName;
title: ComponentTitle;
importPath: Path;
}
export interface StoryIndex {
v: number;
stories: Record<StoryId, StoryIndexEntry>;
}
export type StorySpecifier = StoryId | { name: StoryName; title: ComponentTitle } | '*';
export interface SelectionSpecifier {
storySpecifier: StorySpecifier;
viewMode: ViewMode;
args?: Args;
globals?: Args;
}
export interface Selection {
storyId: StoryId;
viewMode: ViewMode;
}
export type DecoratorApplicator<TFramework extends AnyFramework> = (
storyFn: LegacyStoryFn<TFramework>,
decorators: DecoratorFunction<TFramework>[]
) => LegacyStoryFn<TFramework>;
export interface NormalizedStoriesEntrySpecifier {
directory: string;
titlePrefix?: string;
}
export interface NormalizedStoriesEntry {
glob?: string;
specifier?: NormalizedStoriesEntrySpecifier;
}
export type ExtractOptions = {
includeDocsOnly?: boolean;
};