@aurelia/storybook 2.2.1 → 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 (140) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +18 -14
  3. package/dist/index.js +34 -14
  4. package/dist/index.js.map +1 -1
  5. package/dist/preset.js +30 -20
  6. package/dist/preset.js.map +1 -1
  7. package/dist/preview/render.d.ts +1 -1
  8. package/dist/preview/render.js +34 -14
  9. package/dist/preview/render.js.map +1 -1
  10. package/dist/preview.js +34 -14
  11. package/dist/preview.js.map +1 -1
  12. package/package.json +30 -15
  13. package/preset.js +2 -1
  14. package/.github/workflows/ci.yml +0 -61
  15. package/.github/workflows/publish.yml +0 -82
  16. package/.github/workflows/storybook-preview.yml +0 -62
  17. package/__tests__/create-aurelia-app.test.ts +0 -94
  18. package/__tests__/preset.test.ts +0 -78
  19. package/__tests__/preview.test.ts +0 -17
  20. package/__tests__/render.test.ts +0 -176
  21. package/__tests__/webpack.test.ts +0 -21
  22. package/apps/hello-world/.storybook/main.ts +0 -49
  23. package/apps/hello-world/.storybook/preview.ts +0 -1
  24. package/apps/hello-world/.stylelintrc.json +0 -5
  25. package/apps/hello-world/README.md +0 -28
  26. package/apps/hello-world/eslint.config.mjs +0 -25
  27. package/apps/hello-world/favicon.ico +0 -0
  28. package/apps/hello-world/index.html +0 -17
  29. package/apps/hello-world/package-lock.json +0 -9424
  30. package/apps/hello-world/package.json +0 -55
  31. package/apps/hello-world/src/components/feedback-form.html +0 -111
  32. package/apps/hello-world/src/components/feedback-form.ts +0 -45
  33. package/apps/hello-world/src/components/notification-center.html +0 -119
  34. package/apps/hello-world/src/components/notification-center.ts +0 -27
  35. package/apps/hello-world/src/components/stat-card.html +0 -107
  36. package/apps/hello-world/src/components/stat-card.ts +0 -41
  37. package/apps/hello-world/src/components/weather-widget.html +0 -89
  38. package/apps/hello-world/src/components/weather-widget.ts +0 -31
  39. package/apps/hello-world/src/hello-world.html +0 -48
  40. package/apps/hello-world/src/hello-world.ts +0 -17
  41. package/apps/hello-world/src/main.ts +0 -6
  42. package/apps/hello-world/src/my-app.html +0 -1
  43. package/apps/hello-world/src/my-app.ts +0 -3
  44. package/apps/hello-world/src/resource.d.ts +0 -15
  45. package/apps/hello-world/src/services/weather-service.ts +0 -15
  46. package/apps/hello-world/src/stories/feedback-form.stories.ts +0 -58
  47. package/apps/hello-world/src/stories/hello-world.stories.ts +0 -64
  48. package/apps/hello-world/src/stories/notification-center.stories.ts +0 -88
  49. package/apps/hello-world/src/stories/stat-card.stories.ts +0 -75
  50. package/apps/hello-world/src/stories/weather-widget.stories.ts +0 -62
  51. package/apps/hello-world/test/my-app.spec.ts +0 -15
  52. package/apps/hello-world/test/setup.ts +0 -29
  53. package/apps/hello-world/tsconfig.json +0 -19
  54. package/apps/hello-world/tsconfig.vitest.json +0 -11
  55. package/apps/hello-world/vite.config.ts +0 -17
  56. package/apps/hello-world/vitest.config.ts +0 -15
  57. package/apps/hello-world-rsbuild/.storybook/main.ts +0 -16
  58. package/apps/hello-world-rsbuild/.storybook/preview.ts +0 -1
  59. package/apps/hello-world-rsbuild/.stylelintrc.json +0 -5
  60. package/apps/hello-world-rsbuild/README.md +0 -28
  61. package/apps/hello-world-rsbuild/eslint.config.mjs +0 -25
  62. package/apps/hello-world-rsbuild/favicon.ico +0 -0
  63. package/apps/hello-world-rsbuild/index.html +0 -17
  64. package/apps/hello-world-rsbuild/package-lock.json +0 -11131
  65. package/apps/hello-world-rsbuild/package.json +0 -56
  66. package/apps/hello-world-rsbuild/src/components/feedback-form.html +0 -111
  67. package/apps/hello-world-rsbuild/src/components/feedback-form.ts +0 -45
  68. package/apps/hello-world-rsbuild/src/components/notification-center.html +0 -119
  69. package/apps/hello-world-rsbuild/src/components/notification-center.ts +0 -27
  70. package/apps/hello-world-rsbuild/src/components/stat-card.html +0 -107
  71. package/apps/hello-world-rsbuild/src/components/stat-card.ts +0 -41
  72. package/apps/hello-world-rsbuild/src/components/weather-widget.html +0 -89
  73. package/apps/hello-world-rsbuild/src/components/weather-widget.ts +0 -31
  74. package/apps/hello-world-rsbuild/src/hello-world.html +0 -48
  75. package/apps/hello-world-rsbuild/src/hello-world.ts +0 -17
  76. package/apps/hello-world-rsbuild/src/main.ts +0 -6
  77. package/apps/hello-world-rsbuild/src/my-app.html +0 -1
  78. package/apps/hello-world-rsbuild/src/my-app.ts +0 -3
  79. package/apps/hello-world-rsbuild/src/resource.d.ts +0 -15
  80. package/apps/hello-world-rsbuild/src/services/weather-service.ts +0 -15
  81. package/apps/hello-world-rsbuild/src/stories/feedback-form.stories.ts +0 -58
  82. package/apps/hello-world-rsbuild/src/stories/hello-world.stories.ts +0 -64
  83. package/apps/hello-world-rsbuild/src/stories/notification-center.stories.ts +0 -88
  84. package/apps/hello-world-rsbuild/src/stories/stat-card.stories.ts +0 -75
  85. package/apps/hello-world-rsbuild/src/stories/weather-widget.stories.ts +0 -62
  86. package/apps/hello-world-rsbuild/test/my-app.spec.ts +0 -15
  87. package/apps/hello-world-rsbuild/test/setup.ts +0 -29
  88. package/apps/hello-world-rsbuild/tsconfig.json +0 -19
  89. package/apps/hello-world-rsbuild/tsconfig.vitest.json +0 -11
  90. package/apps/hello-world-rsbuild/vite.config.ts +0 -17
  91. package/apps/hello-world-rsbuild/vitest.config.ts +0 -15
  92. package/apps/hello-world-webpack/.env.development +0 -0
  93. package/apps/hello-world-webpack/.storybook/main.ts +0 -14
  94. package/apps/hello-world-webpack/.storybook/preview.ts +0 -3
  95. package/apps/hello-world-webpack/.stylelintrc.json +0 -5
  96. package/apps/hello-world-webpack/README.md +0 -29
  97. package/apps/hello-world-webpack/eslint.config.mjs +0 -25
  98. package/apps/hello-world-webpack/favicon.ico +0 -0
  99. package/apps/hello-world-webpack/index.html +0 -15
  100. package/apps/hello-world-webpack/package-lock.json +0 -9828
  101. package/apps/hello-world-webpack/package.json +0 -52
  102. package/apps/hello-world-webpack/src/components/feedback-form.html +0 -111
  103. package/apps/hello-world-webpack/src/components/feedback-form.ts +0 -45
  104. package/apps/hello-world-webpack/src/components/notification-center.html +0 -119
  105. package/apps/hello-world-webpack/src/components/notification-center.ts +0 -27
  106. package/apps/hello-world-webpack/src/components/stat-card.html +0 -107
  107. package/apps/hello-world-webpack/src/components/stat-card.ts +0 -41
  108. package/apps/hello-world-webpack/src/components/weather-widget.html +0 -89
  109. package/apps/hello-world-webpack/src/components/weather-widget.ts +0 -31
  110. package/apps/hello-world-webpack/src/hello-world.html +0 -48
  111. package/apps/hello-world-webpack/src/hello-world.ts +0 -17
  112. package/apps/hello-world-webpack/src/main.ts +0 -6
  113. package/apps/hello-world-webpack/src/my-app.css +0 -3
  114. package/apps/hello-world-webpack/src/my-app.html +0 -1
  115. package/apps/hello-world-webpack/src/my-app.stories.ts +0 -17
  116. package/apps/hello-world-webpack/src/my-app.ts +0 -3
  117. package/apps/hello-world-webpack/src/resource.d.ts +0 -13
  118. package/apps/hello-world-webpack/src/services/weather-service.ts +0 -15
  119. package/apps/hello-world-webpack/src/stories/feedback-form.stories.ts +0 -58
  120. package/apps/hello-world-webpack/src/stories/hello-world.stories.ts +0 -64
  121. package/apps/hello-world-webpack/src/stories/notification-center.stories.ts +0 -88
  122. package/apps/hello-world-webpack/src/stories/stat-card.stories.ts +0 -75
  123. package/apps/hello-world-webpack/src/stories/weather-widget.stories.ts +0 -62
  124. package/apps/hello-world-webpack/tsconfig.json +0 -18
  125. package/apps/hello-world-webpack/webpack.config.js +0 -111
  126. package/jest.config.cjs +0 -9
  127. package/rollup.config.mjs +0 -52
  128. package/scripts/sync-versions.cjs +0 -55
  129. package/src/index.ts +0 -42
  130. package/src/preset.ts +0 -79
  131. package/src/preview/helpers.ts +0 -7
  132. package/src/preview/render.ts +0 -243
  133. package/src/preview/storybook-types-runtime.ts +0 -2
  134. package/src/preview/storybook-types.ts +0 -34
  135. package/src/preview/types-runtime.ts +0 -2
  136. package/src/preview/types.ts +0 -62
  137. package/src/preview.ts +0 -11
  138. package/src/webpack.ts +0 -40
  139. package/tsconfig.build.json +0 -5
  140. package/tsconfig.json +0 -15
@@ -1,176 +0,0 @@
1
- import {
2
- render,
3
- renderToCanvas,
4
- createAureliaApp,
5
- createComponentTemplate,
6
- } from '../src/preview/render';
7
-
8
- // Add this at the very top of the file, before any imports.
9
- jest.mock('aurelia', () => {
10
- const actual = jest.requireActual('aurelia');
11
- return {
12
- ...actual,
13
- CustomElement: {
14
- ...actual.CustomElement,
15
- getDefinition: jest.fn().mockReturnValue({
16
- name: 'dummy-comp',
17
- bindables: { prop: { attribute: 'prop', name: 'prop' } },
18
- }),
19
- },
20
- };
21
- });
22
-
23
- describe('render', () => {
24
- it('throws an error when no component is provided', () => {
25
- expect(() =>
26
- render(
27
- {},
28
- { id: 'story-1', title: 'Test', name: 'Story', component: undefined as any } as any
29
- )
30
- ).toThrow(
31
- 'Unable to render story Test / Story as the component annotation is missing from the default export'
32
- );
33
- });
34
-
35
- it('returns the expected object when a component is provided', () => {
36
- const DummyComponent = () => {};
37
- const args = { foo: 'bar' };
38
- const result = render(args, { id: 'story-1', component: DummyComponent as any } as any);
39
- expect(result).toEqual({ Component: DummyComponent, props: args });
40
- });
41
- });
42
-
43
- describe('renderToCanvas', () => {
44
- let canvas: HTMLElement;
45
- const DummyComponent = class {};
46
-
47
- beforeEach(() => {
48
- canvas = document.createElement('div');
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
- },
66
- forceRemount: false,
67
- } as any;
68
-
69
- const cleanup = await renderToCanvas(context, canvas);
70
- expect(showError).toHaveBeenCalled();
71
- expect(typeof cleanup).toBe('function');
72
- });
73
-
74
- it('bootstraps an Aurelia app when none exists or forceRemount is true', async () => {
75
- const fakeAurelia = {
76
- start: jest.fn().mockResolvedValue(undefined),
77
- stop: jest.fn().mockResolvedValue(undefined),
78
- root: { controller: { viewModel: {} } },
79
- } as any;
80
- const story = { template: '<div></div>', props: { test: 'value' } } as any;
81
- const storyFn = jest.fn(() => story) as any;
82
- const showError = jest.fn() as any;
83
- const showMain = jest.fn() as any;
84
-
85
- const bootstrapSpy = jest
86
- .spyOn(require('../src/preview/render'), 'createAureliaApp')
87
- .mockReturnValue(fakeAurelia);
88
-
89
- const context = {
90
- storyFn,
91
- title: 'Test Title',
92
- name: 'Test Story',
93
- showMain,
94
- showError,
95
- storyContext: {
96
- parameters: { args: { param: 'foo' } },
97
- component: DummyComponent as any,
98
- args: { test: 'bar' },
99
- },
100
- forceRemount: false,
101
- } as any;
102
-
103
- const cleanup = await renderToCanvas(context, canvas, createAureliaApp);
104
- expect(showError).not.toHaveBeenCalled();
105
- expect(showMain).toHaveBeenCalled();
106
- expect(bootstrapSpy).toHaveBeenCalled();
107
-
108
- await cleanup();
109
- expect(fakeAurelia.stop).toHaveBeenCalled();
110
- bootstrapSpy.mockRestore();
111
- });
112
-
113
- it('updates the existing app viewModel when re-rendering without forceRemount', async () => {
114
- // Create a fake Aurelia app with a mutable viewModel.
115
- const fakeViewModel: Record<string, any> = {};
116
- const fakeAurelia = {
117
- start: jest.fn().mockResolvedValue(undefined),
118
- stop: jest.fn().mockResolvedValue(undefined),
119
- root: { controller: { viewModel: fakeViewModel } },
120
- } as any;
121
-
122
- const story = { template: '<div></div>', props: { test: 'initial' } } as any;
123
- const storyFn = jest.fn(() => story) as any;
124
- const showError = jest.fn() as any;
125
- const showMain = jest.fn() as any;
126
-
127
- const bootstrapSpy = jest
128
- .spyOn(require('../src/preview/render'), 'createAureliaApp')
129
- .mockReturnValue(fakeAurelia);
130
-
131
- // First render: bootstrap the app.
132
- const context = {
133
- storyFn,
134
- title: 'Title',
135
- name: 'Name',
136
- showMain,
137
- showError,
138
- storyContext: {
139
- parameters: { args: { param: 'foo' } },
140
- component: DummyComponent as any,
141
- args: { test: 'bar' },
142
- },
143
- forceRemount: false,
144
- } as any;
145
- await renderToCanvas(context, canvas, createAureliaApp);
146
- expect(bootstrapSpy).toHaveBeenCalledTimes(1);
147
-
148
- // Second render with new args; should update viewModel instead of re-bootstrap.
149
- const newStory = { template: '<div></div>', props: { test: 'updated' } } as any;
150
- storyFn.mockReturnValueOnce(newStory);
151
- const newContext = {
152
- ...context,
153
- storyContext: {
154
- ...context.storyContext,
155
- parameters: { args: { param: 'baz' } },
156
- args: { test: 'qux' },
157
- },
158
- } as any;
159
- await renderToCanvas(newContext, canvas, createAureliaApp);
160
- expect(bootstrapSpy).toHaveBeenCalledTimes(1);
161
- expect(fakeViewModel).toEqual({ param: 'baz', test: 'updated' });
162
- bootstrapSpy.mockRestore();
163
- });
164
- });
165
-
166
- describe('createComponentTemplate', () => {
167
- it('generates the correct template string', () => {
168
- const DummyComponent = class {};
169
- // The definition is already provided via module mocking.
170
-
171
- const template = createComponentTemplate(DummyComponent as any, '<span>inner</span>');
172
- expect(template).toBe(
173
- '<dummy-comp prop.bind="prop"><span>inner</span></dummy-comp>'
174
- );
175
- });
176
- });
@@ -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
-