@aurelia/storybook 2.1.0 → 2.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +195 -12
  3. package/dist/index.d.ts +25 -0
  4. package/dist/index.js +101 -27
  5. package/dist/index.js.map +1 -1
  6. package/dist/preset.d.ts +21 -0
  7. package/dist/preset.js +74 -20
  8. package/dist/preset.js.map +1 -1
  9. package/dist/preview/helpers.d.ts +2 -0
  10. package/dist/preview/helpers.js +6 -0
  11. package/dist/preview/helpers.js.map +1 -0
  12. package/dist/preview/render.d.ts +7 -0
  13. package/dist/preview/render.js +99 -28
  14. package/dist/preview/render.js.map +1 -1
  15. package/dist/preview/storybook-types-runtime.d.ts +1 -0
  16. package/dist/preview/storybook-types-runtime.js +5 -0
  17. package/dist/preview/storybook-types-runtime.js.map +1 -0
  18. package/dist/preview/storybook-types.d.ts +27 -0
  19. package/dist/preview/types-runtime.d.ts +1 -0
  20. package/dist/preview/types-runtime.js +5 -0
  21. package/dist/preview/types-runtime.js.map +1 -0
  22. package/dist/preview/types.d.ts +44 -0
  23. package/dist/preview.d.ts +3 -0
  24. package/dist/preview.js +104 -29
  25. package/dist/preview.js.map +1 -1
  26. package/dist/webpack.d.ts +10 -0
  27. package/dist/webpack.js +19 -1
  28. package/dist/webpack.js.map +1 -1
  29. package/package.json +75 -15
  30. package/preset.js +2 -1
  31. package/CONTINUITY.md +0 -22
  32. package/__tests__/preset.test.ts +0 -49
  33. package/__tests__/preview.test.ts +0 -139
  34. package/__tests__/render.test.ts +0 -187
  35. package/__tests__/webpack.test.ts +0 -21
  36. package/apps/hello-world/.storybook/main.ts +0 -49
  37. package/apps/hello-world/.storybook/preview.ts +0 -1
  38. package/apps/hello-world/.stylelintrc.json +0 -5
  39. package/apps/hello-world/README.md +0 -28
  40. package/apps/hello-world/eslint.config.mjs +0 -25
  41. package/apps/hello-world/favicon.ico +0 -0
  42. package/apps/hello-world/index.html +0 -17
  43. package/apps/hello-world/package-lock.json +0 -9307
  44. package/apps/hello-world/package.json +0 -55
  45. package/apps/hello-world/src/components/feedback-form.html +0 -111
  46. package/apps/hello-world/src/components/feedback-form.ts +0 -45
  47. package/apps/hello-world/src/components/notification-center.html +0 -119
  48. package/apps/hello-world/src/components/notification-center.ts +0 -27
  49. package/apps/hello-world/src/components/stat-card.html +0 -107
  50. package/apps/hello-world/src/components/stat-card.ts +0 -33
  51. package/apps/hello-world/src/components/weather-widget.html +0 -89
  52. package/apps/hello-world/src/components/weather-widget.ts +0 -30
  53. package/apps/hello-world/src/hello-world.html +0 -48
  54. package/apps/hello-world/src/hello-world.ts +0 -17
  55. package/apps/hello-world/src/main.ts +0 -6
  56. package/apps/hello-world/src/my-app.html +0 -1
  57. package/apps/hello-world/src/my-app.ts +0 -3
  58. package/apps/hello-world/src/resource.d.ts +0 -15
  59. package/apps/hello-world/src/services/weather-service.ts +0 -15
  60. package/apps/hello-world/src/stories/feedback-form.stories.ts +0 -52
  61. package/apps/hello-world/src/stories/hello-world.stories.ts +0 -53
  62. package/apps/hello-world/src/stories/notification-center.stories.ts +0 -81
  63. package/apps/hello-world/src/stories/stat-card.stories.ts +0 -65
  64. package/apps/hello-world/src/stories/weather-widget.stories.ts +0 -57
  65. package/apps/hello-world/test/my-app.spec.ts +0 -15
  66. package/apps/hello-world/test/setup.ts +0 -29
  67. package/apps/hello-world/tsconfig.json +0 -19
  68. package/apps/hello-world/tsconfig.vitest.json +0 -11
  69. package/apps/hello-world/vite.config.ts +0 -17
  70. package/apps/hello-world/vitest.config.ts +0 -15
  71. package/apps/hello-world-webpack/.env.development +0 -0
  72. package/apps/hello-world-webpack/.storybook/main.ts +0 -14
  73. package/apps/hello-world-webpack/.storybook/preview.ts +0 -3
  74. package/apps/hello-world-webpack/.stylelintrc.json +0 -5
  75. package/apps/hello-world-webpack/README.md +0 -29
  76. package/apps/hello-world-webpack/eslint.config.mjs +0 -25
  77. package/apps/hello-world-webpack/favicon.ico +0 -0
  78. package/apps/hello-world-webpack/index.html +0 -15
  79. package/apps/hello-world-webpack/package-lock.json +0 -9853
  80. package/apps/hello-world-webpack/package.json +0 -51
  81. package/apps/hello-world-webpack/src/components/feedback-form.html +0 -111
  82. package/apps/hello-world-webpack/src/components/feedback-form.ts +0 -45
  83. package/apps/hello-world-webpack/src/components/notification-center.html +0 -119
  84. package/apps/hello-world-webpack/src/components/notification-center.ts +0 -27
  85. package/apps/hello-world-webpack/src/components/stat-card.html +0 -107
  86. package/apps/hello-world-webpack/src/components/stat-card.ts +0 -33
  87. package/apps/hello-world-webpack/src/components/weather-widget.html +0 -89
  88. package/apps/hello-world-webpack/src/components/weather-widget.ts +0 -30
  89. package/apps/hello-world-webpack/src/hello-world.html +0 -48
  90. package/apps/hello-world-webpack/src/hello-world.ts +0 -17
  91. package/apps/hello-world-webpack/src/main.ts +0 -6
  92. package/apps/hello-world-webpack/src/my-app.css +0 -3
  93. package/apps/hello-world-webpack/src/my-app.html +0 -1
  94. package/apps/hello-world-webpack/src/my-app.stories.ts +0 -15
  95. package/apps/hello-world-webpack/src/my-app.ts +0 -3
  96. package/apps/hello-world-webpack/src/resource.d.ts +0 -13
  97. package/apps/hello-world-webpack/src/services/weather-service.ts +0 -15
  98. package/apps/hello-world-webpack/src/stories/feedback-form.stories.ts +0 -52
  99. package/apps/hello-world-webpack/src/stories/hello-world.stories.ts +0 -53
  100. package/apps/hello-world-webpack/src/stories/notification-center.stories.ts +0 -81
  101. package/apps/hello-world-webpack/src/stories/stat-card.stories.ts +0 -65
  102. package/apps/hello-world-webpack/src/stories/weather-widget.stories.ts +0 -57
  103. package/apps/hello-world-webpack/tsconfig.json +0 -18
  104. package/apps/hello-world-webpack/webpack.config.js +0 -111
  105. package/dist/preview/types.js +0 -2
  106. package/dist/preview/types.js.map +0 -1
  107. package/jest.config.js +0 -9
  108. package/rollup.config.mjs +0 -50
  109. package/src/index.ts +0 -32
  110. package/src/preset.ts +0 -49
  111. package/src/preview/render.ts +0 -175
  112. package/src/preview/types.ts +0 -7
  113. package/src/preview.ts +0 -1
  114. package/src/webpack.ts +0 -21
  115. package/tsconfig.build.json +0 -5
  116. package/tsconfig.json +0 -15
@@ -1,187 +0,0 @@
1
- import { STORY_CHANGED } from 'storybook/internal/core-events';
2
- import {
3
- render,
4
- renderToCanvas,
5
- bootstrapAureliaApp,
6
- createComponentTemplate,
7
- } from '../src/preview/render';
8
-
9
- // Add this at the very top of the file, before any imports.
10
- jest.mock('aurelia', () => {
11
- const actual = jest.requireActual('aurelia');
12
- return {
13
- ...actual,
14
- CustomElement: {
15
- ...actual.CustomElement,
16
- getDefinition: jest.fn().mockReturnValue({
17
- name: 'dummy-comp',
18
- bindables: { prop: { attribute: 'prop', name: 'prop' } },
19
- }),
20
- },
21
- };
22
- });
23
-
24
- describe('render', () => {
25
- it('throws an error when no component is provided', () => {
26
- expect(() =>
27
- render({}, { id: 'story-1', component: undefined as any } as any)
28
- ).toThrowError(
29
- 'Unable to render story story-1 as the component annotation is missing from the default export'
30
- );
31
- });
32
-
33
- it('returns the expected object when a component is provided', () => {
34
- const DummyComponent = () => {};
35
- const args = { foo: 'bar' };
36
- const result = render(args, { id: 'story-1', component: DummyComponent as any } as any);
37
- expect(result).toEqual({ Component: DummyComponent, props: args, template: '' });
38
- });
39
- });
40
-
41
- describe('renderToCanvas', () => {
42
- let canvas: HTMLElement;
43
- let dummyChannel: { on: jest.Mock; off: jest.Mock };
44
- const DummyComponent = class {};
45
-
46
- beforeEach(() => {
47
- canvas = document.createElement('div');
48
- dummyChannel = { on: jest.fn(), off: jest.fn() } as any;
49
- });
50
-
51
- it('calls showError when the story function returns a falsy value', async () => {
52
- const storyFn = jest.fn(() => null) as any;
53
- const showError = jest.fn() as any;
54
- const showMain = jest.fn() as any;
55
- const context = {
56
- storyFn,
57
- title: 'Test Title',
58
- name: 'Test Story',
59
- showMain,
60
- showError,
61
- storyContext: {
62
- parameters: {},
63
- component: DummyComponent as any,
64
- args: {},
65
- viewMode: 'story',
66
- channel: dummyChannel,
67
- },
68
- forceRemount: false,
69
- } as any;
70
-
71
- const cleanup = await renderToCanvas(context, canvas);
72
- expect(showError).toHaveBeenCalled();
73
- expect(typeof cleanup).toBe('function');
74
- });
75
-
76
- it('bootstraps an Aurelia app when none exists or forceRemount is true', async () => {
77
- const fakeAurelia = {
78
- start: jest.fn().mockResolvedValue(undefined),
79
- stop: jest.fn().mockResolvedValue(undefined),
80
- root: { controller: { viewModel: {} } },
81
- } as any;
82
- const story = { template: '<div></div>', props: { test: 'value' } } as any;
83
- const storyFn = jest.fn(() => story) as any;
84
- const showError = jest.fn() as any;
85
- const showMain = jest.fn() as any;
86
-
87
- // Spy on bootstrapAureliaApp to simulate app creation.
88
- const bootstrapSpy = jest
89
- .spyOn(require('../src/preview/render'), 'bootstrapAureliaApp')
90
- .mockReturnValue(fakeAurelia);
91
-
92
- const context = {
93
- storyFn,
94
- title: 'Test Title',
95
- name: 'Test Story',
96
- showMain,
97
- showError,
98
- storyContext: {
99
- parameters: { args: { param: 'foo' } },
100
- component: DummyComponent as any,
101
- args: { test: 'bar' },
102
- viewMode: 'story',
103
- channel: dummyChannel,
104
- },
105
- forceRemount: false,
106
- } as any;
107
-
108
- const cleanup = await renderToCanvas(context, canvas, bootstrapAureliaApp);
109
- expect(showError).not.toHaveBeenCalled();
110
- expect(showMain).toHaveBeenCalled();
111
- expect(bootstrapSpy).toHaveBeenCalled();
112
-
113
- // Simulate cleanup (which should remove the STORY_CHANGED listener)
114
- await cleanup();
115
- expect(dummyChannel.off).toHaveBeenCalledWith(
116
- STORY_CHANGED,
117
- expect.any(Function)
118
- );
119
- bootstrapSpy.mockRestore();
120
- });
121
-
122
- it('updates the existing app viewModel when re-rendering without forceRemount', async () => {
123
- // Create a fake Aurelia app with a mutable viewModel.
124
- const fakeViewModel: Record<string, any> = {};
125
- const fakeAurelia = {
126
- start: jest.fn().mockResolvedValue(undefined),
127
- stop: jest.fn().mockResolvedValue(undefined),
128
- root: { controller: { viewModel: fakeViewModel } },
129
- } as any;
130
-
131
- const story = { template: '<div></div>', props: { test: 'initial' } } as any;
132
- const storyFn = jest.fn(() => story) as any;
133
- const showError = jest.fn() as any;
134
- const showMain = jest.fn() as any;
135
-
136
- const bootstrapSpy = jest
137
- .spyOn(require('../src/preview/render'), 'bootstrapAureliaApp')
138
- .mockReturnValue(fakeAurelia);
139
-
140
- // First render: bootstrap the app.
141
- const context = {
142
- storyFn,
143
- title: 'Title',
144
- name: 'Name',
145
- showMain,
146
- showError,
147
- storyContext: {
148
- parameters: { args: { param: 'foo' } },
149
- component: DummyComponent as any,
150
- args: { test: 'bar' },
151
- viewMode: 'story',
152
- channel: dummyChannel,
153
- },
154
- forceRemount: false,
155
- } as any;
156
- await renderToCanvas(context, canvas, bootstrapAureliaApp);
157
- expect(bootstrapSpy).toHaveBeenCalledTimes(1);
158
-
159
- // Second render with new args; should update viewModel instead of re-bootstrap.
160
- const newStory = { template: '<div></div>', props: { test: 'updated' } } as any;
161
- storyFn.mockReturnValueOnce(newStory);
162
- const newContext = {
163
- ...context,
164
- storyContext: {
165
- ...context.storyContext,
166
- parameters: { args: { param: 'baz' } },
167
- args: { test: 'qux' },
168
- },
169
- } as any;
170
- await renderToCanvas(newContext, canvas, bootstrapAureliaApp);
171
- expect(bootstrapSpy).toHaveBeenCalledTimes(1);
172
- expect(fakeViewModel).toEqual({ param: 'baz', test: 'qux' });
173
- bootstrapSpy.mockRestore();
174
- });
175
- });
176
-
177
- describe('createComponentTemplate', () => {
178
- it('generates the correct template string', () => {
179
- const DummyComponent = class {};
180
- // The definition is already provided via module mocking.
181
-
182
- const template = createComponentTemplate(DummyComponent as any, '<span>inner</span>');
183
- expect(template).toBe(
184
- '<dummy-comp prop.bind="prop"><span>inner</span></dummy-comp>'
185
- );
186
- });
187
- });
@@ -1,21 +0,0 @@
1
- import { getRules } from '../src/webpack';
2
-
3
- describe('webpack', () => {
4
- describe('getRules', () => {
5
- it('should return the correct rules', () => {
6
- const rules = getRules();
7
- expect(rules).toEqual([
8
- {
9
- test: /\.ts$/i,
10
- use: ['ts-loader', '@aurelia/webpack-loader'],
11
- exclude: /node_modules/,
12
- },
13
- {
14
- test: /\.html$/i,
15
- use: '@aurelia/webpack-loader',
16
- exclude: /node_modules/,
17
- },
18
- ]);
19
- });
20
- });
21
- });
@@ -1,49 +0,0 @@
1
- import type { StorybookConfig } from 'storybook/internal/types';
2
- import { mergeConfig, type InlineConfig } from 'vite';
3
-
4
- const config: StorybookConfig & { viteFinal?: (config: InlineConfig, options: { configType: string }) => InlineConfig | Promise<InlineConfig> } = {
5
- stories: ['../src/stories/**/*.stories.@(ts|tsx|js|jsx|mdx)'],
6
- addons: [
7
- ],
8
- framework: {
9
- name: '@aurelia/storybook',
10
- options: {},
11
- },
12
- core: {
13
- builder: '@storybook/builder-vite',
14
- },
15
- viteFinal: async (viteConfig) => {
16
- // Initialize optimizeDeps and exclude array
17
- if (!viteConfig.optimizeDeps) {
18
- viteConfig.optimizeDeps = {};
19
- }
20
- if (!viteConfig.optimizeDeps.exclude) {
21
- viteConfig.optimizeDeps.exclude = [];
22
- }
23
-
24
- // Exclude Aurelia dependencies from pre-bundling, but allow React for Storybook
25
- const excludeList = [
26
- '@aurelia/runtime-html'
27
- ];
28
-
29
- excludeList.forEach(dep => {
30
- if (viteConfig.optimizeDeps?.exclude && !viteConfig.optimizeDeps.exclude.includes(dep)) {
31
- viteConfig.optimizeDeps.exclude.push(dep);
32
- }
33
- });
34
-
35
- return mergeConfig(viteConfig, {
36
- define: {
37
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
38
- },
39
- // Allow React to be bundled for Storybook's theming system
40
- resolve: {
41
- alias: {
42
- // Ensure React is properly resolved
43
- }
44
- }
45
- });
46
- },
47
- };
48
-
49
- export default config;
@@ -1 +0,0 @@
1
- export { render, renderToCanvas } from '@aurelia/storybook';
@@ -1,5 +0,0 @@
1
- {
2
- "extends": [
3
- "stylelint-config-standard"
4
- ]
5
- }
@@ -1,28 +0,0 @@
1
- # Aurelia Storybook Hello World
2
-
3
- This project is bootstrapped by [aurelia/new](https://github.com/aurelia/new).
4
-
5
- ## Start dev web server
6
-
7
- npm start
8
-
9
- ## Start Storybook
10
-
11
- npm run storybook
12
-
13
- ## Build the app in production mode
14
-
15
- npm run build
16
-
17
- ## Build Storybook
18
-
19
- npm run build-storybook
20
-
21
- ## Unit Tests
22
-
23
- npm run test
24
-
25
- Run unit tests in watch mode.
26
-
27
- npm run test:watch
28
-
@@ -1,25 +0,0 @@
1
- import eslint from "@eslint/js";
2
- import tseslint from 'typescript-eslint';
3
- import tsParser from "@typescript-eslint/parser";
4
- import globals from "globals";
5
-
6
- export default [
7
- eslint.configs.recommended,
8
- ...tseslint.configs.recommended,
9
- {
10
- files: ["**/*.ts"],
11
-
12
- languageOptions: {
13
- globals: {
14
- ...globals.builtin,
15
- ...globals.nodeBuiltin,
16
- ...globals.browser,
17
- ...globals.node,
18
- },
19
-
20
- parser: tsParser,
21
- ecmaVersion: 2019,
22
- sourceType: "module",
23
- },
24
- }
25
- ];
Binary file
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
-
4
- <head>
5
- <meta charset="utf-8">
6
- <title>Aurelia</title>
7
- <meta name="viewport" content="width=device-width, initial-scale=1">
8
- <script type="module" src="/src/main.ts"></script>
9
- <base href="/">
10
- </head>
11
-
12
- <body>
13
- <my-app></my-app>
14
- </body>
15
-
16
- </html>
17
-