@storybook/csf
Advanced tools
Comparing version 0.0.2--canary.50.794a0bf.0 to 0.0.2--canary.51.768ca23.0
export declare const sanitize: (string: string) => string; | ||
export declare const toId: (kind: string, name?: string | undefined) => string; | ||
export declare const toId: (kind: string, name?: string) => string; | ||
export declare const storyNameFromExport: (key: string) => string; | ||
@@ -18,2 +18,3 @@ declare type StoryDescriptor = string[] | RegExp; | ||
}; | ||
export { includeConditionalArg } from './includeConditionalArg'; | ||
export * from './story'; |
@@ -11,5 +11,12 @@ "use strict"; | ||
isExportStory: true, | ||
parseKind: true | ||
parseKind: true, | ||
includeConditionalArg: true | ||
}; | ||
exports.isExportStory = isExportStory; | ||
Object.defineProperty(exports, "includeConditionalArg", { | ||
enumerable: true, | ||
get: function get() { | ||
return _includeConditionalArg.includeConditionalArg; | ||
} | ||
}); | ||
exports.parseKind = exports.storyNameFromExport = exports.toId = exports.sanitize = void 0; | ||
@@ -19,2 +26,4 @@ | ||
var _includeConditionalArg = require("./includeConditionalArg"); | ||
var _story = require("./story"); | ||
@@ -21,0 +30,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { Simplify, UnionToIntersection } from 'type-fest'; | ||
import { SBType, SBScalarType } from './SBType'; | ||
@@ -19,2 +20,17 @@ export * from './SBType'; | ||
}; | ||
declare type ConditionalTest = { | ||
truthy?: boolean; | ||
} | { | ||
exists: boolean; | ||
} | { | ||
eq: any; | ||
} | { | ||
neq: any; | ||
}; | ||
declare type ConditionalValue = { | ||
arg: string; | ||
} | { | ||
global: string; | ||
}; | ||
export declare type Conditional = ConditionalValue & ConditionalTest; | ||
export interface InputType { | ||
@@ -25,2 +41,3 @@ name?: string; | ||
type?: SBType | SBScalarType['name']; | ||
if?: Conditional; | ||
[key: string]: any; | ||
@@ -53,6 +70,11 @@ } | ||
storyResult: unknown; | ||
T?: unknown; | ||
}; | ||
export declare type StoryContextForEnhancers<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryIdentifier & { | ||
component?: TFramework['component']; | ||
subcomponents?: Record<string, TFramework['component']>; | ||
component?: (TFramework & { | ||
T: any; | ||
})['component']; | ||
subcomponents?: Record<string, (TFramework & { | ||
T: any; | ||
})['component']>; | ||
parameters: Parameters; | ||
@@ -83,16 +105,24 @@ initialArgs: TArgs; | ||
}; | ||
export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => Promise<void> | void; | ||
export declare type PartialStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<TArgs>) => TFramework['storyResult']; | ||
export declare type StepLabel = string; | ||
export declare type StepFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (label: StepLabel, play: PlayFunction<TFramework, TArgs>) => Promise<void> | void; | ||
export declare type PlayFunctionContext<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryContext<TFramework, TArgs> & { | ||
step: StepFunction<TFramework, TArgs>; | ||
}; | ||
export declare type PlayFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: PlayFunctionContext<TFramework, TArgs>) => Promise<void> | void; | ||
export declare type PartialStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (update?: StoryContextUpdate<Partial<TArgs>>) => TFramework['storyResult']; | ||
export declare type LegacyStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (context: StoryContext<TFramework, TArgs>) => TFramework['storyResult']; | ||
export declare type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => TFramework['storyResult']; | ||
export declare type ArgsStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (args: TArgs, context: StoryContext<TFramework, TArgs>) => (TFramework & { | ||
T: TArgs; | ||
})['storyResult']; | ||
export declare type StoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyStoryFn<TFramework, TArgs> | ArgsStoryFn<TFramework, TArgs>; | ||
export declare type DecoratorFunction<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (fn: PartialStoryFn<TFramework, TArgs>, c: StoryContext<TFramework, TArgs>) => TFramework['storyResult']; | ||
export declare type DecoratorApplicator<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (storyFn: LegacyStoryFn<TFramework, TArgs>, decorators: DecoratorFunction<TFramework, TArgs>[]) => LegacyStoryFn<TFramework, TArgs>; | ||
export declare type StepRunner<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = (label: StepLabel, play: PlayFunction<TFramework, TArgs>, context: PlayFunctionContext<TFramework, TArgs>) => Promise<void>; | ||
export declare type BaseAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = { | ||
decorators?: DecoratorFunction<TFramework, Args>[]; | ||
decorators?: DecoratorFunction<TFramework, TArgs>[]; | ||
parameters?: Parameters; | ||
args?: Partial<TArgs>; | ||
argTypes?: Partial<ArgTypes<TArgs>>; | ||
loaders?: LoaderFunction<TFramework, Args>[]; | ||
render?: ArgsStoryFn<TFramework, Args>; | ||
loaders?: LoaderFunction<TFramework, TArgs>[]; | ||
render?: ArgsStoryFn<TFramework, TArgs>; | ||
}; | ||
@@ -105,5 +135,6 @@ export declare type ProjectAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & { | ||
applyDecorators?: DecoratorApplicator<TFramework, Args>; | ||
runStep?: StepRunner<TFramework, TArgs>; | ||
}; | ||
declare type StoryDescriptor = string[] | RegExp; | ||
export declare type ComponentAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & { | ||
export interface ComponentAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> extends BaseAnnotations<TFramework, TArgs> { | ||
title?: ComponentTitle; | ||
@@ -113,6 +144,8 @@ id?: ComponentId; | ||
excludeStories?: StoryDescriptor; | ||
component?: TFramework['component']; | ||
component?: (TFramework & { | ||
T: Args extends TArgs ? any : TArgs; | ||
})['component']; | ||
subcomponents?: Record<string, TFramework['component']>; | ||
}; | ||
export declare type StoryAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = BaseAnnotations<TFramework, TArgs> & { | ||
} | ||
export declare type StoryAnnotations<TFramework extends AnyFramework = AnyFramework, TArgs = Args, TRequiredArgs = Partial<TArgs>> = BaseAnnotations<TFramework, TArgs> & { | ||
name?: StoryName; | ||
@@ -122,3 +155,7 @@ storyName?: StoryName; | ||
story?: Omit<StoryAnnotations<TFramework, TArgs>, 'story'>; | ||
}; | ||
} & ({} extends TRequiredArgs ? { | ||
args?: TRequiredArgs; | ||
} : { | ||
args: TRequiredArgs; | ||
}); | ||
export declare type LegacyAnnotatedStoryFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = StoryFn<TFramework, TArgs> & StoryAnnotations<TFramework, TArgs>; | ||
@@ -128,1 +165,8 @@ export declare type LegacyStoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = LegacyAnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>; | ||
export declare type StoryAnnotationsOrFn<TFramework extends AnyFramework = AnyFramework, TArgs = Args> = AnnotatedStoryFn<TFramework, TArgs> | StoryAnnotations<TFramework, TArgs>; | ||
export declare type ArgsFromMeta<TFramework extends AnyFramework, Meta> = Meta extends { | ||
render?: ArgsStoryFn<TFramework, infer RArgs>; | ||
loaders?: (infer Loaders)[]; | ||
decorators?: (infer Decorators)[]; | ||
} ? Simplify<RArgs & DecoratorsArgs<TFramework, Decorators> & LoaderArgs<TFramework, Loaders>> : unknown; | ||
declare type DecoratorsArgs<TFramework extends AnyFramework, Decorators> = UnionToIntersection<Decorators extends DecoratorFunction<TFramework, infer Args> ? Args : unknown>; | ||
declare type LoaderArgs<TFramework extends AnyFramework, Loaders> = UnionToIntersection<Loaders extends LoaderFunction<TFramework, infer Args> ? Args : unknown>; |
"use strict"; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
// NOTE Example of internal type definition for @storybook/<X> (where X is a framework) | ||
// NOTE Examples of using types from @storybook/<X> in real project | ||
var Button = function Button() { | ||
var Button = function Button(props) { | ||
return 'Button'; | ||
}; | ||
}; // NOTE Various kind usages | ||
// NOTE Various kind usages | ||
var simple = { | ||
@@ -29,6 +33,6 @@ title: 'simple', | ||
args: { | ||
a: 1 | ||
x: '1' | ||
}, | ||
argTypes: { | ||
a: { | ||
x: { | ||
type: { | ||
@@ -120,3 +124,3 @@ name: 'string' | ||
var CSF3Story = { | ||
render: function render() { | ||
render: function render(args) { | ||
return 'Named Story'; | ||
@@ -143,3 +147,3 @@ }, | ||
var CSF3StoryStrict = { | ||
render: function render() { | ||
render: function render(args) { | ||
return 'Named Story'; | ||
@@ -163,2 +167,67 @@ }, | ||
x: '1' | ||
}, | ||
play: function () { | ||
var _play = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref) { | ||
var step; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
step = _ref.step; | ||
_context2.next = 3; | ||
return step('a step', /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref2) { | ||
var substep; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
substep = _ref2.step; | ||
_context.next = 3; | ||
return substep('a substep', function () {}); | ||
case 3: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
})); | ||
function play(_x) { | ||
return _play.apply(this, arguments); | ||
} | ||
return play; | ||
}() | ||
}; | ||
var project = { | ||
runStep: function runStep(label, play, context) { | ||
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context3.abrupt("return", play(context)); | ||
case 1: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3); | ||
}))(); | ||
} | ||
@@ -165,0 +234,0 @@ }; // NOTE Jest forced to define at least one test in file |
{ | ||
"name": "@storybook/csf", | ||
"version": "0.0.2--canary.50.794a0bf.0", | ||
"version": "0.0.2--canary.51.768ca23.0", | ||
"description": "Component Story Format (CSF) utilities", | ||
@@ -41,6 +41,10 @@ "keywords": [ | ||
"jest": { | ||
"testEnvironment": "node" | ||
"testEnvironment": "node", | ||
"roots": [ | ||
"<rootDir>/src" | ||
] | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.15" | ||
"lodash": "^4.17.15", | ||
"type-fest": "^2.19.0" | ||
}, | ||
@@ -62,4 +66,4 @@ "devDependencies": { | ||
"jest": "^24.9.0", | ||
"prettier": "^1.19.1", | ||
"typescript": "^3.7.2" | ||
"prettier": "^2.7.1", | ||
"typescript": "^4.8.4" | ||
}, | ||
@@ -66,0 +70,0 @@ "auto": { |
43684
14
1077
2
+ Addedtype-fest@^2.19.0
+ Addedtype-fest@2.19.0(transitive)