@storybook-astro/framework 0.1.0-beta.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/base-IRZo3zgK.d.ts +23 -0
- package/dist/chunk-4SWPVM6R.js +96 -0
- package/dist/chunk-4SWPVM6R.js.map +1 -0
- package/dist/chunk-5EF25G5S.js +69 -0
- package/dist/chunk-5EF25G5S.js.map +1 -0
- package/dist/chunk-7GHEQUPV.js +439 -0
- package/dist/chunk-7GHEQUPV.js.map +1 -0
- package/dist/chunk-C5OH4VBR.js +492 -0
- package/dist/chunk-C5OH4VBR.js.map +1 -0
- package/dist/chunk-DNGQBPT7.js +15 -0
- package/dist/chunk-DNGQBPT7.js.map +1 -0
- package/dist/chunk-E4LB75JN.js +89 -0
- package/dist/chunk-E4LB75JN.js.map +1 -0
- package/dist/chunk-PJEDXZVN.js +240 -0
- package/dist/chunk-PJEDXZVN.js.map +1 -0
- package/dist/chunk-UK43WNEA.js +657 -0
- package/dist/chunk-UK43WNEA.js.map +1 -0
- package/dist/dist-HJOEPVRQ.js +15574 -0
- package/dist/dist-HJOEPVRQ.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +13 -64
- package/dist/index.js.map +1 -1
- package/dist/integrations/index.d.ts +138 -0
- package/dist/integrations/index.js +8 -196
- package/dist/integrations/index.js.map +1 -1
- package/dist/middleware.d.ts +26 -0
- package/dist/middleware.js +179 -0
- package/dist/middleware.js.map +1 -0
- package/dist/portable-stories-BvdaQigq.d.ts +83 -0
- package/dist/preset.d.ts +14 -0
- package/dist/preset.js +5 -1
- package/dist/testing.d.ts +27 -0
- package/dist/testing.js +324 -15539
- package/dist/testing.js.map +1 -1
- package/dist/types-CHTsRtA7.d.ts +42 -0
- package/dist/viteStorybookAstroMiddlewarePlugin-NP2E52IC.js +11 -0
- package/dist/viteStorybookAstroMiddlewarePlugin-NP2E52IC.js.map +1 -0
- package/dist/vitest/index.d.ts +19 -0
- package/dist/vitest/index.js +229 -0
- package/dist/vitest/index.js.map +1 -0
- package/package.json +31 -17
- package/src/importAstroConfig.ts +11 -0
- package/src/index.ts +20 -6
- package/src/integrations/alpine.ts +5 -2
- package/src/integrations/base.ts +2 -2
- package/src/integrations/moduleResolver.ts +43 -0
- package/src/integrations/preact.ts +5 -2
- package/src/integrations/react.ts +5 -2
- package/src/integrations/solid.ts +5 -2
- package/src/integrations/svelte.ts +5 -2
- package/src/integrations/vue.ts +5 -2
- package/src/lib/sanitization.test.ts +232 -0
- package/src/lib/sanitization.ts +338 -0
- package/src/lib/ssr-load-module-with-fs-fallback.ts +29 -0
- package/src/middleware.test.ts +48 -0
- package/src/middleware.ts +204 -96
- package/src/module-mocks.ts +16 -0
- package/src/msw-helpers.ts +1 -0
- package/src/msw.ts +58 -0
- package/src/preset.ts +38 -3
- package/src/rules-options.test.ts +71 -0
- package/src/rules-options.ts +87 -0
- package/src/rules.test.ts +183 -0
- package/src/rules.ts +314 -0
- package/src/testing/astro-runtime.ts +219 -0
- package/src/testing/component-utils.ts +32 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/integration-config.ts +121 -0
- package/src/testing/project-root.ts +185 -0
- package/src/testing/renderer-daemon.ts +269 -0
- package/src/testing/story-composition.ts +33 -0
- package/src/testing/types.ts +14 -0
- package/src/testing/working-directory.ts +28 -0
- package/src/testing.ts +1 -254
- package/src/types.ts +16 -4
- package/src/virtual.d.ts +2 -1
- package/src/vite/createVirtualModulePlugin.test.ts +80 -0
- package/src/vite/createVirtualModulePlugin.ts +25 -0
- package/src/viteAstroContainerRenderersPlugin.ts +60 -26
- package/src/vitePluginAstro.ts +12 -5
- package/src/vitePluginAstroBuildPrerender.ts +665 -204
- package/src/vitePluginAstroRoutesFallback.ts +37 -0
- package/src/vitePluginAstroVueFallback.ts +47 -0
- package/src/viteStorybookAstroMiddlewarePlugin.ts +88 -12
- package/src/viteStorybookRendererFallbackPlugin.ts +13 -23
- package/src/vitest/config.ts +95 -0
- package/src/vitest/global-setup.ts +16 -0
- package/src/vitest/index.ts +2 -0
- package/src/vitest/vite-plugins.ts +187 -0
- package/dist/chunk-KTGNRGDJ.js +0 -561
- package/dist/chunk-KTGNRGDJ.js.map +0 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyMswHandlers,
|
|
3
|
+
resolveSanitizationOptions,
|
|
4
|
+
resolveStoryModuleMock,
|
|
5
|
+
sanitizeRenderPayload,
|
|
6
|
+
selectStoryRules,
|
|
7
|
+
withStoryModuleMocks
|
|
8
|
+
} from "./chunk-C5OH4VBR.js";
|
|
9
|
+
import "./chunk-G3PMV62Z.js";
|
|
10
|
+
|
|
11
|
+
// src/middleware.ts
|
|
12
|
+
import { pathToFileURL } from "url";
|
|
13
|
+
import { experimental_AstroContainer as AstroContainer } from "astro/container";
|
|
14
|
+
import { addRenderers, resolveClientModules } from "virtual:astro-container-renderers";
|
|
15
|
+
async function handlerFactory(_integrations, options) {
|
|
16
|
+
const mode = options?.mode ?? "development";
|
|
17
|
+
const container = await AstroContainer.create({
|
|
18
|
+
// Somewhat hacky way to force client-side Storybook's Vite to resolve modules properly
|
|
19
|
+
resolve: async (specifier) => {
|
|
20
|
+
const mockedModule = resolveStoryModuleMock(specifier);
|
|
21
|
+
if (mockedModule) {
|
|
22
|
+
return mockedModule;
|
|
23
|
+
}
|
|
24
|
+
if (specifier.startsWith("astro:scripts")) {
|
|
25
|
+
return `/@id/${specifier}`;
|
|
26
|
+
}
|
|
27
|
+
const resolution = resolveClientModules(specifier);
|
|
28
|
+
if (resolution) {
|
|
29
|
+
return resolution;
|
|
30
|
+
}
|
|
31
|
+
return specifier;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
addRenderers(container);
|
|
35
|
+
const sanitizationOptions = resolveSanitizationOptions(options?.sanitization);
|
|
36
|
+
const loadModule = options?.loadModule ?? ((id) => {
|
|
37
|
+
const normalizedId = /^[a-zA-Z]:[/\\]/.test(id) ? pathToFileURL(id).href : id;
|
|
38
|
+
return import(
|
|
39
|
+
/* @vite-ignore */
|
|
40
|
+
normalizedId
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
const componentCache = /* @__PURE__ */ new Map();
|
|
44
|
+
let renderQueue = Promise.resolve(void 0);
|
|
45
|
+
async function loadPatchedComponent(componentId, useCache = true) {
|
|
46
|
+
if (!useCache) {
|
|
47
|
+
const { default: component } = await loadModule(componentId);
|
|
48
|
+
return patchCreateAstroCompat(component);
|
|
49
|
+
}
|
|
50
|
+
if (!componentCache.has(componentId)) {
|
|
51
|
+
componentCache.set(componentId, (async () => {
|
|
52
|
+
const { default: component } = await loadModule(componentId);
|
|
53
|
+
return patchCreateAstroCompat(component);
|
|
54
|
+
})());
|
|
55
|
+
}
|
|
56
|
+
const cachedComponent = componentCache.get(componentId);
|
|
57
|
+
if (!cachedComponent) {
|
|
58
|
+
throw new Error(`Failed to load Astro component: ${componentId}`);
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
return await cachedComponent;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
componentCache.delete(componentId);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return async function handler(data) {
|
|
68
|
+
const executeRender = async () => {
|
|
69
|
+
const rulesConfigModule = options?.resolveRulesConfigModule ? await options.resolveRulesConfigModule() : void 0;
|
|
70
|
+
const selectedRules = await selectStoryRules({
|
|
71
|
+
configModule: rulesConfigModule,
|
|
72
|
+
configFilePath: options?.rulesConfigFilePath,
|
|
73
|
+
mode,
|
|
74
|
+
story: data.story
|
|
75
|
+
});
|
|
76
|
+
await applyMswHandlers(selectedRules.mswHandlers);
|
|
77
|
+
return withStoryModuleMocks(selectedRules.moduleMocks, async () => {
|
|
78
|
+
const patchedComponent = await loadPatchedComponent(
|
|
79
|
+
data.component,
|
|
80
|
+
selectedRules.moduleMocks.size === 0
|
|
81
|
+
);
|
|
82
|
+
const processedArgs = await processImageMetadata(data.args ?? {});
|
|
83
|
+
const sanitizedPayload = sanitizeRenderPayload(
|
|
84
|
+
{
|
|
85
|
+
args: processedArgs,
|
|
86
|
+
slots: data.slots ?? {}
|
|
87
|
+
},
|
|
88
|
+
sanitizationOptions
|
|
89
|
+
);
|
|
90
|
+
return container.renderToString(
|
|
91
|
+
patchedComponent,
|
|
92
|
+
{
|
|
93
|
+
props: sanitizedPayload.args,
|
|
94
|
+
slots: sanitizedPayload.slots
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const resultPromise = renderQueue.then(executeRender, executeRender);
|
|
100
|
+
renderQueue = resultPromise.then(
|
|
101
|
+
() => void 0,
|
|
102
|
+
() => void 0
|
|
103
|
+
);
|
|
104
|
+
return resultPromise;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function patchCreateAstroCompat(component) {
|
|
108
|
+
if (typeof component !== "function") {
|
|
109
|
+
throw new Error("Expected Astro component factory to be a function.");
|
|
110
|
+
}
|
|
111
|
+
const originalComponent = component;
|
|
112
|
+
const wrapped = ((result, props, slots) => {
|
|
113
|
+
if (result && typeof result.createAstro === "function") {
|
|
114
|
+
const originalCreateAstro = result.createAstro;
|
|
115
|
+
const runtimeExpectsAstroGlobal = originalCreateAstro.length >= 3;
|
|
116
|
+
result.createAstro = (...args) => {
|
|
117
|
+
if (args.length === 3 && !runtimeExpectsAstroGlobal) {
|
|
118
|
+
return originalCreateAstro(args[1], args[2]);
|
|
119
|
+
}
|
|
120
|
+
return originalCreateAstro(...args);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return originalComponent(result, props, slots);
|
|
124
|
+
});
|
|
125
|
+
wrapped.isAstroComponentFactory = originalComponent.isAstroComponentFactory;
|
|
126
|
+
wrapped.moduleId = originalComponent.moduleId;
|
|
127
|
+
wrapped.propagation = originalComponent.propagation;
|
|
128
|
+
return wrapped;
|
|
129
|
+
}
|
|
130
|
+
async function processImageMetadata(args) {
|
|
131
|
+
const processed = {};
|
|
132
|
+
for (const [key, value] of Object.entries(args)) {
|
|
133
|
+
if (isImageMetadata(value)) {
|
|
134
|
+
processed[key] = convertImageMetadataToUrl(value);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(value)) {
|
|
138
|
+
processed[key] = await Promise.all(
|
|
139
|
+
value.map(async (item) => {
|
|
140
|
+
if (isImageMetadata(item)) {
|
|
141
|
+
return convertImageMetadataToUrl(item);
|
|
142
|
+
}
|
|
143
|
+
if (isRecord(item)) {
|
|
144
|
+
return processImageMetadata(item);
|
|
145
|
+
}
|
|
146
|
+
return item;
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (isRecord(value)) {
|
|
152
|
+
processed[key] = await processImageMetadata(value);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
processed[key] = value;
|
|
156
|
+
}
|
|
157
|
+
return processed;
|
|
158
|
+
}
|
|
159
|
+
function isImageMetadata(value) {
|
|
160
|
+
return isRecord(value) && typeof value.src === "string" && ("width" in value || "height" in value || "format" in value);
|
|
161
|
+
}
|
|
162
|
+
function convertImageMetadataToUrl(imageMetadata) {
|
|
163
|
+
const src = imageMetadata.src;
|
|
164
|
+
const fsPath = imageMetadata.fsPath;
|
|
165
|
+
if (typeof src === "string") {
|
|
166
|
+
return src;
|
|
167
|
+
}
|
|
168
|
+
if (typeof fsPath === "string") {
|
|
169
|
+
return fsPath;
|
|
170
|
+
}
|
|
171
|
+
return String(imageMetadata);
|
|
172
|
+
}
|
|
173
|
+
function isRecord(value) {
|
|
174
|
+
return typeof value === "object" && value !== null;
|
|
175
|
+
}
|
|
176
|
+
export {
|
|
177
|
+
handlerFactory
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware.ts"],"sourcesContent":["import { pathToFileURL } from 'node:url';\nimport { experimental_AstroContainer as AstroContainer } from 'astro/container';\nimport type { Integration } from './integrations/index.ts';\nimport type { SanitizationOptions } from './lib/sanitization.ts';\nimport { resolveSanitizationOptions, sanitizeRenderPayload } from './lib/sanitization.ts';\nimport { resolveStoryModuleMock, withStoryModuleMocks } from './module-mocks.ts';\nimport { applyMswHandlers } from './msw.ts';\nimport { selectStoryRules } from './rules.ts';\nimport type { RenderStoryInput } from './types.ts';\nimport { addRenderers, resolveClientModules } from 'virtual:astro-container-renderers';\n\ntype ResolveRulesConfigModule = () => unknown | Promise<unknown>;\n\ntype AstroCreateResult = {\n createAstro?: (...args: unknown[]) => unknown;\n};\n\ntype AstroComponentFactory = ((\n result: AstroCreateResult,\n props: unknown,\n slots: unknown\n) => unknown) & {\n isAstroComponentFactory?: boolean;\n moduleId?: string;\n propagation?: unknown;\n};\n\nexport type HandlerProps = {\n component: string;\n args?: Record<string, unknown>;\n slots?: Record<string, unknown>;\n story?: RenderStoryInput;\n};\n\ntype HandlerFactoryOptions = {\n mode?: 'development' | 'production';\n sanitization?: SanitizationOptions;\n rulesConfigFilePath?: string;\n resolveRulesConfigModule?: ResolveRulesConfigModule;\n loadModule?: (id: string) => Promise<{ default: unknown }>;\n};\n\nexport async function handlerFactory(_integrations: Integration[], options?: HandlerFactoryOptions) {\n const mode = options?.mode ?? 'development';\n const container = await AstroContainer.create({\n // Somewhat hacky way to force client-side Storybook's Vite to resolve modules properly\n resolve: async (specifier) => {\n const mockedModule = resolveStoryModuleMock(specifier);\n\n if (mockedModule) {\n return mockedModule;\n }\n\n if (specifier.startsWith('astro:scripts')) {\n return `/@id/${specifier}`;\n }\n\n const resolution = resolveClientModules(specifier);\n\n if (resolution) {\n return resolution;\n }\n\n return specifier;\n }\n });\n\n addRenderers(container);\n const sanitizationOptions = resolveSanitizationOptions(options?.sanitization);\n const loadModule =\n options?.loadModule ??\n ((id: string) => {\n const normalizedId = /^[a-zA-Z]:[/\\\\]/.test(id) ? pathToFileURL(id).href : id;\n\n return import(/* @vite-ignore */ normalizedId);\n });\n const componentCache = new Map<string, Promise<AstroComponentFactory>>();\n let renderQueue = Promise.resolve<void>(undefined);\n\n async function loadPatchedComponent(componentId: string, useCache = true) {\n if (!useCache) {\n const { default: component } = await loadModule(componentId);\n\n return patchCreateAstroCompat(component);\n }\n\n if (!componentCache.has(componentId)) {\n componentCache.set(componentId, (async () => {\n const { default: component } = await loadModule(componentId);\n\n return patchCreateAstroCompat(component);\n })());\n }\n\n const cachedComponent = componentCache.get(componentId);\n\n if (!cachedComponent) {\n throw new Error(`Failed to load Astro component: ${componentId}`);\n }\n\n try {\n return await cachedComponent;\n } catch (error) {\n // Drop failed entries so transient/module errors can recover on the next request.\n componentCache.delete(componentId);\n throw error;\n }\n }\n\n return async function handler(data: HandlerProps) {\n const executeRender = async () => {\n const rulesConfigModule = options?.resolveRulesConfigModule\n ? await options.resolveRulesConfigModule()\n : undefined;\n\n const selectedRules = await selectStoryRules({\n configModule: rulesConfigModule,\n configFilePath: options?.rulesConfigFilePath,\n mode,\n story: data.story\n });\n\n await applyMswHandlers(selectedRules.mswHandlers);\n\n return withStoryModuleMocks(selectedRules.moduleMocks, async () => {\n const patchedComponent = await loadPatchedComponent(\n data.component,\n selectedRules.moduleMocks.size === 0\n );\n const processedArgs = await processImageMetadata(data.args ?? {});\n const sanitizedPayload = sanitizeRenderPayload(\n {\n args: processedArgs,\n slots: data.slots ?? {}\n },\n sanitizationOptions\n );\n\n return container.renderToString(\n patchedComponent as Parameters<typeof container.renderToString>[0],\n {\n props: sanitizedPayload.args,\n slots: sanitizedPayload.slots\n }\n );\n });\n };\n\n const resultPromise = renderQueue.then(executeRender, executeRender);\n\n renderQueue = resultPromise.then(\n () => undefined,\n () => undefined\n );\n\n return resultPromise;\n };\n}\n\nfunction patchCreateAstroCompat(component: unknown): AstroComponentFactory {\n if (typeof component !== 'function') {\n throw new Error('Expected Astro component factory to be a function.');\n }\n\n const originalComponent = component as AstroComponentFactory;\n const wrapped = ((result: AstroCreateResult, props: unknown, slots: unknown) => {\n if (result && typeof result.createAstro === 'function') {\n const originalCreateAstro = result.createAstro;\n const runtimeExpectsAstroGlobal = originalCreateAstro.length >= 3;\n\n result.createAstro = (...args: unknown[]) => {\n if (args.length === 3 && !runtimeExpectsAstroGlobal) {\n return originalCreateAstro(args[1], args[2]);\n }\n\n return originalCreateAstro(...args);\n };\n }\n\n return originalComponent(result, props, slots);\n }) as AstroComponentFactory;\n\n wrapped.isAstroComponentFactory = originalComponent.isAstroComponentFactory;\n wrapped.moduleId = originalComponent.moduleId;\n wrapped.propagation = originalComponent.propagation;\n\n return wrapped;\n}\n\nasync function processImageMetadata(\n args: Record<string, unknown>\n): Promise<Record<string, unknown>> {\n const processed: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(args)) {\n if (isImageMetadata(value)) {\n processed[key] = convertImageMetadataToUrl(value);\n\n continue;\n }\n\n if (Array.isArray(value)) {\n processed[key] = await Promise.all(\n value.map(async (item) => {\n if (isImageMetadata(item)) {\n return convertImageMetadataToUrl(item);\n }\n\n if (isRecord(item)) {\n return processImageMetadata(item);\n }\n\n return item;\n })\n );\n\n continue;\n }\n\n if (isRecord(value)) {\n processed[key] = await processImageMetadata(value);\n\n continue;\n }\n\n processed[key] = value;\n }\n\n return processed;\n}\n\nfunction isImageMetadata(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n typeof value.src === 'string' &&\n ('width' in value || 'height' in value || 'format' in value)\n );\n}\n\nfunction convertImageMetadataToUrl(imageMetadata: Record<string, unknown>): string {\n const src = imageMetadata.src;\n const fsPath = imageMetadata.fsPath;\n\n if (typeof src === 'string') {\n return src;\n }\n\n if (typeof fsPath === 'string') {\n return fsPath;\n }\n\n return String(imageMetadata);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B,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AO,QAAQ,UAAU;AAC3B,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,aAAa;AAC7B;AAEA,SAAS,SAAS,OAAkD;AAClE,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD;","names":[]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as storybook_internal_types from 'storybook/internal/types';
|
|
2
|
+
import { WebRenderer, ProjectAnnotations, Args, StoryAnnotationsOrFn, ComponentAnnotations, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations } from 'storybook/internal/types';
|
|
3
|
+
|
|
4
|
+
interface AstroRenderer extends WebRenderer {
|
|
5
|
+
component: any;
|
|
6
|
+
storyResult: any;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Function that sets the globalConfig of your storybook. The global config is the preview module of
|
|
10
|
+
* your .storybook folder.
|
|
11
|
+
*
|
|
12
|
+
* It should be run a single time, so that your global config (e.g. decorators) is applied to your
|
|
13
|
+
* stories when using `composeStories` or `composeStory`.
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
*
|
|
17
|
+
* ```jsx
|
|
18
|
+
* // setup-file.js
|
|
19
|
+
* import { setProjectAnnotations } from '@storybook-astro/framework';
|
|
20
|
+
* import projectAnnotations from './.storybook/preview';
|
|
21
|
+
*
|
|
22
|
+
* setProjectAnnotations(projectAnnotations);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param projectAnnotations - E.g. (import projectAnnotations from '../.storybook/preview')
|
|
26
|
+
*/
|
|
27
|
+
declare function setProjectAnnotations(projectAnnotations: NamedOrDefaultProjectAnnotations<AstroRenderer> | NamedOrDefaultProjectAnnotations<AstroRenderer>[]): NormalizedProjectAnnotations<AstroRenderer>;
|
|
28
|
+
/**
|
|
29
|
+
* Function that will receive a story along with meta (e.g. a default export from a .stories file)
|
|
30
|
+
* and optionally projectAnnotations e.g. (import * as projectAnnotations from '../.storybook/preview')
|
|
31
|
+
* and will return a composed component that has all args/parameters/decorators/etc combined and applied to it.
|
|
32
|
+
*
|
|
33
|
+
* It's very useful for reusing a story in scenarios outside of Storybook like unit testing.
|
|
34
|
+
*
|
|
35
|
+
* Example:
|
|
36
|
+
* ```jsx
|
|
37
|
+
* import { render } from '@testing-library/react';
|
|
38
|
+
* import { composeStory } from '@storybook-astro/framework';
|
|
39
|
+
* import meta, { Primary as PrimaryStory } from './Button.stories';
|
|
40
|
+
*
|
|
41
|
+
* const Primary = composeStory(PrimaryStory, meta);
|
|
42
|
+
*
|
|
43
|
+
* test('renders primary button', () => {
|
|
44
|
+
* const { getByRole } = render(<Primary>Hello world</Primary>);
|
|
45
|
+
* expect(getByRole('button')).toBeInTheDocument();
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param story - E.g. (import { Primary } from './Button.stories')
|
|
50
|
+
* @param componentAnnotations - E.g. (import meta from './Button.stories')
|
|
51
|
+
* @param projectAnnotations - E.g. (import * as projectAnnotations from '../.storybook/preview') this can be applied automatically if you use `setProjectAnnotations` in your setup files.
|
|
52
|
+
* @param exportsName - In case your story does not contain a name and you want it to have a name.
|
|
53
|
+
*/
|
|
54
|
+
declare function composeStory<TArgs extends Args = Args>(story: StoryAnnotationsOrFn<AstroRenderer, TArgs>, componentAnnotations: ComponentAnnotations<AstroRenderer, TArgs>, projectAnnotations?: ProjectAnnotations<AstroRenderer>, exportsName?: string): storybook_internal_types.ComposedStoryFn<AstroRenderer, Partial<TArgs>>;
|
|
55
|
+
/**
|
|
56
|
+
* Function that will receive a stories import (e.g. `import * as stories from './Button.stories'`)
|
|
57
|
+
* and optionally a globalConfig (e.g. `import * from '../.storybook/preview`)
|
|
58
|
+
* and will return an object containing all the stories passed, but now as a composed component that has all args/parameters/decorators/etc combined and applied to it.
|
|
59
|
+
*
|
|
60
|
+
* It's very useful for reusing stories in scenarios outside of Storybook like unit testing.
|
|
61
|
+
*
|
|
62
|
+
* Example:
|
|
63
|
+
* ```jsx
|
|
64
|
+
* import { render } from '@testing-library/react';
|
|
65
|
+
* import { composeStories } from '@storybook-astro/framework';
|
|
66
|
+
* import * as stories from './Button.stories';
|
|
67
|
+
*
|
|
68
|
+
* const { Primary, Secondary } = composeStories(stories);
|
|
69
|
+
*
|
|
70
|
+
* test('renders primary button', () => {
|
|
71
|
+
* const { getByRole } = render(<Primary>Hello world</Primary>);
|
|
72
|
+
* expect(getByRole('button')).toBeInTheDocument();
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param storiesImport - E.g. (import * as stories from './Button.stories')
|
|
77
|
+
* @param projectAnnotations - E.g. (import * as globalConfig from '../.storybook/preview') this can be applied automatically if you use `setProjectAnnotations` in your setup files.
|
|
78
|
+
*/
|
|
79
|
+
declare function composeStories<TModule extends Record<string, any>>(storiesImport: TModule, projectAnnotations?: ProjectAnnotations<AstroRenderer>): {
|
|
80
|
+
[K in keyof Omit<TModule, 'default'>]: any;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { type AstroRenderer as A, composeStory as a, composeStories as c, setProjectAnnotations as s };
|
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { c as StorybookConfigVite } from './types-CHTsRtA7.js';
|
|
2
|
+
import 'storybook/internal/types';
|
|
3
|
+
import 'vite';
|
|
4
|
+
import './base-IRZo3zgK.js';
|
|
5
|
+
import 'astro';
|
|
6
|
+
import 'sanitize-html';
|
|
7
|
+
|
|
8
|
+
declare const core: {
|
|
9
|
+
builder: string;
|
|
10
|
+
renderer: string;
|
|
11
|
+
};
|
|
12
|
+
declare const viteFinal: StorybookConfigVite['viteFinal'];
|
|
13
|
+
|
|
14
|
+
export { core, viteFinal };
|
package/dist/preset.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
core,
|
|
3
3
|
viteFinal
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-UK43WNEA.js";
|
|
5
|
+
import "./chunk-C5OH4VBR.js";
|
|
6
|
+
import "./chunk-E4LB75JN.js";
|
|
7
|
+
import "./chunk-7GHEQUPV.js";
|
|
8
|
+
import "./chunk-DNGQBPT7.js";
|
|
5
9
|
import "./chunk-G3PMV62Z.js";
|
|
6
10
|
export {
|
|
7
11
|
core,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { A as AstroRenderer, a as composeStory$1, s as setProjectAnnotations$1 } from './portable-stories-BvdaQigq.js';
|
|
2
|
+
import { Store_CSFExports, ProjectAnnotations } from 'storybook/internal/types';
|
|
3
|
+
|
|
4
|
+
declare function composeStories<TModule extends Store_CSFExports<AstroRenderer> & Record<string, unknown>>(storiesImport: TModule, projectAnnotations?: ProjectAnnotations<AstroRenderer>): { [K in keyof Omit<TModule, "default">]: any; };
|
|
5
|
+
declare const composeStory: typeof composeStory$1;
|
|
6
|
+
declare const setProjectAnnotations: typeof setProjectAnnotations$1;
|
|
7
|
+
|
|
8
|
+
type StoryMeta = {
|
|
9
|
+
component: unknown;
|
|
10
|
+
args?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
type ComposedStory = {
|
|
13
|
+
(...args: unknown[]): unknown;
|
|
14
|
+
args?: Record<string, unknown>;
|
|
15
|
+
component?: unknown;
|
|
16
|
+
run?: () => unknown | Promise<unknown>;
|
|
17
|
+
storyName?: string;
|
|
18
|
+
__storybookAstroMeta?: StoryMeta;
|
|
19
|
+
__storybookAstroStoryExport?: {
|
|
20
|
+
args?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
declare function renderStory(story: ComposedStory): Promise<any>;
|
|
25
|
+
declare const renderAstroStory: typeof renderStory;
|
|
26
|
+
|
|
27
|
+
export { composeStories, composeStory, renderAstroStory, renderStory, setProjectAnnotations };
|