@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,175 +0,0 @@
1
- import { STORY_CHANGED } from 'storybook/internal/core-events';
2
- import type { RenderContext, ArgsStoryFn } from 'storybook/internal/types';
3
- import type { AureliaRenderer } from './types';
4
- import Aurelia, { Constructable, CustomElement } from 'aurelia';
5
-
6
- interface AureliaStoryResult {
7
- template: string;
8
- components?: unknown[];
9
- Component?: unknown;
10
- container?: any;
11
- items?: unknown[];
12
- innerHtml?: string;
13
- props?: Record<string, any>;
14
- }
15
-
16
- // Track Aurelia apps for cleanup
17
- const appMap = new Map<HTMLElement, any>();
18
-
19
- async function teardown(element: HTMLElement) {
20
- if (appMap.has(element)) {
21
- const app = appMap.get(element);
22
- if (app) {
23
- await app.stop();
24
- appMap.delete(element);
25
- }
26
- }
27
- }
28
-
29
- export const render: ArgsStoryFn<AureliaRenderer> = (args, context) => {
30
- const { id, component: Component } = context;
31
-
32
- if (!Component) {
33
- throw new Error(
34
- `Unable to render story ${id} as the component annotation is missing from the default export`
35
- );
36
- }
37
- return { Component, props: args, template: '' };
38
- };
39
-
40
- export async function renderToCanvas(
41
- {
42
- storyFn,
43
- title,
44
- name,
45
- showMain,
46
- showError,
47
- storyContext,
48
- forceRemount,
49
- }: RenderContext<AureliaRenderer>,
50
- canvasElement: HTMLElement,
51
- bootstrapAppFn?: typeof createAureliaApp
52
- ) {
53
- // Store reference to the original storybook root element
54
- const rootElement = canvasElement;
55
-
56
- // Ensure we have (or create) a single container inside the root where the Aurelia app actually renders
57
- let hostElement: HTMLElement;
58
- if (rootElement.id === 'storybook-root') {
59
- hostElement = rootElement.querySelector('.aurelia-story-container') as HTMLElement;
60
- if (!hostElement) {
61
- hostElement = document.createElement('div');
62
- hostElement.className = 'aurelia-story-container';
63
- hostElement.style.height = '100%';
64
- rootElement.appendChild(hostElement);
65
- }
66
- } else {
67
- hostElement = rootElement;
68
- }
69
-
70
- // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe
71
- const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;
72
- const { parameters, component, args } = storyContext;
73
-
74
- let app = appMap.get(rootElement);
75
- const story = storyFn() as AureliaStoryResult;
76
-
77
- // Temporary debug logging
78
- console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);
79
-
80
- if (!story) {
81
- showError({
82
- title: `Expecting an Aurelia component from the story: "${name}" of "${title}".`,
83
- description: `
84
- Did you forget to return the Aurelia component from the story?
85
- Use "() => ({ template: '<custom-component></custom-component>' })" when defining the story.
86
- `,
87
- });
88
- return () => {};
89
- }
90
-
91
- showMain();
92
-
93
- if (!app || forceRemount) {
94
- if (forceRemount && app) {
95
- await teardown(rootElement);
96
- app = undefined;
97
- }
98
- // Clear container before mounting new app
99
- hostElement.innerHTML = '';
100
-
101
- const mergedProps = { ...parameters?.args, ...args, ...story.props };
102
-
103
- const aureliaApp = appBootstrapFn(
104
- story,
105
- mergedProps,
106
- hostElement,
107
- component as Constructable
108
- );
109
- await aureliaApp.start();
110
- appMap.set(rootElement, aureliaApp);
111
- app = aureliaApp;
112
- } else {
113
- // update existing app props
114
- const mergedProps = { ...parameters?.args, ...args, ...story.props };
115
- if (app?.root?.controller?.viewModel) {
116
- Object.assign(app.root.controller.viewModel, mergedProps);
117
- }
118
- }
119
-
120
- // Return cleanup fn
121
- return async () => {
122
- await teardown(rootElement);
123
- };
124
- }
125
-
126
- export function createAureliaApp(
127
- story: AureliaStoryResult,
128
- args: Record<string, any>,
129
- domElement: HTMLElement,
130
- component?: Constructable
131
- ) {
132
- const aurelia = new Aurelia(story.container);
133
-
134
- if (story.items?.length) {
135
- aurelia.register(...story.items);
136
- }
137
-
138
- if (story.components?.length) {
139
- aurelia.register(...story.components);
140
- }
141
-
142
- let { template } = story;
143
-
144
- if (component) {
145
- template = template ?? createComponentTemplate(component, story.innerHtml);
146
- aurelia.register(component);
147
- }
148
-
149
- const App = CustomElement.define(
150
- {
151
- name: 'sb-app',
152
- template,
153
- containerless: true,
154
- },
155
- class {}
156
- );
157
-
158
- const app = Object.assign(new App(), args);
159
-
160
- return aurelia.app({
161
- host: domElement,
162
- component: app,
163
- });
164
- }
165
-
166
- export function createComponentTemplate(
167
- component: Constructable,
168
- innerHtml?: string
169
- ): string {
170
- const def = CustomElement.getDefinition(component);
171
-
172
- return `<${def.name} ${Object.values(def.bindables)
173
- .map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
174
- .join(' ')}>${innerHtml ?? ''}</${def.name}>`;
175
- }
@@ -1,7 +0,0 @@
1
- import type { Renderer } from 'storybook/internal/types';
2
-
3
- export interface AureliaRenderer extends Renderer {
4
- /** The DOM element in which the story is rendered */
5
- canvasElement: HTMLElement;
6
- }
7
-
package/src/preview.ts DELETED
@@ -1 +0,0 @@
1
- export { renderToCanvas, render } from './preview/render';
package/src/webpack.ts DELETED
@@ -1,21 +0,0 @@
1
- // src/webpack.ts
2
- import type { RuleSetRule } from 'webpack';
3
-
4
- /**
5
- * A set of rules to be added to the webpack configuration.
6
- * @returns
7
- */
8
- export function getRules(): RuleSetRule[] {
9
- return [
10
- {
11
- test: /\.ts$/i,
12
- use: ['ts-loader', '@aurelia/webpack-loader'],
13
- exclude: /node_modules/,
14
- },
15
- {
16
- test: /\.html$/i,
17
- use: '@aurelia/webpack-loader',
18
- exclude: /node_modules/,
19
- },
20
- ];
21
- }
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": ["src"],
4
- "exclude": ["__tests__"]
5
- }
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "declaration": true,
6
- "outDir": "dist",
7
- "rootDir": "src",
8
- "strict": true,
9
- "moduleResolution": "bundler",
10
- "esModuleInterop": true,
11
- "skipLibCheck": true
12
- },
13
- "include": ["src", "__tests__"]
14
- }
15
-