generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
relax some types, add more tests & bring closer to final goal
- Loading branch information
Showing
7 changed files
with
92 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import type { Args as BaseArgs, StoryContext as BaseStoryContext } from '@storybook/types'; | ||
import type { Args as BaseArgs } from '@storybook/types'; | ||
import type { EmptyObject } from 'type-fest'; | ||
|
||
import type { Meta, StoryCmp, SvelteRenderer } from '#types'; | ||
import type { Meta, StoryCmp, StoryContext as BaseStoryContext } from '#types'; | ||
|
||
import Story from './runtime/Story.svelte'; | ||
import type { Component, SvelteComponent } from 'svelte'; | ||
|
||
export { setTemplate } from './runtime/contexts/template.svelte'; | ||
|
||
export function defineMeta< | ||
const TOverrideArgs extends BaseArgs = EmptyObject, | ||
const TMeta extends Meta = Meta, | ||
>(meta: TMeta) { | ||
export function defineMeta<const TMeta extends Meta = Meta>(meta: TMeta) { | ||
return { | ||
Story: Story as StoryCmp<TOverrideArgs, TMeta>, | ||
meta, | ||
Story: Story as StoryCmp<EmptyObject, TMeta>, | ||
meta: meta as TMeta extends { component?: infer TCmp } | ||
? TCmp extends Component | SvelteComponent | __sveltets_2_IsomorphicComponent | ||
? Meta<TCmp> | ||
: never | ||
: TMeta extends { args?: infer TArgs } | ||
? TArgs extends BaseArgs | ||
? Meta<Component<TArgs>> | ||
: never | ||
: never, | ||
}; | ||
} | ||
|
||
export type Args<Component extends ReturnType<typeof defineMeta>['Story']> = | ||
Component extends typeof Story<infer _TOverrideArgs extends BaseArgs, infer TMeta extends Meta> | ||
export type Args<Component extends StoryCmp<any, any>> = | ||
Component extends StoryCmp<infer _TOverrideArgs extends BaseArgs, infer TMeta extends Meta> | ||
? TMeta['args'] | ||
: never; | ||
|
||
export type StoryContext<Component extends ReturnType<typeof defineMeta>['Story']> = | ||
Component extends typeof Story<infer _TOverrideArgs extends BaseArgs, infer TMeta extends Meta> | ||
? BaseStoryContext<SvelteRenderer, TMeta['args']> | ||
export type StoryContext<Component extends StoryCmp<any, any>> = | ||
Component extends StoryCmp<infer _TOverrideArgs extends BaseArgs, infer TMeta extends Meta> | ||
? BaseStoryContext<TMeta['args']> | ||
: never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters