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.
Move to
render(args, context)
pattern
- Loading branch information
Showing
13 changed files
with
193 additions
and
188 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
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,27 +1,27 @@ | ||
import { compile, type Root } from "svelte/compiler"; | ||
import { compile, type Root } from 'svelte/compiler'; | ||
|
||
import type { StoriesFileMeta } from "./types.js"; | ||
import { walkOnModule } from "./walkers/module.js"; | ||
import { walkOnFragment } from "./walkers/fragment.js"; | ||
import type { StoriesFileMeta } from './types.js'; | ||
import { walkOnModule } from './walkers/module.js'; | ||
import { walkOnFragment } from './walkers/fragment.js'; | ||
|
||
/** | ||
* Parse raw stories file component in Svelte format, | ||
* and extract the most stories file meta, | ||
* which are required to generate `StoryFn's` for `@storybook/svelte` components. | ||
*/ | ||
export function extractStories(rawSource: string): StoriesFileMeta { | ||
const { ast }: { ast: Root } = compile(rawSource, { modernAst: true }); | ||
const { module, fragment } = ast; | ||
const { ast }: { ast: Root } = compile(rawSource, { modernAst: true }); | ||
const { module, fragment } = ast; | ||
|
||
const moduleMeta = walkOnModule(module); | ||
const fragmentMeta = walkOnFragment({ | ||
fragment, | ||
rawSource, | ||
addonComponentName: moduleMeta.addonComponentName, | ||
}); | ||
const moduleMeta = walkOnModule(module); | ||
const fragmentMeta = walkOnFragment({ | ||
fragment, | ||
rawSource, | ||
addonComponentName: moduleMeta.addonComponentName, | ||
}); | ||
|
||
return { | ||
module: moduleMeta, | ||
fragment: fragmentMeta, | ||
}; | ||
return { | ||
module: moduleMeta, | ||
fragment: fragmentMeta, | ||
}; | ||
} |
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,59 +1,59 @@ | ||
import type { Meta } from "@storybook/svelte"; | ||
import type { Meta } from '@storybook/svelte'; | ||
|
||
import type { defineMeta } from "../index.js"; | ||
import type { defineMeta } from '../index.js'; | ||
|
||
export const ADDON_FN_NAME = "defineMeta"; | ||
export const ADDON_COMPONENT_NAME = "Story"; | ||
export const ADDON_META_VAR_NAME = "meta"; | ||
export const ADDON_FN_NAME = 'defineMeta'; | ||
export const ADDON_COMPONENT_NAME = 'Story'; | ||
export const ADDON_META_VAR_NAME = 'meta'; | ||
|
||
/** | ||
* Data extracted from the static analytic of a single stories file - `*.stories.svelte`. | ||
*/ | ||
export interface StoriesFileMeta { | ||
module: ModuleMeta; | ||
fragment: FragmentMeta; | ||
module: ModuleMeta; | ||
fragment: FragmentMeta; | ||
} | ||
|
||
/** | ||
* Meta extracted from static analysis of the module tag _(`<script context="module">`)_ | ||
* from the single stories file - `*.stories.svelte`. | ||
*/ | ||
export interface ModuleMeta extends Pick<Meta, "tags"> { | ||
description?: string; | ||
// NOTE: Why? It could be overriden with `import { defineMeta as d } ...` | ||
addonFnName: typeof defineMeta.name | (string & {}); | ||
// NOTE: Why? It could be overriden with `const { Story: S } ...` | ||
addonComponentName: typeof ADDON_COMPONENT_NAME | (string & {}); | ||
// NOTE: Why? It could be overriden with `const { meta: m } ...` | ||
addonMetaVarName: typeof ADDON_META_VAR_NAME | (string & {}); | ||
export interface ModuleMeta extends Pick<Meta, 'tags'> { | ||
description?: string; | ||
// NOTE: Why? It could be overriden with `import { defineMeta as d } ...` | ||
addonFnName: typeof defineMeta.name | (string & {}); | ||
// NOTE: Why? It could be overriden with `const { Story: S } ...` | ||
addonComponentName: typeof ADDON_COMPONENT_NAME | (string & {}); | ||
// NOTE: Why? It could be overriden with `const { meta: m } ...` | ||
addonMetaVarName: typeof ADDON_META_VAR_NAME | (string & {}); | ||
} | ||
|
||
/** | ||
* Meta extracted from static analysis of the `Fragment` _(html-like code)_ | ||
* from the single stories file - `*.stories.svelte`. | ||
*/ | ||
export interface FragmentMeta { | ||
stories: Record<StoryMeta["id"], StoryMeta>; | ||
stories: Record<StoryMeta['id'], StoryMeta>; | ||
} | ||
|
||
/** | ||
* Meta extracted from static analysis of the single <Story /> component | ||
* in the stories file - `*.stories.svelte`. | ||
*/ | ||
export interface StoryMeta { | ||
/** | ||
* Id of the story. By default is hashed, otherwise can be overriden. | ||
*/ | ||
id: string; | ||
/** | ||
* Name of the story. | ||
* @default "Default" | ||
*/ | ||
name: string; | ||
/** | ||
* Description of the story, will display above the sample in docs mode. | ||
*/ | ||
description?: string; | ||
/** Raw source for children _(what is inside the <Story>...</Story> tags)_ */ | ||
rawSource?: string; | ||
/** | ||
* Id of the story. By default is hashed, otherwise can be overriden. | ||
*/ | ||
id: string; | ||
/** | ||
* Name of the story. | ||
* @default "Default" | ||
*/ | ||
name: string; | ||
/** | ||
* Description of the story, will display above the sample in docs mode. | ||
*/ | ||
description?: string; | ||
/** Raw source for children _(what is inside the <Story>...</Story> tags)_ */ | ||
rawSource?: string; | ||
} |
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
Oops, something went wrong.