@aurelia/storybook 1.0.0 → 1.0.2

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.
Files changed (36) hide show
  1. package/README.md +29 -33
  2. package/__tests__/render.test.ts +1 -1
  3. package/apps/hello-world/.storybook/main.ts +32 -12
  4. package/apps/hello-world/package-lock.json +7448 -0
  5. package/apps/hello-world/package.json +10 -10
  6. package/apps/hello-world/src/stories/hello-world.stories.ts +11 -10
  7. package/apps/hello-world-webpack/.storybook/main.ts +1 -4
  8. package/apps/hello-world-webpack/package-lock.json +380 -3515
  9. package/apps/hello-world-webpack/package.json +9 -10
  10. package/apps/hello-world-webpack/src/hello-world.html +6 -0
  11. package/apps/hello-world-webpack/src/hello-world.ts +17 -0
  12. package/apps/hello-world-webpack/src/my-app.stories.ts +10 -7
  13. package/apps/hello-world-webpack/src/stories/hello-world.stories.ts +54 -0
  14. package/dist/index.js +65 -38
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +62 -39
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/preset.js +15 -1
  19. package/dist/preset.js.map +1 -1
  20. package/dist/preset.mjs +15 -1
  21. package/dist/preset.mjs.map +1 -1
  22. package/dist/preview/render.js +41 -40
  23. package/dist/preview/render.js.map +1 -1
  24. package/dist/preview/render.mjs +41 -40
  25. package/dist/preview/render.mjs.map +1 -1
  26. package/dist/preview.js +81 -39
  27. package/dist/preview.js.map +1 -1
  28. package/dist/preview.mjs +81 -40
  29. package/dist/preview.mjs.map +1 -1
  30. package/package.json +6 -10
  31. package/rollup.config.mjs +6 -4
  32. package/src/index.ts +28 -0
  33. package/src/preset.ts +19 -1
  34. package/src/preview/render.ts +51 -49
  35. package/src/preview/types.ts +1 -1
  36. package/src/preview.ts +1 -50
package/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  > **Note:** Storybook support is currently in an early stage, and there may be bugs, issues, or unsupported features in this plugin. The intention is to make this plugin more production-ready when Aurelia 2 reaches stable release.
4
4
 
5
- This package provides an integration between Aurelia 2 and Storybook 8 using Vite or Webpack. It lets you write and render Aurelia 2 components as Storybook stories with full support for Storybook controls, actions, and interactive testing.
5
+ This package provides an integration between Aurelia 2 and Storybook 9 using Vite or Webpack. It lets you write and render Aurelia 2 components as Storybook stories with full support for Storybook controls, actions, and interactive testing.
6
6
 
7
7
  ## Features
8
8
 
9
9
  - **Vite & Webpack Support**: Works with both Vite (via `@storybook/builder-vite`) and Webpack 5 (via `@storybook/builder-webpack5`).
10
10
  - **Aurelia Enhancement**: Renders Aurelia 2 components using Aurelia's `enhance()` API.
11
- - **Storybook 8 Compatibility**: Fully compatible with Storybook 8's new rendering API.
11
+ - **Storybook 9 Compatibility**: Fully compatible with Storybook 9's new rendering API.
12
12
  - **Arg & Action Support**: Use story args and actions as you would with any Storybook story.
13
13
 
14
14
  ## Installation
@@ -22,7 +22,13 @@ npm install --save-dev @aurelia/storybook
22
22
  Also, make sure to have the required dependencies installed in your project:
23
23
 
24
24
  ```bash
25
- npm install --save-dev @storybook/addons @storybook/core-events @storybook/builder-vite @storybook/core-common @storybook/preview-api @storybook/types
25
+ npm install --save-dev storybook @storybook/builder-vite
26
+ ```
27
+
28
+ For testing functionality, you may also want to install:
29
+
30
+ ```bash
31
+ npm install --save-dev @storybook/test @storybook/addon-actions
26
32
  ```
27
33
 
28
34
  > **Tip:** Check your existing Aurelia 2 app for already installed versions. The peer dependencies are expected to be compatible with Aurelia 2 beta releases (see `package.json` for version details).
@@ -43,16 +49,14 @@ To integrate Aurelia 2 with your Storybook instance, follow these steps:
43
49
  Create or update your `.storybook/main.ts` file with the following contents:
44
50
 
45
51
  ```typescript
46
- import type { StorybookConfig } from '@storybook/core-common';
47
- import { mergeConfig } from 'vite';
52
+ import type { StorybookConfig } from 'storybook/internal/types';
53
+ import { mergeConfig, type InlineConfig } from 'vite';
48
54
 
49
- const config: StorybookConfig & { viteFinal?: (config: any, options: any) => any } = {
55
+ const config: StorybookConfig & { viteFinal?: (config: InlineConfig, options: { configType: string }) => InlineConfig | Promise<InlineConfig> } = {
50
56
  stories: ['../src/stories/**/*.stories.@(ts|tsx|js|jsx|mdx)'],
51
57
  addons: [
52
- // Addons like:
53
- // '@storybook/addon-links',
54
- // '@storybook/addon-essentials',
55
- // '@storybook/addon-interactions'
58
+ // Additional addons (essentials are now built into Storybook 9 core):
59
+ '@storybook/addon-links'
56
60
  ],
57
61
  framework: {
58
62
  name: '@aurelia/storybook',
@@ -73,7 +77,7 @@ To integrate Aurelia 2 with your Storybook instance, follow these steps:
73
77
  },
74
78
  };
75
79
 
76
- export default config as any;
80
+ export default config;
77
81
  ```
78
82
 
79
83
  - **.storybook/preview.ts**
@@ -85,21 +89,19 @@ To integrate Aurelia 2 with your Storybook instance, follow these steps:
85
89
  export { render, renderToCanvas } from '@aurelia/storybook';
86
90
  ```
87
91
 
88
- > **Note:** Addons such as `@storybook/addon-links`, `@storybook/addon-essentials`, and `@storybook/addon-interactions` are supported by installing them and adding them to the `addons` array in your configuration.
92
+ > **Note:** Essential features like actions, controls, backgrounds, and viewport are now built into Storybook 9 core and don't need to be installed separately. However, if you need to use the `action()` function in your stories (for programmatic actions), you may still need to install `@storybook/addon-actions`. Additional addons like `@storybook/addon-links` can be installed and added to the `addons` array in your configuration.
89
93
 
90
94
  ### Using with Webpack
91
95
 
92
96
  If you prefer to use Webpack instead of Vite, update your `.storybook/main.ts` configuration:
93
97
 
94
98
  ```typescript
95
- import type { StorybookConfig } from '@storybook/core-common';
99
+ import type { StorybookConfig } from 'storybook/internal/types';
96
100
 
97
101
  const config: StorybookConfig = {
98
102
  stories: ['../src/**/*.stories.@(ts|tsx|js|jsx|mdx)'],
99
103
  addons: [
100
- '@storybook/addon-webpack5-compiler-swc',
101
- '@storybook/addon-links',
102
- '@storybook/addon-essentials'
104
+ '@storybook/addon-links'
103
105
  ],
104
106
  framework: {
105
107
  name: '@aurelia/storybook',
@@ -132,14 +134,14 @@ Aurelia 2 stories are written similarly to standard Storybook stories, with a fe
132
134
 
133
135
  ```typescript
134
136
  import { HelloWorld } from '../hello-world';
135
- import { action } from '@storybook/addon-actions';
136
- import { userEvent, within } from '@storybook/testing-library';
137
+ import { fn } from '@storybook/test';
138
+ import { userEvent, within } from '@storybook/test';
137
139
 
138
140
  const meta = {
139
141
  title: 'Example/HelloWorld',
140
142
  component: HelloWorld,
141
- render: (args) => ({
142
- template: <hello-world message.bind="message" on-increment.bind="onIncrement"></hello-world>,
143
+ render: () => ({
144
+ template: `<hello-world message.bind="message" on-increment.bind="onIncrement"></hello-world>`,
143
145
  }),
144
146
  argTypes: {
145
147
  message: { control: 'text' },
@@ -152,16 +154,16 @@ export default meta;
152
154
  export const DefaultHelloWorld = {
153
155
  args: {
154
156
  message: "Hello from Storybook!",
155
- onIncrement: action('increment')
157
+ onIncrement: fn()
156
158
  }
157
159
  };
158
160
 
159
161
  export const InteractiveHelloWorld = {
160
162
  args: {
161
163
  message: "Try clicking the button!",
162
- onIncrement: action('increment')
164
+ onIncrement: fn()
163
165
  },
164
- play: async ({ canvasElement }) => {
166
+ play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
165
167
  const canvas = within(canvasElement);
166
168
  const button = canvas.getByRole('button');
167
169
  // Simulate three button clicks
@@ -173,13 +175,13 @@ export const InteractiveHelloWorld = {
173
175
 
174
176
  export const NoArgs = {
175
177
  render: () => ({
176
- template: <hello-world></hello-world>
178
+ template: `<hello-world></hello-world>`
177
179
  })
178
180
  };
179
181
 
180
182
  export const WithCustomTemplate = {
181
- render: (args) => ({
182
- template: <hello-world message.bind="message">Click me!</hello-world>
183
+ render: () => ({
184
+ template: `<hello-world message.bind="message">Click me!</hello-world>`
183
185
  }),
184
186
  args: {
185
187
  message: "This is a custom message"
@@ -214,13 +216,7 @@ If you wish to contribute or modify the integration:
214
216
  npm run watch
215
217
  ```
216
218
 
217
- 3. **Link the package** in your Aurelia project:
218
-
219
- ```bash
220
- npm link @aurelia/storybook
221
- ```
222
-
223
- 4. **Run Storybook** in your local Aurelia application to see the integration in action.
219
+ 3. **Run Storybook** in your local application to see the integration in action.
224
220
 
225
221
  ## Contributing
226
222
 
@@ -1,4 +1,4 @@
1
- import { STORY_CHANGED } from '@storybook/core-events';
1
+ import { STORY_CHANGED } from 'storybook/internal/core-events';
2
2
  import {
3
3
  render,
4
4
  renderToCanvas,
@@ -1,12 +1,10 @@
1
- import type { StorybookConfig } from '@storybook/core-common';
2
- import { mergeConfig } from 'vite';
1
+ import type { StorybookConfig } from 'storybook/internal/types';
2
+ import { mergeConfig, type InlineConfig } from 'vite';
3
3
 
4
- const config: StorybookConfig & { viteFinal?: (config: any, options: any) => any } = {
4
+ const config: StorybookConfig & { viteFinal?: (config: InlineConfig, options: { configType: string }) => InlineConfig | Promise<InlineConfig> } = {
5
5
  stories: ['../src/stories/**/*.stories.@(ts|tsx|js|jsx|mdx)'],
6
6
  addons: [
7
- '@storybook/addon-links',
8
- '@storybook/addon-essentials',
9
- '@storybook/addon-interactions'
7
+ '@storybook/addon-links'
10
8
  ],
11
9
  framework: {
12
10
  name: '@aurelia/storybook',
@@ -16,15 +14,37 @@ const config: StorybookConfig & { viteFinal?: (config: any, options: any) => any
16
14
  builder: '@storybook/builder-vite',
17
15
  },
18
16
  viteFinal: async (viteConfig) => {
19
- viteConfig.optimizeDeps = viteConfig.optimizeDeps || {};
20
- viteConfig.optimizeDeps.exclude = viteConfig.optimizeDeps.exclude || [];
21
- if (!viteConfig.optimizeDeps.exclude.includes('@aurelia/runtime-html')) {
22
- viteConfig.optimizeDeps.exclude.push('@aurelia/runtime-html');
17
+ // Initialize optimizeDeps and exclude array
18
+ if (!viteConfig.optimizeDeps) {
19
+ viteConfig.optimizeDeps = {};
23
20
  }
21
+ if (!viteConfig.optimizeDeps.exclude) {
22
+ viteConfig.optimizeDeps.exclude = [];
23
+ }
24
+
25
+ // Exclude Aurelia dependencies from pre-bundling, but allow React for Storybook
26
+ const excludeList = [
27
+ '@aurelia/runtime-html'
28
+ ];
29
+
30
+ excludeList.forEach(dep => {
31
+ if (viteConfig.optimizeDeps?.exclude && !viteConfig.optimizeDeps.exclude.includes(dep)) {
32
+ viteConfig.optimizeDeps.exclude.push(dep);
33
+ }
34
+ });
35
+
24
36
  return mergeConfig(viteConfig, {
25
- // ...any additional Vite configuration
37
+ define: {
38
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
39
+ },
40
+ // Allow React to be bundled for Storybook's theming system
41
+ resolve: {
42
+ alias: {
43
+ // Ensure React is properly resolved
44
+ }
45
+ }
26
46
  });
27
47
  },
28
48
  };
29
49
 
30
- export default config as any;
50
+ export default config;