@cappa/plugin-storybook 0.8.2 → 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.
@@ -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.js")];
319
+ const previewAnnotations = [require.resolve("./preview.cjs")];
320
320
  //#endregion
321
321
  exports.cappaPluginStorybook = cappaPluginStorybook;
322
322
  exports.previewAnnotations = previewAnnotations;
@@ -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.js", import.meta.url))];
319
+ const previewAnnotations = [fileURLToPath(new URL("./preview.mjs", import.meta.url))];
320
320
  //#endregion
321
321
  export { cappaPluginStorybook, previewAnnotations };
@@ -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;
@@ -0,0 +1,6 @@
1
+ //#region src/storybook/addon/preview.d.ts
2
+ declare const decorators: ((...args: any) => any)[];
3
+ declare const parameters: {};
4
+ declare const afterEach: () => void;
5
+ //#endregion
6
+ export { afterEach, decorators, parameters };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappa/plugin-storybook",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Storybook plugin for Cappa - takes screenshots of Storybook stories",
5
5
  "publishConfig": {
6
6
  "access": "public"