storybook-framework-qwik 0.2.4 → 0.3.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/dist/addArgsHelpers.d.ts +10 -0
- package/dist/addArgsHelpers.js +41 -0
- package/dist/component-to-jsx.d.ts +1 -1
- package/dist/docs/qwik-docgen.js +1 -1
- package/dist/preview.d.ts +2 -1
- package/dist/preview.js +19 -2
- package/package.json +10 -10
- package/template/cli/button.stories.ts +3 -11
- package/template/cli/button.tsx +2 -2
- package/template/cli/header.stories.ts +6 -16
- package/template/cli/header.tsx +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Renderer, ArgsEnhancer } from "@storybook/types";
|
|
2
|
+
/**
|
|
3
|
+
* Automatically add action args for argTypes whose name
|
|
4
|
+
* matches a regex, such as `^on.*` for react-style `onClick` etc.
|
|
5
|
+
*/
|
|
6
|
+
export declare const inferActionsFromArgTypesRegex: ArgsEnhancer<Renderer>;
|
|
7
|
+
/**
|
|
8
|
+
* Add action args for list of strings.
|
|
9
|
+
*/
|
|
10
|
+
export declare const addActionsFromArgTypes: ArgsEnhancer<Renderer>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// This file is entirely copied from @storybook/addon-actions (changing the action import)
|
|
2
|
+
import { action } from "@storybook/addon-actions";
|
|
3
|
+
// interface ActionsParameter {
|
|
4
|
+
// disable?: boolean;
|
|
5
|
+
// argTypesRegex?: RegExp;
|
|
6
|
+
// }
|
|
7
|
+
const isInInitialArgs = (name, initialArgs) => typeof initialArgs[name] === "undefined" && !(name in initialArgs);
|
|
8
|
+
/**
|
|
9
|
+
* Automatically add action args for argTypes whose name
|
|
10
|
+
* matches a regex, such as `^on.*` for react-style `onClick` etc.
|
|
11
|
+
*/
|
|
12
|
+
export const inferActionsFromArgTypesRegex = (context) => {
|
|
13
|
+
const { initialArgs, argTypes, parameters: { actions }, } = context;
|
|
14
|
+
if (!actions || actions.disable || !actions.argTypesRegex || !argTypes) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
const argTypesRegex = new RegExp(actions.argTypesRegex);
|
|
18
|
+
const argTypesMatchingRegex = Object.entries(argTypes).filter(([name]) => !!argTypesRegex.test(name));
|
|
19
|
+
return argTypesMatchingRegex.reduce((acc, [name, argType]) => {
|
|
20
|
+
if (isInInitialArgs(name, initialArgs)) {
|
|
21
|
+
acc[name] = action(name);
|
|
22
|
+
}
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Add action args for list of strings.
|
|
28
|
+
*/
|
|
29
|
+
export const addActionsFromArgTypes = (context) => {
|
|
30
|
+
const { initialArgs, argTypes, parameters: { actions }, } = context;
|
|
31
|
+
if (actions?.disable || !argTypes) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
const argTypesWithAction = Object.entries(argTypes).filter(([name, argType]) => !!argType["action"]);
|
|
35
|
+
return argTypesWithAction.reduce((acc, [name, argType]) => {
|
|
36
|
+
if (isInInitialArgs(name, initialArgs)) {
|
|
37
|
+
acc[name] = action(typeof argType["action"] === "string" ? argType["action"] : name);
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
}, {});
|
|
41
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { FunctionComponent } from "@builder.io/qwik";
|
|
2
2
|
import { Args } from "./types.js";
|
|
3
|
-
export declare const componentToJSX: (Component: FunctionComponent, args: Args) => import("@builder.io/qwik
|
|
3
|
+
export declare const componentToJSX: (Component: FunctionComponent, args: Args) => import("@builder.io/qwik").JSXOutput;
|
package/dist/docs/qwik-docgen.js
CHANGED
|
@@ -17,7 +17,7 @@ export function qwikDocgen() {
|
|
|
17
17
|
skipPropsWithName: ["key", "q:slot"],
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
|
-
const s = new MagicString
|
|
20
|
+
const s = new MagicString(src);
|
|
21
21
|
s.append(`window.__STORYBOOK_COMPONENT_DOC__ ??= new Map();`);
|
|
22
22
|
componentDocs.forEach((componentDoc) => s.append(`window.__STORYBOOK_COMPONENT_DOC__.set("${toKebabCase(componentDoc.displayName)}", ${JSON.stringify(componentDoc)});`));
|
|
23
23
|
return {
|
package/dist/preview.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ArgsStoryFn, RenderContext } from "@storybook/types";
|
|
1
|
+
import { ArgsEnhancer, ArgsStoryFn, RenderContext } from "@storybook/types";
|
|
2
2
|
import { QwikRenderer } from "./types.js";
|
|
3
3
|
export { parameters, argTypesEnhancers } from "./docs/config.js";
|
|
4
4
|
export declare const render: ArgsStoryFn<QwikRenderer<unknown>>;
|
|
5
5
|
export declare function renderToCanvas<T>({ storyFn, showMain }: RenderContext<QwikRenderer<T>>, canvasElement: QwikRenderer<T>["canvasElement"]): Promise<void>;
|
|
6
|
+
export declare const argsEnhancers: ArgsEnhancer[];
|
package/dist/preview.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { render as renderQwik } from "@builder.io/qwik";
|
|
1
|
+
import { inlinedQrl, render as renderQwik } from "@builder.io/qwik";
|
|
2
2
|
import { componentToJSX } from "./component-to-jsx.js";
|
|
3
|
+
import { addActionsFromArgTypes, inferActionsFromArgTypesRegex, } from "./addArgsHelpers.js";
|
|
3
4
|
export { parameters, argTypesEnhancers } from "./docs/config.js";
|
|
4
5
|
// returns the Qwik component as a JSX element (</MyComponent>)
|
|
5
6
|
// If a story has a custom renderer, it will replace this function.
|
|
@@ -12,9 +13,9 @@ export const render = (args, context) => {
|
|
|
12
13
|
};
|
|
13
14
|
export async function renderToCanvas({ storyFn, showMain }, canvasElement) {
|
|
14
15
|
const container = document.createElement("div");
|
|
15
|
-
await renderQwik(container, storyFn());
|
|
16
16
|
canvasElement.childNodes.forEach((c) => c.remove());
|
|
17
17
|
canvasElement.append(container);
|
|
18
|
+
await renderQwik(container, storyFn());
|
|
18
19
|
showMain();
|
|
19
20
|
}
|
|
20
21
|
// I don't know how to do HMR stuff correctly, and Vite seems to keep referencing old files when you make a change.
|
|
@@ -25,3 +26,19 @@ if (viteHotMeta) {
|
|
|
25
26
|
document.location.reload();
|
|
26
27
|
});
|
|
27
28
|
}
|
|
29
|
+
const actionsArgsEnhancers = [
|
|
30
|
+
addActionsFromArgTypes,
|
|
31
|
+
inferActionsFromArgTypesRegex,
|
|
32
|
+
];
|
|
33
|
+
export const argsEnhancers =
|
|
34
|
+
// use the argsEnhancers from addon-actions, then wrap the actions in Qwik's inlinedQrl function so things work.
|
|
35
|
+
actionsArgsEnhancers.map((actionsEnhancer) => {
|
|
36
|
+
return ((context) => {
|
|
37
|
+
const argsWithActions = actionsEnhancer(context);
|
|
38
|
+
let finalArgs = {};
|
|
39
|
+
Object.keys(argsWithActions).forEach((key) => {
|
|
40
|
+
finalArgs[key] = inlinedQrl(argsWithActions[key], key);
|
|
41
|
+
});
|
|
42
|
+
return finalArgs;
|
|
43
|
+
});
|
|
44
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-framework-qwik",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Storybook for Qwik: View Qwik components in isolation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -83,24 +83,24 @@
|
|
|
83
83
|
"fmt.check": "prettier --check ."
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@storybook/builder-vite": "
|
|
87
|
-
"@storybook/docs-tools": "
|
|
88
|
-
"magic-string": "^0.30.
|
|
86
|
+
"@storybook/builder-vite": "^7.6.16",
|
|
87
|
+
"@storybook/docs-tools": "^7.6.16",
|
|
88
|
+
"magic-string": "^0.30.7",
|
|
89
89
|
"react-docgen-typescript": "^2.2.2"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"@builder.io/qwik": ">=0.15.2"
|
|
93
93
|
},
|
|
94
94
|
"optionalDependencies": {
|
|
95
|
-
"@builder.io/qwik-city": "
|
|
95
|
+
"@builder.io/qwik-city": "1.4.1"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
|
-
"@storybook/types": "
|
|
98
|
+
"@storybook/types": "^7.6.16",
|
|
99
99
|
"@suin/semantic-release-yarn": "1.1.0",
|
|
100
|
-
"@types/node": "^18.
|
|
101
|
-
"semantic-release": "^
|
|
102
|
-
"typescript": "~5.
|
|
103
|
-
"vite": "^
|
|
100
|
+
"@types/node": "^18.19.17",
|
|
101
|
+
"semantic-release": "^22.0.12",
|
|
102
|
+
"typescript": "~5.3.3",
|
|
103
|
+
"vite": "^5.1.3"
|
|
104
104
|
},
|
|
105
105
|
"engines": {
|
|
106
106
|
"node": "^14.18 || >=16"
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import { action } from "@storybook/addon-actions";
|
|
2
|
-
import { $ } from "@builder.io/qwik";
|
|
3
1
|
import type { Meta, StoryObj } from "storybook-framework-qwik";
|
|
4
|
-
import type { ButtonProps
|
|
2
|
+
import type { ButtonProps } from "./button";
|
|
5
3
|
import { Button } from "./button";
|
|
6
4
|
|
|
7
5
|
const meta = {
|
|
8
6
|
title: "Button",
|
|
9
|
-
args: {
|
|
10
|
-
// automatic actions are not yet supported.
|
|
11
|
-
// See https://github.com/literalpie/storybook-framework-qwik/issues/16
|
|
12
|
-
// For now, use the legacy addon-actions API wrapped in a $ to make your own QRL action.
|
|
13
|
-
onClick$: $<onClickEvent>((event, element) => {
|
|
14
|
-
action("click action")({ event, element });
|
|
15
|
-
}),
|
|
16
|
-
},
|
|
7
|
+
args: { },
|
|
17
8
|
argTypes: {
|
|
9
|
+
onClick$: { action: 'onClick'},
|
|
18
10
|
backgroundColor: { control: "color" },
|
|
19
11
|
},
|
|
20
12
|
component: Button,
|
package/template/cli/button.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PropFunction
|
|
1
|
+
import type { PropFunction } from "@builder.io/qwik";
|
|
2
2
|
import { component$, useStylesScoped$ } from "@builder.io/qwik";
|
|
3
3
|
import buttonStyles from "./button.css?inline";
|
|
4
4
|
|
|
@@ -37,7 +37,7 @@ export const getClassForSize = (size: "small" | "medium" | "large") => {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export type onClickEvent = (
|
|
40
|
-
event:
|
|
40
|
+
event: MouseEvent,
|
|
41
41
|
element: Element
|
|
42
42
|
) => void;
|
|
43
43
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "storybook-framework-qwik";
|
|
2
2
|
import type { HeaderProps } from "./header";
|
|
3
3
|
import { Header } from "./header";
|
|
4
|
-
import { $ } from "@builder.io/qwik";
|
|
5
|
-
import { action } from "@storybook/addon-actions";
|
|
6
4
|
|
|
7
5
|
const meta = {
|
|
8
6
|
title: "Example/Header",
|
|
@@ -13,20 +11,12 @@ const meta = {
|
|
|
13
11
|
// More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout
|
|
14
12
|
layout: "fullscreen",
|
|
15
13
|
},
|
|
16
|
-
args: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}),
|
|
23
|
-
onLogin$: $<() => void>(() => {
|
|
24
|
-
action("Login Action")();
|
|
25
|
-
}),
|
|
26
|
-
onLogout$: $<() => void>(() => {
|
|
27
|
-
action("Logout Action")();
|
|
28
|
-
}),
|
|
29
|
-
},
|
|
14
|
+
args: { },
|
|
15
|
+
argTypes: {
|
|
16
|
+
onCreateAccount$: { action: 'onCreateAccount' },
|
|
17
|
+
onLogin$: { action: 'onLogin' },
|
|
18
|
+
onLogout$: { action: 'onLogout' },
|
|
19
|
+
}
|
|
30
20
|
} satisfies Meta<HeaderProps>;
|
|
31
21
|
|
|
32
22
|
export default meta;
|
package/template/cli/header.tsx
CHANGED
|
@@ -26,7 +26,7 @@ export const Header = component$(
|
|
|
26
26
|
viewBox="0 0 32 32"
|
|
27
27
|
xmlns="http://www.w3.org/2000/svg"
|
|
28
28
|
>
|
|
29
|
-
<g fill="none"
|
|
29
|
+
<g fill="none" fill-rule="evenodd">
|
|
30
30
|
<path
|
|
31
31
|
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
32
32
|
fill="#FFF"
|