@cappa/plugin-storybook 0.8.1 → 0.8.3
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/dist/index.cjs.cjs +1 -1
- package/dist/index.esm.mjs +1 -1
- package/dist/preview.cjs +61 -0
- package/dist/preview.d.cts +6 -0
- package/package.json +8 -8
package/dist/index.cjs.cjs
CHANGED
|
@@ -316,7 +316,7 @@ const cappaPluginStorybook = (options) => {
|
|
|
316
316
|
};
|
|
317
317
|
//#endregion
|
|
318
318
|
//#region src/index.cjs.ts
|
|
319
|
-
const previewAnnotations = [require.resolve("./preview.
|
|
319
|
+
const previewAnnotations = [require.resolve("./preview.cjs")];
|
|
320
320
|
//#endregion
|
|
321
321
|
exports.cappaPluginStorybook = cappaPluginStorybook;
|
|
322
322
|
exports.previewAnnotations = previewAnnotations;
|
package/dist/index.esm.mjs
CHANGED
|
@@ -316,6 +316,6 @@ const cappaPluginStorybook = (options) => {
|
|
|
316
316
|
};
|
|
317
317
|
//#endregion
|
|
318
318
|
//#region src/index.esm.ts
|
|
319
|
-
const previewAnnotations = [fileURLToPath(new URL("./preview.
|
|
319
|
+
const previewAnnotations = [fileURLToPath(new URL("./preview.mjs", import.meta.url))];
|
|
320
320
|
//#endregion
|
|
321
321
|
export { cappaPluginStorybook, previewAnnotations };
|
package/dist/preview.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let storybook_preview_api = require("storybook/preview-api");
|
|
3
|
+
//#region src/storybook/util.ts
|
|
4
|
+
/**
|
|
5
|
+
* Wait for a function to be exposed on the window object
|
|
6
|
+
* @param name - The name of the function to wait for
|
|
7
|
+
* @param timeoutMs - The timeout in milliseconds
|
|
8
|
+
* @returns The function or rejects if the function is not exposed within the timeout
|
|
9
|
+
*/
|
|
10
|
+
const waitForExposed = (name, timeoutMs = 5e3) => {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const start = performance.now();
|
|
13
|
+
const t = setInterval(() => {
|
|
14
|
+
const fn = window[name];
|
|
15
|
+
if (typeof fn === "function") {
|
|
16
|
+
clearInterval(t);
|
|
17
|
+
resolve(fn);
|
|
18
|
+
} else if (performance.now() - start > timeoutMs) {
|
|
19
|
+
clearInterval(t);
|
|
20
|
+
reject(/* @__PURE__ */ new Error(`Timed out waiting for ${name}`));
|
|
21
|
+
}
|
|
22
|
+
}, 16);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/storybook/addon/browser.ts
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the current window is a cappa window
|
|
29
|
+
*/
|
|
30
|
+
const isCappa = () => {
|
|
31
|
+
return navigator.userAgent.includes("CappaStorybook");
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/storybook/addon/preview.ts
|
|
35
|
+
const decorators = [(0, storybook_preview_api.makeDecorator)({
|
|
36
|
+
name: "withCappa",
|
|
37
|
+
parameterName: "cappa",
|
|
38
|
+
skipIfNoParametersOrOptions: false,
|
|
39
|
+
wrapper: (getStory, context, { parameters }) => {
|
|
40
|
+
if (isCappa()) {
|
|
41
|
+
window.__cappa_screenshot = true;
|
|
42
|
+
if (context.playFunction != null) window.__cappa_has_play_function = true;
|
|
43
|
+
queueMicrotask(async () => {
|
|
44
|
+
try {
|
|
45
|
+
(await waitForExposed("__cappa_parameters"))(context.id, parameters ?? {});
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("Cappa decorator error:", error);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return getStory(context);
|
|
52
|
+
}
|
|
53
|
+
})];
|
|
54
|
+
const parameters = {};
|
|
55
|
+
const afterEach = () => {
|
|
56
|
+
window.playAfterEach = true;
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.afterEach = afterEach;
|
|
60
|
+
exports.decorators = decorators;
|
|
61
|
+
exports.parameters = parameters;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappa/plugin-storybook",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -63,19 +63,19 @@
|
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@swc/core": "^1.15.18",
|
|
65
65
|
"chalk": "^5.6.2",
|
|
66
|
-
"@cappa/
|
|
67
|
-
"@cappa/
|
|
66
|
+
"@cappa/core": "0.9.0",
|
|
67
|
+
"@cappa/logger": "0.0.11"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@arethetypeswrong/cli": "0.18.2",
|
|
71
|
-
"@types/node": "25.
|
|
72
|
-
"@vitest/coverage-v8": "4.1.
|
|
73
|
-
"@vitest/ui": "4.1.
|
|
71
|
+
"@types/node": "25.6.0",
|
|
72
|
+
"@vitest/coverage-v8": "4.1.4",
|
|
73
|
+
"@vitest/ui": "4.1.4",
|
|
74
74
|
"playwright-core": "^1.58.2",
|
|
75
75
|
"storybook": "^10.3.1",
|
|
76
|
-
"tsdown": "0.21.
|
|
76
|
+
"tsdown": "0.21.8",
|
|
77
77
|
"typescript": "6.0.2",
|
|
78
|
-
"vitest": "4.1.
|
|
78
|
+
"vitest": "4.1.4"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"test": "vitest",
|