@aurelia/storybook 0.1.0 → 1.0.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/LICENSE +1 -1
- package/README.md +31 -3
- package/__tests__/preset.test.ts +49 -0
- package/__tests__/preview.test.ts +139 -0
- package/__tests__/render.test.ts +0 -1
- package/__tests__/webpack.test.ts +21 -0
- package/apps/hello-world/.storybook/main.ts +30 -0
- package/apps/hello-world/.storybook/preview.ts +1 -0
- package/apps/hello-world/.stylelintrc.json +5 -0
- package/apps/hello-world/.yarnrc.yml +2 -0
- package/apps/hello-world/README.md +28 -0
- package/apps/hello-world/eslint.config.mjs +25 -0
- package/apps/hello-world/favicon.ico +0 -0
- package/apps/hello-world/index.html +17 -0
- package/apps/hello-world/package.json +65 -0
- package/apps/hello-world/src/hello-world.html +6 -0
- package/apps/hello-world/src/hello-world.ts +17 -0
- package/apps/hello-world/src/main.ts +6 -0
- package/apps/hello-world/src/my-app.html +1 -0
- package/apps/hello-world/src/my-app.ts +3 -0
- package/apps/hello-world/src/resource.d.ts +15 -0
- package/apps/hello-world/src/stories/hello-world.stories.ts +53 -0
- package/apps/hello-world/test/my-app.spec.ts +15 -0
- package/apps/hello-world/test/setup.ts +29 -0
- package/apps/hello-world/tsconfig.json +18 -0
- package/apps/hello-world/tsconfig.vitest.json +11 -0
- package/apps/hello-world/vite.config.ts +19 -0
- package/apps/hello-world/vitest.config.ts +15 -0
- package/apps/hello-world-webpack/.storybook/main.ts +18 -0
- package/apps/hello-world-webpack/.storybook/preview.ts +3 -0
- package/apps/hello-world-webpack/.stylelintrc.json +5 -0
- package/apps/hello-world-webpack/.yarnrc.yml +2 -0
- package/apps/hello-world-webpack/README.md +29 -0
- package/apps/hello-world-webpack/eslint.config.mjs +25 -0
- package/apps/hello-world-webpack/favicon.ico +0 -0
- package/apps/hello-world-webpack/index.html +15 -0
- package/apps/hello-world-webpack/package-lock.json +10178 -0
- package/apps/hello-world-webpack/package.json +55 -0
- package/apps/hello-world-webpack/src/main.ts +6 -0
- package/apps/hello-world-webpack/src/my-app.css +3 -0
- package/apps/hello-world-webpack/src/my-app.html +1 -0
- package/apps/hello-world-webpack/src/my-app.stories.ts +12 -0
- package/apps/hello-world-webpack/src/my-app.ts +3 -0
- package/apps/hello-world-webpack/src/resource.d.ts +13 -0
- package/apps/hello-world-webpack/tsconfig.json +18 -0
- package/apps/hello-world-webpack/webpack.config.js +111 -0
- package/dist/index.js +112 -3
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +109 -0
- package/dist/index.mjs.map +1 -0
- package/dist/preset.js +44 -2
- package/dist/preset.js.map +1 -0
- package/dist/preset.mjs +46 -0
- package/dist/preset.mjs.map +1 -0
- package/dist/preview/render.js +26 -14
- package/dist/preview/render.js.map +1 -0
- package/dist/{src/preview/render.js → preview/render.mjs} +8 -4
- package/dist/preview/render.mjs.map +1 -0
- package/dist/preview/types.js +3 -1
- package/dist/preview/types.js.map +1 -0
- package/dist/preview/types.mjs +2 -0
- package/dist/preview/types.mjs.map +1 -0
- package/dist/preview.js +75 -0
- package/dist/preview.js.map +1 -0
- package/dist/preview.mjs +73 -0
- package/dist/preview.mjs.map +1 -0
- package/dist/webpack.js +23 -0
- package/dist/webpack.js.map +1 -0
- package/dist/webpack.mjs +21 -0
- package/dist/webpack.mjs.map +1 -0
- package/jest.config.js +1 -1
- package/package.json +40 -20
- package/rollup.config.mjs +51 -0
- package/src/preset.ts +22 -5
- package/src/preview.ts +50 -0
- package/src/webpack.ts +21 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +1 -0
- package/dist/__tests__/example.test.js +0 -6
- package/dist/__tests__/render.test.d.ts +0 -1
- package/dist/__tests__/render.test.js +0 -156
- package/dist/index.d.ts +0 -3
- package/dist/preset.d.ts +0 -8
- package/dist/preview/render.d.ts +0 -17
- package/dist/preview/render.test.d.ts +0 -1
- package/dist/preview/render.test.js +0 -126
- package/dist/preview/types.d.ts +0 -5
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.js +0 -3
- package/dist/src/preset.d.ts +0 -8
- package/dist/src/preset.js +0 -11
- package/dist/src/preview/render.d.ts +0 -17
- package/dist/src/preview/types.d.ts +0 -5
- package/dist/src/preview/types.js +0 -1
- /package/{dist/__tests__/example.test.d.ts → apps/hello-world-webpack/.env.development} +0 -0
package/dist/preview/render.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var coreEvents = require('@storybook/core-events');
|
|
4
|
+
var Aurelia = require('aurelia');
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Merges multiple sources into a single object.
|
|
5
8
|
* Sources can be story parameters, args, or story.props.
|
|
@@ -18,13 +21,14 @@ async function teardown(element) {
|
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
|
-
|
|
24
|
+
const render = (args, { id, component: Component }) => {
|
|
22
25
|
if (!Component) {
|
|
23
26
|
throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);
|
|
24
27
|
}
|
|
25
28
|
return { Component, props: args, template: '' };
|
|
26
29
|
};
|
|
27
|
-
|
|
30
|
+
async function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }, canvasElement, bootstrapAppFn) {
|
|
31
|
+
const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;
|
|
28
32
|
const { parameters, component, args } = storyContext;
|
|
29
33
|
let app = appMap.get(canvasElement);
|
|
30
34
|
const story = storyFn();
|
|
@@ -39,18 +43,20 @@ export async function renderToCanvas({ storyFn, title, name, showMain, showError
|
|
|
39
43
|
return () => { };
|
|
40
44
|
}
|
|
41
45
|
showMain();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// if no app or forceRemount, tear down existing app (if any) first.
|
|
46
|
+
let mergedProps;
|
|
47
|
+
// Use full merge (including story.props) when bootstrapping a new app or force remounting.
|
|
45
48
|
if (!app || forceRemount) {
|
|
49
|
+
mergedProps = mergeStoryProps(parameters?.args, args, story.props);
|
|
46
50
|
if (app) {
|
|
47
51
|
await teardown(canvasElement);
|
|
48
52
|
}
|
|
49
|
-
app =
|
|
53
|
+
app = appBootstrapFn(story, mergedProps, canvasElement, component);
|
|
50
54
|
await app.start();
|
|
51
55
|
appMap.set(canvasElement, app);
|
|
52
56
|
}
|
|
53
57
|
else {
|
|
58
|
+
// Update the existing app viewModel only with parameters and args (exclude story.props).
|
|
59
|
+
mergedProps = mergeStoryProps(parameters?.args, args);
|
|
54
60
|
if (app.root?.controller?.viewModel) {
|
|
55
61
|
Object.assign(app.root.controller.viewModel, mergedProps);
|
|
56
62
|
}
|
|
@@ -63,17 +69,17 @@ export async function renderToCanvas({ storyFn, title, name, showMain, showError
|
|
|
63
69
|
// When the story changes, clean up the Aurelia app
|
|
64
70
|
teardown(canvasElement);
|
|
65
71
|
};
|
|
66
|
-
channel.on(STORY_CHANGED, onStoryChange);
|
|
72
|
+
channel.on(coreEvents.STORY_CHANGED, onStoryChange);
|
|
67
73
|
}
|
|
68
74
|
// Return teardown function that also unsubscribes from STORY_CHANGED
|
|
69
75
|
return async () => {
|
|
70
76
|
if (channel && onStoryChange) {
|
|
71
|
-
channel.off(STORY_CHANGED, onStoryChange);
|
|
77
|
+
channel.off(coreEvents.STORY_CHANGED, onStoryChange);
|
|
72
78
|
}
|
|
73
79
|
await teardown(canvasElement);
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
|
-
|
|
82
|
+
function bootstrapAureliaApp(story, args, domElement, component) {
|
|
77
83
|
const aurelia = new Aurelia(story.container);
|
|
78
84
|
if (story.items?.length) {
|
|
79
85
|
aurelia.register(...story.items);
|
|
@@ -86,7 +92,7 @@ export function bootstrapAureliaApp(story, args, domElement, component) {
|
|
|
86
92
|
template = template ?? createComponentTemplate(component, story.innerHtml);
|
|
87
93
|
aurelia.register(component);
|
|
88
94
|
}
|
|
89
|
-
const App = CustomElement.define({
|
|
95
|
+
const App = Aurelia.CustomElement.define({
|
|
90
96
|
name: 'au-storybook',
|
|
91
97
|
template,
|
|
92
98
|
containerless: true,
|
|
@@ -98,9 +104,15 @@ export function bootstrapAureliaApp(story, args, domElement, component) {
|
|
|
98
104
|
component: app,
|
|
99
105
|
});
|
|
100
106
|
}
|
|
101
|
-
|
|
102
|
-
const def = CustomElement.getDefinition(component);
|
|
107
|
+
function createComponentTemplate(component, innerHtml) {
|
|
108
|
+
const def = Aurelia.CustomElement.getDefinition(component);
|
|
103
109
|
return `<${def.name} ${Object.values(def.bindables)
|
|
104
110
|
.map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
|
|
105
111
|
.join(' ')}>${innerHtml ?? ''}</${def.name}>`;
|
|
106
112
|
}
|
|
113
|
+
|
|
114
|
+
exports.bootstrapAureliaApp = bootstrapAureliaApp;
|
|
115
|
+
exports.createComponentTemplate = createComponentTemplate;
|
|
116
|
+
exports.render = render;
|
|
117
|
+
exports.renderToCanvas = renderToCanvas;
|
|
118
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sources":["../../src/preview/render.ts"],"sourcesContent":["import { STORY_CHANGED } from '@storybook/core-events';\nimport type { RenderContext, ArgsStoryFn } from '@storybook/types';\nimport type { AureliaRenderer } from './types';\nimport Aurelia, { Constructable, CustomElement } from 'aurelia';\n\ninterface AureliaStoryResult {\n template: string;\n components?: unknown[];\n Component?: unknown;\n container?: any;\n items?: unknown[];\n innerHtml?: string;\n props?: Record<string, any>;\n}\n\n/**\n * Merges multiple sources into a single object.\n * Sources can be story parameters, args, or story.props.\n */\nfunction mergeStoryProps(\n ...sources: Array<Record<string, any> | undefined>\n): Record<string, any> {\n return Object.assign({}, ...sources);\n}\n\n// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, Aurelia>();\n\nasync function teardown(element: HTMLElement) {\n if (appMap.has(element)) {\n const app = appMap.get(element);\n if (app) {\n await app.stop();\n appMap.delete(element);\n }\n }\n}\n\nexport const render: ArgsStoryFn<AureliaRenderer> = (args, { id, component: Component }) => {\n if (!Component) {\n throw new Error(\n `Unable to render story ${id} as the component annotation is missing from the default export`\n );\n }\n return { Component, props: args, template: '' };\n};\n\nexport async function renderToCanvas(\n {\n storyFn,\n title,\n name,\n showMain,\n showError,\n storyContext,\n forceRemount,\n }: RenderContext<AureliaRenderer>,\n canvasElement: HTMLElement,\n bootstrapAppFn?: typeof bootstrapAureliaApp\n) {\n const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;\n\n const { parameters, component, args } = storyContext;\n let app = appMap.get(canvasElement);\n\n const story = storyFn() as AureliaStoryResult;\n\n if (!story) {\n showError({\n title: `Expecting an Aurelia component from the story: \"${name}\" of \"${title}\".`,\n description: `\n Did you forget to return the Aurelia component from the story?\n Use \"() => ({ template: '<custom-component></custom-component>' })\" when defining the story.\n `,\n });\n return () => {};\n }\n\n showMain();\n\n let mergedProps;\n // Use full merge (including story.props) when bootstrapping a new app or force remounting.\n if (!app || forceRemount) {\n mergedProps = mergeStoryProps(parameters?.args, args, story.props);\n if (app) {\n await teardown(canvasElement);\n }\n app = appBootstrapFn(\n story,\n mergedProps,\n canvasElement,\n component as Constructable\n ) as Aurelia;\n await app.start();\n appMap.set(canvasElement, app);\n } else {\n // Update the existing app viewModel only with parameters and args (exclude story.props).\n mergedProps = mergeStoryProps(parameters?.args, args);\n if (app.root?.controller?.viewModel) {\n Object.assign(app.root.controller.viewModel, mergedProps);\n }\n }\n\n // Set up story change listener for cleanup\n const channel = storyContext.viewMode === 'story' ? storyContext.channel : null;\n let onStoryChange: () => void;\n if (channel) {\n onStoryChange = () => {\n // When the story changes, clean up the Aurelia app\n teardown(canvasElement);\n };\n channel.on(STORY_CHANGED, onStoryChange);\n }\n\n // Return teardown function that also unsubscribes from STORY_CHANGED\n return async () => {\n if (channel && onStoryChange) {\n channel.off(STORY_CHANGED, onStoryChange);\n }\n await teardown(canvasElement);\n };\n}\n\nexport function bootstrapAureliaApp(\n story: AureliaStoryResult,\n args: Record<string, any>,\n domElement: HTMLElement,\n component?: Constructable\n) {\n const aurelia = new Aurelia(story.container);\n\n if (story.items?.length) {\n aurelia.register(...story.items);\n }\n\n if (story.components?.length) {\n aurelia.register(...story.components);\n }\n\n let { template } = story;\n\n if (component) {\n template = template ?? createComponentTemplate(component, story.innerHtml);\n aurelia.register(component);\n }\n\n const App = CustomElement.define(\n {\n name: 'au-storybook',\n template,\n containerless: true,\n },\n class {}\n );\n\n const app = Object.assign(new App(), args);\n\n return aurelia.app({\n host: domElement,\n component: app,\n });\n}\n\nexport function createComponentTemplate(\n component: Constructable,\n innerHtml?: string\n): string {\n const def = CustomElement.getDefinition(component);\n\n return `<${def.name} ${Object.values(def.bindables)\n .map((bindable) => `${bindable.attribute}.bind=\"${bindable.name}\"`)\n .join(' ')}>${innerHtml ?? ''}</${def.name}>`;\n}"],"names":["STORY_CHANGED","CustomElement"],"mappings":";;;;;AAeA;;;AAGG;AACH,SAAS,eAAe,CACtB,GAAG,OAA+C,EAAA;IAElD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC;AACtC;AAEA;AACA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAwB;AAE9C,eAAe,QAAQ,CAAC,OAAoB,EAAA;AAC1C,IAAA,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QACvB,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;QAC/B,IAAI,GAAG,EAAE;AACP,YAAA,MAAM,GAAG,CAAC,IAAI,EAAE;AAChB,YAAA,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;;;AAG5B;AAEO,MAAM,MAAM,GAAiC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,KAAI;IACzF,IAAI,CAAC,SAAS,EAAE;AACd,QAAA,MAAM,IAAI,KAAK,CACb,0BAA0B,EAAE,CA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AAA,MAAM,GAAG,GAAGC,qBAAa,CAAC,MAAM,CAC9B;AACE,QAAA,IAAI,EAAE,cAAc;QACpB,QAAQ;AACR,QAAA,aAAa,EAAE,IAAI;KACpB,EACD,MAAA;AAAQ,KAAA,CACT;AAED,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,IAAI,CAAC;IAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;AACjB,QAAA,IAAI,EAAE,UAAU;AAChB,QAAA,SAAS,EAAE,GAAG;AACf,KAAA,CAAC;AACJ;AAEM,SAAU,uBAAuB,CACrC,SAAwB,EACxB,SAAkB,EAAA;IAElB,MAAM,GAAG,GAAGA,qBAAa,CAAC,aAAa,CAAC,SAAS,CAAC;AAElD,IAAA,OAAO,CAAA,CAAA,EAAI,GAAG,CAAC,IAAI,CAAA,CAAA,EAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS;AAC/C,SAAA,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAA,EAAG,QAAQ,CAAC,SAAS,CAAA,OAAA,EAAU,QAAQ,CAAC,IAAI,GAAG;AACjE,SAAA,IAAI,CAAC,GAAG,CAAC,CAAA,CAAA,EAAI,SAAS,IAAI,EAAE,CAAA,EAAA,EAAK,GAAG,CAAC,IAAI,CAAA,CAAA,CAAG;AACjD;;;;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { STORY_CHANGED } from '@storybook/core-events';
|
|
2
2
|
import Aurelia, { CustomElement } from 'aurelia';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Merges multiple sources into a single object.
|
|
5
6
|
* Sources can be story parameters, args, or story.props.
|
|
@@ -18,13 +19,13 @@ async function teardown(element) {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
const render = (args, { id, component: Component }) => {
|
|
22
23
|
if (!Component) {
|
|
23
24
|
throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);
|
|
24
25
|
}
|
|
25
26
|
return { Component, props: args, template: '' };
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
+
async function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }, canvasElement, bootstrapAppFn) {
|
|
28
29
|
const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;
|
|
29
30
|
const { parameters, component, args } = storyContext;
|
|
30
31
|
let app = appMap.get(canvasElement);
|
|
@@ -76,7 +77,7 @@ export async function renderToCanvas({ storyFn, title, name, showMain, showError
|
|
|
76
77
|
await teardown(canvasElement);
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
+
function bootstrapAureliaApp(story, args, domElement, component) {
|
|
80
81
|
const aurelia = new Aurelia(story.container);
|
|
81
82
|
if (story.items?.length) {
|
|
82
83
|
aurelia.register(...story.items);
|
|
@@ -101,9 +102,12 @@ export function bootstrapAureliaApp(story, args, domElement, component) {
|
|
|
101
102
|
component: app,
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
function createComponentTemplate(component, innerHtml) {
|
|
105
106
|
const def = CustomElement.getDefinition(component);
|
|
106
107
|
return `<${def.name} ${Object.values(def.bindables)
|
|
107
108
|
.map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
|
|
108
109
|
.join(' ')}>${innerHtml ?? ''}</${def.name}>`;
|
|
109
110
|
}
|
|
111
|
+
|
|
112
|
+
export { bootstrapAureliaApp, createComponentTemplate, render, renderToCanvas };
|
|
113
|
+
//# sourceMappingURL=render.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.mjs","sources":["../../src/preview/render.ts"],"sourcesContent":["import { STORY_CHANGED } from '@storybook/core-events';\nimport type { RenderContext, ArgsStoryFn } from '@storybook/types';\nimport type { AureliaRenderer } from './types';\nimport Aurelia, { Constructable, CustomElement } from 'aurelia';\n\ninterface AureliaStoryResult {\n template: string;\n components?: unknown[];\n Component?: unknown;\n container?: any;\n items?: unknown[];\n innerHtml?: string;\n props?: Record<string, any>;\n}\n\n/**\n * Merges multiple sources into a single object.\n * Sources can be story parameters, args, or story.props.\n */\nfunction mergeStoryProps(\n ...sources: Array<Record<string, any> | undefined>\n): Record<string, any> {\n return Object.assign({}, ...sources);\n}\n\n// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, Aurelia>();\n\nasync function teardown(element: HTMLElement) {\n if (appMap.has(element)) {\n const app = appMap.get(element);\n if (app) {\n await app.stop();\n appMap.delete(element);\n }\n }\n}\n\nexport const render: ArgsStoryFn<AureliaRenderer> = (args, { id, component: Component }) => {\n if (!Component) {\n throw new Error(\n `Unable to render story ${id} as the component annotation is missing from the default export`\n );\n }\n return { Component, props: args, template: '' };\n};\n\nexport async function renderToCanvas(\n {\n storyFn,\n title,\n name,\n showMain,\n showError,\n storyContext,\n forceRemount,\n }: RenderContext<AureliaRenderer>,\n canvasElement: HTMLElement,\n bootstrapAppFn?: typeof bootstrapAureliaApp\n) {\n const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;\n\n const { parameters, component, args } = storyContext;\n let app = appMap.get(canvasElement);\n\n const story = storyFn() as AureliaStoryResult;\n\n if (!story) {\n showError({\n title: `Expecting an Aurelia component from the story: \"${name}\" of \"${title}\".`,\n description: `\n Did you forget to return the Aurelia component from the story?\n Use \"() => ({ template: '<custom-component></custom-component>' })\" when defining the story.\n `,\n });\n return () => {};\n }\n\n showMain();\n\n let mergedProps;\n // Use full merge (including story.props) when bootstrapping a new app or force remounting.\n if (!app || forceRemount) {\n mergedProps = mergeStoryProps(parameters?.args, args, story.props);\n if (app) {\n await teardown(canvasElement);\n }\n app = appBootstrapFn(\n story,\n mergedProps,\n canvasElement,\n component as Constructable\n ) as Aurelia;\n await app.start();\n appMap.set(canvasElement, app);\n } else {\n // Update the existing app viewModel only with parameters and args (exclude story.props).\n mergedProps = mergeStoryProps(parameters?.args, args);\n if (app.root?.controller?.viewModel) {\n Object.assign(app.root.controller.viewModel, mergedProps);\n }\n }\n\n // Set up story change listener for cleanup\n const channel = storyContext.viewMode === 'story' ? storyContext.channel : null;\n let onStoryChange: () => void;\n if (channel) {\n onStoryChange = () => {\n // When the story changes, clean up the Aurelia app\n teardown(canvasElement);\n };\n channel.on(STORY_CHANGED, onStoryChange);\n }\n\n // Return teardown function that also unsubscribes from STORY_CHANGED\n return async () => {\n if (channel && onStoryChange) {\n channel.off(STORY_CHANGED, onStoryChange);\n }\n await teardown(canvasElement);\n };\n}\n\nexport function bootstrapAureliaApp(\n story: AureliaStoryResult,\n args: Record<string, any>,\n domElement: HTMLElement,\n component?: Constructable\n) {\n const aurelia = new Aurelia(story.container);\n\n if (story.items?.length) {\n aurelia.register(...story.items);\n }\n\n if (story.components?.length) {\n aurelia.register(...story.components);\n }\n\n let { template } = story;\n\n if (component) {\n template = template ?? createComponentTemplate(component, story.innerHtml);\n aurelia.register(component);\n }\n\n const App = CustomElement.define(\n {\n name: 'au-storybook',\n template,\n containerless: true,\n },\n class {}\n );\n\n const app = Object.assign(new App(), args);\n\n return aurelia.app({\n host: domElement,\n component: app,\n });\n}\n\nexport function createComponentTemplate(\n component: Constructable,\n innerHtml?: string\n): string {\n const def = CustomElement.getDefinition(component);\n\n return `<${def.name} ${Object.values(def.bindables)\n .map((bindable) => `${bindable.attribute}.bind=\"${bindable.name}\"`)\n .join(' ')}>${innerHtml ?? ''}</${def.name}>`;\n}"],"names":[],"mappings":";;;AAeA;;;AAGG;AACH,SAAS,eAAe,CACtB,GAAG,OAA+C,EAAA;IAElD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,OAAO,CAAC;AACtC;AAEA;AACA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAwB;AAE9C,eAAe,QAAQ,CAAC,OAAoB,EAAA;AAC1C,IAAA,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QACvB,MAAM,GAAG,GAAG,MAAM,CA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":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@storybook/core-events');
|
|
4
|
+
var Aurelia = require('aurelia');
|
|
5
|
+
|
|
6
|
+
function bootstrapAureliaApp(story, args, domElement, component) {
|
|
7
|
+
const aurelia = new Aurelia(story.container);
|
|
8
|
+
if (story.items?.length) {
|
|
9
|
+
aurelia.register(...story.items);
|
|
10
|
+
}
|
|
11
|
+
if (story.components?.length) {
|
|
12
|
+
aurelia.register(...story.components);
|
|
13
|
+
}
|
|
14
|
+
let { template } = story;
|
|
15
|
+
if (component) {
|
|
16
|
+
template = template ?? createComponentTemplate(component, story.innerHtml);
|
|
17
|
+
aurelia.register(component);
|
|
18
|
+
}
|
|
19
|
+
const App = Aurelia.CustomElement.define({
|
|
20
|
+
name: 'au-storybook',
|
|
21
|
+
template,
|
|
22
|
+
containerless: true,
|
|
23
|
+
}, class {
|
|
24
|
+
});
|
|
25
|
+
const app = Object.assign(new App(), args);
|
|
26
|
+
return aurelia.app({
|
|
27
|
+
host: domElement,
|
|
28
|
+
component: app,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function createComponentTemplate(component, innerHtml) {
|
|
32
|
+
const def = Aurelia.CustomElement.getDefinition(component);
|
|
33
|
+
return `<${def.name} ${Object.values(def.bindables)
|
|
34
|
+
.map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
|
|
35
|
+
.join(' ')}>${innerHtml ?? ''}</${def.name}>`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Track the current story's cleanup function
|
|
39
|
+
let currentCleanup = null;
|
|
40
|
+
const render = (args, context) => {
|
|
41
|
+
// Clean up previous story if exists
|
|
42
|
+
if (currentCleanup) {
|
|
43
|
+
currentCleanup();
|
|
44
|
+
currentCleanup = null;
|
|
45
|
+
}
|
|
46
|
+
// Create a container element
|
|
47
|
+
const container = document.createElement('div');
|
|
48
|
+
// Get the story function result
|
|
49
|
+
const story = context.storyFn();
|
|
50
|
+
// Bootstrap Aurelia app immediately
|
|
51
|
+
if (story && (story.Component || story.template)) {
|
|
52
|
+
const app = bootstrapAureliaApp(story, args, container, story.Component || context.component);
|
|
53
|
+
// Start the app asynchronously
|
|
54
|
+
const startPromise = app.start();
|
|
55
|
+
if (startPromise && typeof startPromise.catch === 'function') {
|
|
56
|
+
startPromise.catch((error) => {
|
|
57
|
+
console.error('Failed to start Aurelia app:', error);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// Set cleanup function
|
|
61
|
+
currentCleanup = () => {
|
|
62
|
+
const stopPromise = app.stop();
|
|
63
|
+
if (stopPromise && typeof stopPromise.catch === 'function') {
|
|
64
|
+
stopPromise.catch((error) => {
|
|
65
|
+
console.error('Failed to stop Aurelia app:', error);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Return the container element immediately
|
|
71
|
+
return container;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.render = render;
|
|
75
|
+
//# sourceMappingURL=preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.js","sources":["../src/preview/render.ts","../src/preview.ts"],"sourcesContent":["import { STORY_CHANGED } from '@storybook/core-events';\nimport type { RenderContext, ArgsStoryFn } from '@storybook/types';\nimport type { AureliaRenderer } from './types';\nimport Aurelia, { Constructable, CustomElement } from 'aurelia';\n\ninterface AureliaStoryResult {\n template: string;\n components?: unknown[];\n Component?: unknown;\n container?: any;\n items?: unknown[];\n innerHtml?: string;\n props?: Record<string, any>;\n}\n\n/**\n * Merges multiple sources into a single object.\n * Sources can be story parameters, args, or story.props.\n */\nfunction mergeStoryProps(\n ...sources: Array<Record<string, any> | undefined>\n): Record<string, any> {\n return Object.assign({}, ...sources);\n}\n\n// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, Aurelia>();\n\nasync function teardown(element: HTMLElement) {\n if (appMap.has(element)) {\n const app = appMap.get(element);\n if (app) {\n await app.stop();\n appMap.delete(element);\n }\n }\n}\n\nexport const render: ArgsStoryFn<AureliaRenderer> = (args, { id, component: Component }) => {\n if (!Component) {\n throw new Error(\n `Unable to render story ${id} as the component annotation is missing from the default export`\n );\n }\n return { Component, props: args, template: '' };\n};\n\nexport async function renderToCanvas(\n {\n storyFn,\n title,\n name,\n showMain,\n showError,\n storyContext,\n forceRemount,\n }: RenderContext<AureliaRenderer>,\n canvasElement: HTMLElement,\n bootstrapAppFn?: typeof bootstrapAureliaApp\n) {\n const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;\n\n const { parameters, component, args } = storyContext;\n let app = appMap.get(canvasElement);\n\n const story = storyFn() as AureliaStoryResult;\n\n if (!story) {\n showError({\n title: `Expecting an Aurelia component from the story: \"${name}\" of \"${title}\".`,\n description: `\n Did you forget to return the Aurelia component from the story?\n Use \"() => ({ template: '<custom-component></custom-component>' })\" when defining the story.\n `,\n });\n return () => {};\n }\n\n showMain();\n\n let mergedProps;\n // Use full merge (including story.props) when bootstrapping a new app or force remounting.\n if (!app || forceRemount) {\n mergedProps = mergeStoryProps(parameters?.args, args, story.props);\n if (app) {\n await teardown(canvasElement);\n }\n app = appBootstrapFn(\n story,\n mergedProps,\n canvasElement,\n component as Constructable\n ) as Aurelia;\n await app.start();\n appMap.set(canvasElement, app);\n } else {\n // Update the existing app viewModel only with parameters and args (exclude story.props).\n mergedProps = mergeStoryProps(parameters?.args, args);\n if (app.root?.controller?.viewModel) {\n Object.assign(app.root.controller.viewModel, mergedProps);\n }\n }\n\n // Set up story change listener for cleanup\n const channel = storyContext.viewMode === 'story' ? storyContext.channel : null;\n let onStoryChange: () => void;\n if (channel) {\n onStoryChange = () => {\n // When the story changes, clean up the Aurelia app\n teardown(canvasElement);\n };\n channel.on(STORY_CHANGED, onStoryChange);\n }\n\n // Return teardown function that also unsubscribes from STORY_CHANGED\n return async () => {\n if (channel && onStoryChange) {\n channel.off(STORY_CHANGED, onStoryChange);\n }\n await teardown(canvasElement);\n };\n}\n\nexport function bootstrapAureliaApp(\n story: AureliaStoryResult,\n args: Record<string, any>,\n domElement: HTMLElement,\n component?: Constructable\n) {\n const aurelia = new Aurelia(story.container);\n\n if (story.items?.length) {\n aurelia.register(...story.items);\n }\n\n if (story.components?.length) {\n aurelia.register(...story.components);\n }\n\n let { template } = story;\n\n if (component) {\n template = template ?? createComponentTemplate(component, story.innerHtml);\n aurelia.register(component);\n }\n\n const App = CustomElement.define(\n {\n name: 'au-storybook',\n template,\n containerless: true,\n },\n class {}\n );\n\n const app = Object.assign(new App(), args);\n\n return aurelia.app({\n host: domElement,\n component: app,\n });\n}\n\nexport function createComponentTemplate(\n component: Constructable,\n innerHtml?: string\n): string {\n const def = CustomElement.getDefinition(component);\n\n return `<${def.name} ${Object.values(def.bindables)\n .map((bindable) => `${bindable.attribute}.bind=\"${bindable.name}\"`)\n .join(' ')}>${innerHtml ?? ''}</${def.name}>`;\n}","import { renderToCanvas, bootstrapAureliaApp } from './preview/render';\nimport Aurelia from 'aurelia';\n\n// Track the current story's cleanup function\nlet currentCleanup: (() => void) | null = null;\n\nexport const render = (args: any, context: any) => {\n // Clean up previous story if exists\n if (currentCleanup) {\n currentCleanup();\n currentCleanup = null;\n }\n\n // Create a container element\n const container = document.createElement('div');\n \n // Get the story function result\n const story = context.storyFn();\n \n // Bootstrap Aurelia app immediately\n if (story && (story.Component || story.template)) {\n const app = bootstrapAureliaApp(\n story,\n args,\n container,\n story.Component || context.component\n ) as Aurelia;\n \n // Start the app asynchronously\n const startPromise = app.start();\n if (startPromise && typeof startPromise.catch === 'function') {\n startPromise.catch((error: any) => {\n console.error('Failed to start Aurelia app:', error);\n });\n }\n \n // Set cleanup function\n currentCleanup = () => {\n const stopPromise = app.stop();\n if (stopPromise && typeof stopPromise.catch === 'function') {\n stopPromise.catch((error: any) => {\n console.error('Failed to stop Aurelia app:', error);\n });\n }\n };\n }\n \n // Return the container element immediately\n return container;\n}; "],"names":["CustomElement"],"mappings":";;;;;AA2HM,SAAU,mBAAmB,CACjC,KAAyB,EACzB,IAAyB,EACzB,UAAuB,EACvB,SAAyB,EAAA;IAEzB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC;AAE5C,IAAA,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE;QACvB,OAAO,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;;AAGlC,IAAA,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE;QAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC;;AAGvC,IAAA,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK;IAExB,IAAI,SAAS,EAAE;QACb,QAAQ,GAAG,QAAQ,IAAI,uBAAuB,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC;AAC1E,QAAA,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;;AAG7B,IAAA,MAAM,GAAG,GAAGA,qBAAa,CAAC,MAAM,CAC9B;AACE,QAAA,IAAI,EAAE,cAAc;QACpB,QAAQ;AACR,QAAA,aAAa,EAAE,IAAI;KACpB,EACD,MAAA;AAAQ,KAAA,CACT;AAED,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,IAAI,CAAC;IAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;AACjB,QAAA,IAAI,EAAE,UAAU;AAChB,QAAA,SAAS,EAAE,GAAG;AACf,KAAA,CAAC;AACJ;AAEM,SAAU,uBAAuB,CACrC,SAAwB,EACxB,SAAkB,EAAA;IAElB,MAAM,GAAG,GAAGA,qBAAa,CAAC,aAAa,CAA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AI,WAAW,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,EAAE;AAC1D,gBAAA,WAAW,CAAC,KAAK,CAAC,CAAC,KAAU,KAAI;AAC/B,oBAAA,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC;AACrD,iBAAC,CAAC;;AAEN,SAAC;;;AAIH,IAAA,OAAO,SAAS;AAClB;;;;"}
|
package/dist/preview.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import '@storybook/core-events';
|
|
2
|
+
import Aurelia, { CustomElement } from 'aurelia';
|
|
3
|
+
|
|
4
|
+
function bootstrapAureliaApp(story, args, domElement, component) {
|
|
5
|
+
const aurelia = new Aurelia(story.container);
|
|
6
|
+
if (story.items?.length) {
|
|
7
|
+
aurelia.register(...story.items);
|
|
8
|
+
}
|
|
9
|
+
if (story.components?.length) {
|
|
10
|
+
aurelia.register(...story.components);
|
|
11
|
+
}
|
|
12
|
+
let { template } = story;
|
|
13
|
+
if (component) {
|
|
14
|
+
template = template ?? createComponentTemplate(component, story.innerHtml);
|
|
15
|
+
aurelia.register(component);
|
|
16
|
+
}
|
|
17
|
+
const App = CustomElement.define({
|
|
18
|
+
name: 'au-storybook',
|
|
19
|
+
template,
|
|
20
|
+
containerless: true,
|
|
21
|
+
}, class {
|
|
22
|
+
});
|
|
23
|
+
const app = Object.assign(new App(), args);
|
|
24
|
+
return aurelia.app({
|
|
25
|
+
host: domElement,
|
|
26
|
+
component: app,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function createComponentTemplate(component, innerHtml) {
|
|
30
|
+
const def = CustomElement.getDefinition(component);
|
|
31
|
+
return `<${def.name} ${Object.values(def.bindables)
|
|
32
|
+
.map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
|
|
33
|
+
.join(' ')}>${innerHtml ?? ''}</${def.name}>`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Track the current story's cleanup function
|
|
37
|
+
let currentCleanup = null;
|
|
38
|
+
const render = (args, context) => {
|
|
39
|
+
// Clean up previous story if exists
|
|
40
|
+
if (currentCleanup) {
|
|
41
|
+
currentCleanup();
|
|
42
|
+
currentCleanup = null;
|
|
43
|
+
}
|
|
44
|
+
// Create a container element
|
|
45
|
+
const container = document.createElement('div');
|
|
46
|
+
// Get the story function result
|
|
47
|
+
const story = context.storyFn();
|
|
48
|
+
// Bootstrap Aurelia app immediately
|
|
49
|
+
if (story && (story.Component || story.template)) {
|
|
50
|
+
const app = bootstrapAureliaApp(story, args, container, story.Component || context.component);
|
|
51
|
+
// Start the app asynchronously
|
|
52
|
+
const startPromise = app.start();
|
|
53
|
+
if (startPromise && typeof startPromise.catch === 'function') {
|
|
54
|
+
startPromise.catch((error) => {
|
|
55
|
+
console.error('Failed to start Aurelia app:', error);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Set cleanup function
|
|
59
|
+
currentCleanup = () => {
|
|
60
|
+
const stopPromise = app.stop();
|
|
61
|
+
if (stopPromise && typeof stopPromise.catch === 'function') {
|
|
62
|
+
stopPromise.catch((error) => {
|
|
63
|
+
console.error('Failed to stop Aurelia app:', error);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// Return the container element immediately
|
|
69
|
+
return container;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { render };
|
|
73
|
+
//# sourceMappingURL=preview.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.mjs","sources":["../src/preview/render.ts","../src/preview.ts"],"sourcesContent":["import { STORY_CHANGED } from '@storybook/core-events';\nimport type { RenderContext, ArgsStoryFn } from '@storybook/types';\nimport type { AureliaRenderer } from './types';\nimport Aurelia, { Constructable, CustomElement } from 'aurelia';\n\ninterface AureliaStoryResult {\n template: string;\n components?: unknown[];\n Component?: unknown;\n container?: any;\n items?: unknown[];\n innerHtml?: string;\n props?: Record<string, any>;\n}\n\n/**\n * Merges multiple sources into a single object.\n * Sources can be story parameters, args, or story.props.\n */\nfunction mergeStoryProps(\n ...sources: Array<Record<string, any> | undefined>\n): Record<string, any> {\n return Object.assign({}, ...sources);\n}\n\n// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, Aurelia>();\n\nasync function teardown(element: HTMLElement) {\n if (appMap.has(element)) {\n const app = appMap.get(element);\n if (app) {\n await app.stop();\n appMap.delete(element);\n }\n }\n}\n\nexport const render: ArgsStoryFn<AureliaRenderer> = (args, { id, component: Component }) => {\n if (!Component) {\n throw new Error(\n `Unable to render story ${id} as the component annotation is missing from the default export`\n );\n }\n return { Component, props: args, template: '' };\n};\n\nexport async function renderToCanvas(\n {\n storyFn,\n title,\n name,\n showMain,\n showError,\n storyContext,\n forceRemount,\n }: RenderContext<AureliaRenderer>,\n canvasElement: HTMLElement,\n bootstrapAppFn?: typeof bootstrapAureliaApp\n) {\n const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;\n\n const { parameters, component, args } = storyContext;\n let app = appMap.get(canvasElement);\n\n const story = storyFn() as AureliaStoryResult;\n\n if (!story) {\n showError({\n title: `Expecting an Aurelia component from the story: \"${name}\" of \"${title}\".`,\n description: `\n Did you forget to return the Aurelia component from the story?\n Use \"() => ({ template: '<custom-component></custom-component>' })\" when defining the story.\n `,\n });\n return () => {};\n }\n\n showMain();\n\n let mergedProps;\n // Use full merge (including story.props) when bootstrapping a new app or force remounting.\n if (!app || forceRemount) {\n mergedProps = mergeStoryProps(parameters?.args, args, story.props);\n if (app) {\n await teardown(canvasElement);\n }\n app = appBootstrapFn(\n story,\n mergedProps,\n canvasElement,\n component as Constructable\n ) as Aurelia;\n await app.start();\n appMap.set(canvasElement, app);\n } else {\n // Update the existing app viewModel only with parameters and args (exclude story.props).\n mergedProps = mergeStoryProps(parameters?.args, args);\n if (app.root?.controller?.viewModel) {\n Object.assign(app.root.controller.viewModel, mergedProps);\n }\n }\n\n // Set up story change listener for cleanup\n const channel = storyContext.viewMode === 'story' ? storyContext.channel : null;\n let onStoryChange: () => void;\n if (channel) {\n onStoryChange = () => {\n // When the story changes, clean up the Aurelia app\n teardown(canvasElement);\n };\n channel.on(STORY_CHANGED, onStoryChange);\n }\n\n // Return teardown function that also unsubscribes from STORY_CHANGED\n return async () => {\n if (channel && onStoryChange) {\n channel.off(STORY_CHANGED, onStoryChange);\n }\n await teardown(canvasElement);\n };\n}\n\nexport function bootstrapAureliaApp(\n story: AureliaStoryResult,\n args: Record<string, any>,\n domElement: HTMLElement,\n component?: Constructable\n) {\n const aurelia = new Aurelia(story.container);\n\n if (story.items?.length) {\n aurelia.register(...story.items);\n }\n\n if (story.components?.length) {\n aurelia.register(...story.components);\n }\n\n let { template } = story;\n\n if (component) {\n template = template ?? createComponentTemplate(component, story.innerHtml);\n aurelia.register(component);\n }\n\n const App = CustomElement.define(\n {\n name: 'au-storybook',\n template,\n containerless: true,\n },\n class {}\n );\n\n const app = Object.assign(new App(), args);\n\n return aurelia.app({\n host: domElement,\n component: app,\n });\n}\n\nexport function createComponentTemplate(\n component: Constructable,\n innerHtml?: string\n): string {\n const def = CustomElement.getDefinition(component);\n\n return `<${def.name} ${Object.values(def.bindables)\n .map((bindable) => `${bindable.attribute}.bind=\"${bindable.name}\"`)\n .join(' ')}>${innerHtml ?? ''}</${def.name}>`;\n}","import { renderToCanvas, bootstrapAureliaApp } from './preview/render';\nimport Aurelia from 'aurelia';\n\n// Track the current story's cleanup function\nlet currentCleanup: (() => void) | null = null;\n\nexport const render = (args: any, context: any) => {\n // Clean up previous story if exists\n if (currentCleanup) {\n currentCleanup();\n currentCleanup = null;\n }\n\n // Create a container element\n const container = document.createElement('div');\n \n // Get the story function result\n const story = context.storyFn();\n \n // Bootstrap Aurelia app immediately\n if (story && (story.Component || story.template)) {\n const app = bootstrapAureliaApp(\n story,\n args,\n container,\n story.Component || context.component\n ) as Aurelia;\n \n // Start the app asynchronously\n const startPromise = app.start();\n if (startPromise && typeof startPromise.catch === 'function') {\n startPromise.catch((error: any) => {\n console.error('Failed to start Aurelia app:', error);\n });\n }\n \n // Set cleanup function\n currentCleanup = () => {\n const stopPromise = app.stop();\n if (stopPromise && typeof stopPromise.catch === 'function') {\n stopPromise.catch((error: any) => {\n console.error('Failed to stop Aurelia app:', error);\n });\n }\n };\n }\n \n // Return the container element immediately\n return container;\n}; "],"names":[],"mappings":";;;AA2HM,SAAU,mBAAmB,CACjC,KAAyB,EACzB,IAAyB,EACzB,UAAuB,EACvB,SAAyB,EAAA;IAEzB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC;AAE5C,IAAA,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE;QACvB,OAAO,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;;AAGlC,IAAA,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE;QAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC;;AAGvC,IAAA,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK;IAExB,IAAI,SAAS,EAAE;QACb,QAAQ,GAAG,QAAQ,IAAI,uBAAuB,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC;AAC1E,QAAA,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;;AAG7B,IAAA,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAC9B;AACE,QAAA,IAAI,EAAE,cAAc;QACpB,QAAQ;AACR,QAAA,aAAa,EAAE,IAAI;KACpB,EACD,MAAA;AAAQ,KAAA,CACT;AAED,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,IAAI,CAAC;IAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;AACjB,QAAA,IAAI,EAAE,UAAU;AAChB,QAAA,SAAS,EAAE,GAAG;AACf,KAAA,CAAC;AACJ;AAEM,SAAU,uBAAuB,CACrC,SAAwB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K;AACpB,YAAA,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,EAAE;YAC9B,IAAI,WAAW,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,EAAE;AAC1D,gBAAA,WAAW,CAAC,KAAK,CAAC,CAAC,KAAU,KAAI;AAC/B,oBAAA,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC;AACrD,iBAAC,CAAC;;AAEN,SAAC;;;AAIH,IAAA,OAAO,SAAS;AAClB;;;;"}
|
package/dist/webpack.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A set of rules to be added to the webpack configuration.
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
function getRules() {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
test: /\.ts$/i,
|
|
11
|
+
use: ['ts-loader', '@aurelia/webpack-loader'],
|
|
12
|
+
exclude: /node_modules/,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
test: /\.html$/i,
|
|
16
|
+
use: '@aurelia/webpack-loader',
|
|
17
|
+
exclude: /node_modules/,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.getRules = getRules;
|
|
23
|
+
//# sourceMappingURL=webpack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.js","sources":["../src/webpack.ts"],"sourcesContent":["// src/webpack.ts\nimport type { RuleSetRule } from 'webpack';\n\n/**\n * A set of rules to be added to the webpack configuration.\n * @returns\n */\nexport function getRules(): RuleSetRule[] {\n return [\n {\n test: /\\.ts$/i,\n use: ['ts-loader', '@aurelia/webpack-loader'],\n exclude: /node_modules/,\n },\n {\n test: /\\.html$/i,\n use: '@aurelia/webpack-loader',\n exclude: /node_modules/,\n },\n ];\n}\n"],"names":[],"mappings":";;AAGA;;;AAGG;SACa,QAAQ,GAAA;IACtB,OAAO;AACL,QAAA;AACE,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,GAAG,EAAE,CAAC,WAAW,EAAE,yBAAyB,CAAC;AAC7C,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;AACD,QAAA;AACE,YAAA,IAAI,EAAE,UAAU;AAChB,YAAA,GAAG,EAAE,yBAAyB;AAC9B,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;KACF;AACH;;;;"}
|
package/dist/webpack.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of rules to be added to the webpack configuration.
|
|
3
|
+
* @returns
|
|
4
|
+
*/
|
|
5
|
+
function getRules() {
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
test: /\.ts$/i,
|
|
9
|
+
use: ['ts-loader', '@aurelia/webpack-loader'],
|
|
10
|
+
exclude: /node_modules/,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
test: /\.html$/i,
|
|
14
|
+
use: '@aurelia/webpack-loader',
|
|
15
|
+
exclude: /node_modules/,
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { getRules };
|
|
21
|
+
//# sourceMappingURL=webpack.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.mjs","sources":["../src/webpack.ts"],"sourcesContent":["// src/webpack.ts\nimport type { RuleSetRule } from 'webpack';\n\n/**\n * A set of rules to be added to the webpack configuration.\n * @returns\n */\nexport function getRules(): RuleSetRule[] {\n return [\n {\n test: /\\.ts$/i,\n use: ['ts-loader', '@aurelia/webpack-loader'],\n exclude: /node_modules/,\n },\n {\n test: /\\.html$/i,\n use: '@aurelia/webpack-loader',\n exclude: /node_modules/,\n },\n ];\n}\n"],"names":[],"mappings":"AAGA;;;AAGG;SACa,QAAQ,GAAA;IACtB,OAAO;AACL,QAAA;AACE,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,GAAG,EAAE,CAAC,WAAW,EAAE,yBAAyB,CAAC;AAC7C,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;AACD,QAAA;AACE,YAAA,IAAI,EAAE,UAAU;AAChB,YAAA,GAAG,EAAE,yBAAyB;AAC9B,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;KACF;AACH;;;;"}
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,35 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurelia/storybook",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A Storybook plugin to render Aurelia 2 components using Vite",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A Storybook plugin to render Aurelia 2 components using Vite or Webpack",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
7
8
|
"publishConfig": {
|
|
8
9
|
"access": "public"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
|
-
"build": "
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"build": "rollup -c",
|
|
13
|
+
"build:types": "tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
14
|
+
"watch": "rollup -c -w",
|
|
15
|
+
"test": "NODE_OPTIONS=--no-deprecation jest"
|
|
14
16
|
},
|
|
15
17
|
"peerDependencies": {
|
|
16
|
-
"@aurelia/runtime-html": "^2.0.0-beta.
|
|
17
|
-
"@aurelia/vite-plugin": "^2.0.0-beta.
|
|
18
|
+
"@aurelia/runtime-html": "^2.0.0-beta.24",
|
|
19
|
+
"@aurelia/vite-plugin": "^2.0.0-beta.24",
|
|
18
20
|
"@storybook/addons": "^7.6.17",
|
|
19
|
-
"@storybook/builder-vite": "^
|
|
20
|
-
"@storybook/
|
|
21
|
-
"@storybook/core-
|
|
22
|
-
"
|
|
21
|
+
"@storybook/builder-vite": "^9.0.12",
|
|
22
|
+
"@storybook/builder-webpack5": "^9.0.12",
|
|
23
|
+
"@storybook/core-common": "^8.6.14",
|
|
24
|
+
"@storybook/core-events": "^8.6.14",
|
|
25
|
+
"aurelia": "^2.0.0-beta.24"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
28
|
+
"@aurelia/webpack-loader": "^2.0.0-beta.24",
|
|
29
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
30
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
31
|
+
"@rollup/plugin-typescript": "^12.1.3",
|
|
32
|
+
"@storybook/builder-vite": "^9.0.12",
|
|
33
|
+
"@storybook/core-common": "^8.6.14",
|
|
34
|
+
"@storybook/preview-api": "^8.6.14",
|
|
35
|
+
"@storybook/types": "^8.6.14",
|
|
36
|
+
"@types/jest": "^30.0.0",
|
|
37
|
+
"glob": "^11.0.3",
|
|
38
|
+
"jest": "^30.0.2",
|
|
39
|
+
"jest-environment-jsdom": "^30.0.2",
|
|
40
|
+
"rollup": "^4.44.0",
|
|
41
|
+
"ts-jest": "^29.4.0",
|
|
42
|
+
"ts-loader": "^9.5.2",
|
|
43
|
+
"typescript": "^5.8.3"
|
|
44
|
+
},
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"require": "./dist/index.js",
|
|
48
|
+
"import": "./dist/index.mjs"
|
|
49
|
+
},
|
|
50
|
+
"./preset": {
|
|
51
|
+
"require": "./dist/preset.js",
|
|
52
|
+
"import": "./dist/preset.mjs"
|
|
53
|
+
}
|
|
34
54
|
}
|
|
35
55
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import typescript from '@rollup/plugin-typescript';
|
|
2
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
+
import { glob } from 'glob';
|
|
5
|
+
|
|
6
|
+
const external = [
|
|
7
|
+
'@aurelia/runtime-html',
|
|
8
|
+
'@aurelia/vite-plugin',
|
|
9
|
+
'@storybook/addons',
|
|
10
|
+
'@storybook/builder-vite',
|
|
11
|
+
'@storybook/core-common',
|
|
12
|
+
'@storybook/core-events',
|
|
13
|
+
'aurelia'
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
// Get all TypeScript files from src directory
|
|
17
|
+
const srcFiles = glob.sync('src/**/*.ts').reduce((acc, file) => {
|
|
18
|
+
const key = file.replace(/^src\//, '').replace(/\.ts$/, '');
|
|
19
|
+
acc[key] = file;
|
|
20
|
+
return acc;
|
|
21
|
+
}, {});
|
|
22
|
+
|
|
23
|
+
const createConfig = (input, output) => ({
|
|
24
|
+
input,
|
|
25
|
+
output: {
|
|
26
|
+
file: output,
|
|
27
|
+
format: output.endsWith('.mjs') ? 'esm' : 'cjs',
|
|
28
|
+
sourcemap: true,
|
|
29
|
+
exports: 'named'
|
|
30
|
+
},
|
|
31
|
+
plugins: [
|
|
32
|
+
typescript({
|
|
33
|
+
tsconfig: './tsconfig.json',
|
|
34
|
+
declaration: false,
|
|
35
|
+
outDir: 'dist'
|
|
36
|
+
}),
|
|
37
|
+
resolve(),
|
|
38
|
+
commonjs()
|
|
39
|
+
],
|
|
40
|
+
external
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Create configs for all source files
|
|
44
|
+
const configs = Object.entries(srcFiles).flatMap(([name, input]) => [
|
|
45
|
+
// ESM build
|
|
46
|
+
createConfig(input, `dist/${name}.mjs`),
|
|
47
|
+
// CommonJS build
|
|
48
|
+
createConfig(input, `dist/${name}.js`)
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
export default configs;
|
package/src/preset.ts
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
// src/preset.ts
|
|
2
2
|
// Minimal preset for Storybook-Aurelia2
|
|
3
3
|
|
|
4
|
+
import { getRules } from './webpack';
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Optionally adjust the Vite configuration.
|
|
6
8
|
*/
|
|
7
9
|
export async function viteFinal(config: any): Promise<any> {
|
|
8
10
|
// For now, return the config unchanged.
|
|
9
11
|
return config;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A function to configure webpack.
|
|
16
|
+
* @param config
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export async function webpackFinal(config: any): Promise<any> {
|
|
20
|
+
const rules = config.module?.rules;
|
|
21
|
+
if (rules) {
|
|
22
|
+
rules.push(...getRules());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Export a default for compatibility.
|
|
29
|
+
export default { viteFinal, webpackFinal };
|
|
30
|
+
|
|
31
|
+
export const previewAnnotations = [require.resolve('./preview')];
|