@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.
- package/CHANGELOG.md +11 -0
- package/README.md +195 -12
- package/dist/index.d.ts +25 -0
- package/dist/index.js +101 -27
- package/dist/index.js.map +1 -1
- package/dist/preset.d.ts +21 -0
- package/dist/preset.js +74 -20
- package/dist/preset.js.map +1 -1
- package/dist/preview/helpers.d.ts +2 -0
- package/dist/preview/helpers.js +6 -0
- package/dist/preview/helpers.js.map +1 -0
- package/dist/preview/render.d.ts +7 -0
- package/dist/preview/render.js +99 -28
- package/dist/preview/render.js.map +1 -1
- package/dist/preview/storybook-types-runtime.d.ts +1 -0
- package/dist/preview/storybook-types-runtime.js +5 -0
- package/dist/preview/storybook-types-runtime.js.map +1 -0
- package/dist/preview/storybook-types.d.ts +27 -0
- package/dist/preview/types-runtime.d.ts +1 -0
- package/dist/preview/types-runtime.js +5 -0
- package/dist/preview/types-runtime.js.map +1 -0
- package/dist/preview/types.d.ts +44 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +104 -29
- package/dist/preview.js.map +1 -1
- package/dist/webpack.d.ts +10 -0
- package/dist/webpack.js +19 -1
- package/dist/webpack.js.map +1 -1
- package/package.json +75 -15
- package/preset.js +2 -1
- package/CONTINUITY.md +0 -22
- package/__tests__/preset.test.ts +0 -49
- package/__tests__/preview.test.ts +0 -139
- package/__tests__/render.test.ts +0 -187
- package/__tests__/webpack.test.ts +0 -21
- package/apps/hello-world/.storybook/main.ts +0 -49
- package/apps/hello-world/.storybook/preview.ts +0 -1
- package/apps/hello-world/.stylelintrc.json +0 -5
- package/apps/hello-world/README.md +0 -28
- package/apps/hello-world/eslint.config.mjs +0 -25
- package/apps/hello-world/favicon.ico +0 -0
- package/apps/hello-world/index.html +0 -17
- package/apps/hello-world/package-lock.json +0 -9307
- package/apps/hello-world/package.json +0 -55
- package/apps/hello-world/src/components/feedback-form.html +0 -111
- package/apps/hello-world/src/components/feedback-form.ts +0 -45
- package/apps/hello-world/src/components/notification-center.html +0 -119
- package/apps/hello-world/src/components/notification-center.ts +0 -27
- package/apps/hello-world/src/components/stat-card.html +0 -107
- package/apps/hello-world/src/components/stat-card.ts +0 -33
- package/apps/hello-world/src/components/weather-widget.html +0 -89
- package/apps/hello-world/src/components/weather-widget.ts +0 -30
- package/apps/hello-world/src/hello-world.html +0 -48
- package/apps/hello-world/src/hello-world.ts +0 -17
- package/apps/hello-world/src/main.ts +0 -6
- package/apps/hello-world/src/my-app.html +0 -1
- package/apps/hello-world/src/my-app.ts +0 -3
- package/apps/hello-world/src/resource.d.ts +0 -15
- package/apps/hello-world/src/services/weather-service.ts +0 -15
- package/apps/hello-world/src/stories/feedback-form.stories.ts +0 -52
- package/apps/hello-world/src/stories/hello-world.stories.ts +0 -53
- package/apps/hello-world/src/stories/notification-center.stories.ts +0 -81
- package/apps/hello-world/src/stories/stat-card.stories.ts +0 -65
- package/apps/hello-world/src/stories/weather-widget.stories.ts +0 -57
- package/apps/hello-world/test/my-app.spec.ts +0 -15
- package/apps/hello-world/test/setup.ts +0 -29
- package/apps/hello-world/tsconfig.json +0 -19
- package/apps/hello-world/tsconfig.vitest.json +0 -11
- package/apps/hello-world/vite.config.ts +0 -17
- package/apps/hello-world/vitest.config.ts +0 -15
- package/apps/hello-world-webpack/.env.development +0 -0
- package/apps/hello-world-webpack/.storybook/main.ts +0 -14
- package/apps/hello-world-webpack/.storybook/preview.ts +0 -3
- package/apps/hello-world-webpack/.stylelintrc.json +0 -5
- package/apps/hello-world-webpack/README.md +0 -29
- package/apps/hello-world-webpack/eslint.config.mjs +0 -25
- package/apps/hello-world-webpack/favicon.ico +0 -0
- package/apps/hello-world-webpack/index.html +0 -15
- package/apps/hello-world-webpack/package-lock.json +0 -9853
- package/apps/hello-world-webpack/package.json +0 -51
- package/apps/hello-world-webpack/src/components/feedback-form.html +0 -111
- package/apps/hello-world-webpack/src/components/feedback-form.ts +0 -45
- package/apps/hello-world-webpack/src/components/notification-center.html +0 -119
- package/apps/hello-world-webpack/src/components/notification-center.ts +0 -27
- package/apps/hello-world-webpack/src/components/stat-card.html +0 -107
- package/apps/hello-world-webpack/src/components/stat-card.ts +0 -33
- package/apps/hello-world-webpack/src/components/weather-widget.html +0 -89
- package/apps/hello-world-webpack/src/components/weather-widget.ts +0 -30
- package/apps/hello-world-webpack/src/hello-world.html +0 -48
- package/apps/hello-world-webpack/src/hello-world.ts +0 -17
- package/apps/hello-world-webpack/src/main.ts +0 -6
- package/apps/hello-world-webpack/src/my-app.css +0 -3
- package/apps/hello-world-webpack/src/my-app.html +0 -1
- package/apps/hello-world-webpack/src/my-app.stories.ts +0 -15
- package/apps/hello-world-webpack/src/my-app.ts +0 -3
- package/apps/hello-world-webpack/src/resource.d.ts +0 -13
- package/apps/hello-world-webpack/src/services/weather-service.ts +0 -15
- package/apps/hello-world-webpack/src/stories/feedback-form.stories.ts +0 -52
- package/apps/hello-world-webpack/src/stories/hello-world.stories.ts +0 -53
- package/apps/hello-world-webpack/src/stories/notification-center.stories.ts +0 -81
- package/apps/hello-world-webpack/src/stories/stat-card.stories.ts +0 -65
- package/apps/hello-world-webpack/src/stories/weather-widget.stories.ts +0 -57
- package/apps/hello-world-webpack/tsconfig.json +0 -18
- package/apps/hello-world-webpack/webpack.config.js +0 -111
- package/dist/preview/types.js +0 -2
- package/dist/preview/types.js.map +0 -1
- package/jest.config.js +0 -9
- package/rollup.config.mjs +0 -50
- package/src/index.ts +0 -32
- package/src/preset.ts +0 -49
- package/src/preview/render.ts +0 -175
- package/src/preview/types.ts +0 -7
- package/src/preview.ts +0 -1
- package/src/webpack.ts +0 -21
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -15
package/src/preview/render.ts
DELETED
|
@@ -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
|
-
}
|
package/src/preview/types.ts
DELETED
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
|
-
}
|
package/tsconfig.build.json
DELETED
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
|
-
|