diff --git a/packages/examples/react/package.json b/packages/examples/react/package.json index 7338e6e..8b48b56 100644 --- a/packages/examples/react/package.json +++ b/packages/examples/react/package.json @@ -6,7 +6,8 @@ "scripts": { "build": "vite build", "dev": "vite --port=7707", - "preview": "vite preview", + "preview": "vite build && vite preview", + "preview-static": "vite build && open http://localhost:8080 && npx -y http-server ./dist", "storylite": "open http://localhost:7707 && vite --port=7707" }, "dependencies": { diff --git a/packages/storylite/CHANGELOG.md b/packages/storylite/CHANGELOG.md index 35c551d..43fefaa 100644 --- a/packages/storylite/CHANGELOG.md +++ b/packages/storylite/CHANGELOG.md @@ -1,5 +1,11 @@ # @storylite/storylite +## 0.1.2 + +### Patch Changes + +- fix: router has now fully static site support. fix navigation. + ## 0.1.1 ### Patch Changes diff --git a/packages/storylite/package.json b/packages/storylite/package.json index 7f1f0e3..14fd30c 100644 --- a/packages/storylite/package.json +++ b/packages/storylite/package.json @@ -1,6 +1,6 @@ { "name": "@storylite/storylite", - "version": "0.1.1", + "version": "0.1.2", "description": "A lightweight alternative to StoryBook, built on top of Vite⚡️", "license": "MIT", "type": "module", diff --git a/packages/storylite/src/components/Story.tsx b/packages/storylite/src/components/Story.tsx index e0b1b4b..e6a6225 100644 --- a/packages/storylite/src/components/Story.tsx +++ b/packages/storylite/src/components/Story.tsx @@ -7,13 +7,14 @@ import { ElementIds, StoryComponent, StoryMeta, StoryModule } from '@/types' import Toolbar from './Toolbar' -export function Story({ story, exportName }: { story: string; exportName: string }): JSX.Element { +export function Story({ story, exportName }: { story: string; exportName?: string }): JSX.Element { const notFound = ( - +

Story not found:{' '} - {story}.{exportName} + {story} + {exportName ? `.${exportName}` : '.?'}

@@ -24,8 +25,15 @@ export function Story({ story, exportName }: { story: string; exportName: string return notFound } - if (exportName.match(/^[A-Z]/) && typeof storyMapData.module[exportName] === 'function') { - const StorySandboxWrapper = createStorySandboxWrapper(story, exportName, storyMapData.module) + const defaultExportName = Object.keys(storyMapData.module).filter(key => key !== 'default')[0] + const _exportName = exportName ?? defaultExportName + + if (!_exportName) { + return notFound + } + + if (_exportName.match(/^[A-Z]/) && typeof storyMapData.module[_exportName] === 'function') { + const StorySandboxWrapper = createStorySandboxWrapper(story, _exportName, storyMapData.module) return } @@ -45,19 +53,12 @@ function createStorySandboxWrapper( } const components: [string, StoryComponent][] = [] - // const componentNames = getStoryComponentNames(storyExport) const metadata = storyExport.default || {} - // for (const key of componentNames) { - // components.push([key, storyExport[key]]) - // } - components.push([exportName, storyExport[exportName]]) const StoryWrapper = () => { const stories = components.map(([, Comp], i) => { - // const title = Comp.storyTitle || Comp.displayName || compName - return (
@@ -66,7 +67,7 @@ function createStorySandboxWrapper( }) return ( - + {stories} ) @@ -77,10 +78,12 @@ function createStorySandboxWrapper( export function StorySandbox({ story, + exportName, metadata, children, }: { story: string + exportName?: string metadata?: StoryMeta children?: React.ReactNode }) { @@ -92,7 +95,7 @@ export function StorySandbox({ return (
- +
{children === undefined &&

Loading story...

} @@ -101,20 +104,3 @@ export function StorySandbox({
) } - -// function getStoryComponentNames(storyExport: any): string[] { -// if (!storyExport) { -// return [] -// } -// -// const exports = Object.getOwnPropertyNames(storyExport) -// const componentNames: string[] = [] -// -// for (const key of exports) { -// if (key.match(/^[A-Z]/) && typeof storyExport[key] === 'function') { -// componentNames.push(key) -// } -// } -// -// return componentNames -// } diff --git a/packages/storylite/src/components/StoryFrame.tsx b/packages/storylite/src/components/StoryFrame.tsx index 95cbbb1..e459722 100644 --- a/packages/storylite/src/components/StoryFrame.tsx +++ b/packages/storylite/src/components/StoryFrame.tsx @@ -7,7 +7,7 @@ type StoryFrameProps = { export default function StoryFrame({ story, exportName }: StoryFrameProps) { const iframeSrc = - story === undefined ? '/sandbox/dashboard' : `/sandbox/stories/${story}/${exportName || ''}` + story === undefined ? '/#/sandbox/dashboard' : `/#/sandbox/stories/${story}/${exportName || ''}` return (