@aurelia/storybook 0.1.0 → 0.1.1
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/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 +10 -2
- package/dist/preset.js.map +1 -0
- package/dist/{src/preset.js → preset.mjs} +5 -2
- package/dist/preset.mjs.map +1 -0
- package/dist/preview/render.d.ts +1 -1
- 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/package.json +20 -3
- package/rollup.config.mjs +51 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +1 -0
- package/dist/__tests__/example.test.d.ts +0 -0
- package/dist/__tests__/example.test.js +0 -6
- package/dist/__tests__/render.test.js +0 -156
- package/dist/preview/render.test.d.ts +0 -1
- package/dist/preview/render.test.js +0 -126
- 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/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__ → __tests__}/render.test.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var coreEvents = require('@storybook/core-events');
|
|
4
|
+
var Aurelia = require('aurelia');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Merges multiple sources into a single object.
|
|
8
|
+
* Sources can be story parameters, args, or story.props.
|
|
9
|
+
*/
|
|
10
|
+
function mergeStoryProps(...sources) {
|
|
11
|
+
return Object.assign({}, ...sources);
|
|
12
|
+
}
|
|
13
|
+
// Track Aurelia apps for cleanup
|
|
14
|
+
const appMap = new Map();
|
|
15
|
+
async function teardown(element) {
|
|
16
|
+
if (appMap.has(element)) {
|
|
17
|
+
const app = appMap.get(element);
|
|
18
|
+
if (app) {
|
|
19
|
+
await app.stop();
|
|
20
|
+
appMap.delete(element);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }, canvasElement, bootstrapAppFn) {
|
|
25
|
+
const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;
|
|
26
|
+
const { parameters, component, args } = storyContext;
|
|
27
|
+
let app = appMap.get(canvasElement);
|
|
28
|
+
const story = storyFn();
|
|
29
|
+
if (!story) {
|
|
30
|
+
showError({
|
|
31
|
+
title: `Expecting an Aurelia component from the story: "${name}" of "${title}".`,
|
|
32
|
+
description: `
|
|
33
|
+
Did you forget to return the Aurelia component from the story?
|
|
34
|
+
Use "() => ({ template: '<custom-component></custom-component>' })" when defining the story.
|
|
35
|
+
`,
|
|
36
|
+
});
|
|
37
|
+
return () => { };
|
|
38
|
+
}
|
|
39
|
+
showMain();
|
|
40
|
+
let mergedProps;
|
|
41
|
+
// Use full merge (including story.props) when bootstrapping a new app or force remounting.
|
|
42
|
+
if (!app || forceRemount) {
|
|
43
|
+
mergedProps = mergeStoryProps(parameters?.args, args, story.props);
|
|
44
|
+
if (app) {
|
|
45
|
+
await teardown(canvasElement);
|
|
46
|
+
}
|
|
47
|
+
app = appBootstrapFn(story, mergedProps, canvasElement, component);
|
|
48
|
+
await app.start();
|
|
49
|
+
appMap.set(canvasElement, app);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Update the existing app viewModel only with parameters and args (exclude story.props).
|
|
53
|
+
mergedProps = mergeStoryProps(parameters?.args, args);
|
|
54
|
+
if (app.root?.controller?.viewModel) {
|
|
55
|
+
Object.assign(app.root.controller.viewModel, mergedProps);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Set up story change listener for cleanup
|
|
59
|
+
const channel = storyContext.viewMode === 'story' ? storyContext.channel : null;
|
|
60
|
+
let onStoryChange;
|
|
61
|
+
if (channel) {
|
|
62
|
+
onStoryChange = () => {
|
|
63
|
+
// When the story changes, clean up the Aurelia app
|
|
64
|
+
teardown(canvasElement);
|
|
65
|
+
};
|
|
66
|
+
channel.on(coreEvents.STORY_CHANGED, onStoryChange);
|
|
67
|
+
}
|
|
68
|
+
// Return teardown function that also unsubscribes from STORY_CHANGED
|
|
69
|
+
return async () => {
|
|
70
|
+
if (channel && onStoryChange) {
|
|
71
|
+
channel.off(coreEvents.STORY_CHANGED, onStoryChange);
|
|
72
|
+
}
|
|
73
|
+
await teardown(canvasElement);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function bootstrapAureliaApp(story, args, domElement, component) {
|
|
77
|
+
const aurelia = new Aurelia(story.container);
|
|
78
|
+
if (story.items?.length) {
|
|
79
|
+
aurelia.register(...story.items);
|
|
80
|
+
}
|
|
81
|
+
if (story.components?.length) {
|
|
82
|
+
aurelia.register(...story.components);
|
|
83
|
+
}
|
|
84
|
+
let { template } = story;
|
|
85
|
+
if (component) {
|
|
86
|
+
template = template ?? createComponentTemplate(component, story.innerHtml);
|
|
87
|
+
aurelia.register(component);
|
|
88
|
+
}
|
|
89
|
+
const App = Aurelia.CustomElement.define({
|
|
90
|
+
name: 'au-storybook',
|
|
91
|
+
template,
|
|
92
|
+
containerless: true,
|
|
93
|
+
}, class {
|
|
94
|
+
});
|
|
95
|
+
const app = Object.assign(new App(), args);
|
|
96
|
+
return aurelia.app({
|
|
97
|
+
host: domElement,
|
|
98
|
+
component: app,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function createComponentTemplate(component, innerHtml) {
|
|
102
|
+
const def = Aurelia.CustomElement.getDefinition(component);
|
|
103
|
+
return `<${def.name} ${Object.values(def.bindables)
|
|
104
|
+
.map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
|
|
105
|
+
.join(' ')}>${innerHtml ?? ''}</${def.name}>`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const render = renderToCanvas;
|
|
109
|
+
|
|
110
|
+
exports.render = render;
|
|
111
|
+
exports.renderToCanvas = renderToCanvas;
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/preview/render.ts","../src/index.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 } from './preview/render';\n\nexport { renderToCanvas };\nexport const render = renderToCanvas;\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;AAWO,eAAe,cAAc,CAClC,EACE,OAAO,EACP,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACmB,EACjC,aAA0B,EAC1B,cAA2C,EAAA;AAE3C,IAAA,MAAM,cAAc,GAAG,cAAc,IAAI,mBAAmB;IAE5D,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,YAAY;IACpD,IAAI,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC;AAEnC,IAAA,MAAM,KAAK,GAAG,OAAO,EAAwB;IAE7C,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,SAAS,CAAC;AACR,YAAA,KAAK,EAAE,CAAA,gDAAA,EAAmD,IAAI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AG,CAAC,SAAS;AAC/C,SAAA,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAA,EAAG,QAAQ,CAAC,SAAS,CAAU,OAAA,EAAA,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;;ACzKO,MAAM,MAAM,GAAG;;;;;"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { STORY_CHANGED } from '@storybook/core-events';
|
|
2
|
+
import Aurelia, { CustomElement } from 'aurelia';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Merges multiple sources into a single object.
|
|
6
|
+
* Sources can be story parameters, args, or story.props.
|
|
7
|
+
*/
|
|
8
|
+
function mergeStoryProps(...sources) {
|
|
9
|
+
return Object.assign({}, ...sources);
|
|
10
|
+
}
|
|
11
|
+
// Track Aurelia apps for cleanup
|
|
12
|
+
const appMap = new Map();
|
|
13
|
+
async function teardown(element) {
|
|
14
|
+
if (appMap.has(element)) {
|
|
15
|
+
const app = appMap.get(element);
|
|
16
|
+
if (app) {
|
|
17
|
+
await app.stop();
|
|
18
|
+
appMap.delete(element);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }, canvasElement, bootstrapAppFn) {
|
|
23
|
+
const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;
|
|
24
|
+
const { parameters, component, args } = storyContext;
|
|
25
|
+
let app = appMap.get(canvasElement);
|
|
26
|
+
const story = storyFn();
|
|
27
|
+
if (!story) {
|
|
28
|
+
showError({
|
|
29
|
+
title: `Expecting an Aurelia component from the story: "${name}" of "${title}".`,
|
|
30
|
+
description: `
|
|
31
|
+
Did you forget to return the Aurelia component from the story?
|
|
32
|
+
Use "() => ({ template: '<custom-component></custom-component>' })" when defining the story.
|
|
33
|
+
`,
|
|
34
|
+
});
|
|
35
|
+
return () => { };
|
|
36
|
+
}
|
|
37
|
+
showMain();
|
|
38
|
+
let mergedProps;
|
|
39
|
+
// Use full merge (including story.props) when bootstrapping a new app or force remounting.
|
|
40
|
+
if (!app || forceRemount) {
|
|
41
|
+
mergedProps = mergeStoryProps(parameters?.args, args, story.props);
|
|
42
|
+
if (app) {
|
|
43
|
+
await teardown(canvasElement);
|
|
44
|
+
}
|
|
45
|
+
app = appBootstrapFn(story, mergedProps, canvasElement, component);
|
|
46
|
+
await app.start();
|
|
47
|
+
appMap.set(canvasElement, app);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// Update the existing app viewModel only with parameters and args (exclude story.props).
|
|
51
|
+
mergedProps = mergeStoryProps(parameters?.args, args);
|
|
52
|
+
if (app.root?.controller?.viewModel) {
|
|
53
|
+
Object.assign(app.root.controller.viewModel, mergedProps);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Set up story change listener for cleanup
|
|
57
|
+
const channel = storyContext.viewMode === 'story' ? storyContext.channel : null;
|
|
58
|
+
let onStoryChange;
|
|
59
|
+
if (channel) {
|
|
60
|
+
onStoryChange = () => {
|
|
61
|
+
// When the story changes, clean up the Aurelia app
|
|
62
|
+
teardown(canvasElement);
|
|
63
|
+
};
|
|
64
|
+
channel.on(STORY_CHANGED, onStoryChange);
|
|
65
|
+
}
|
|
66
|
+
// Return teardown function that also unsubscribes from STORY_CHANGED
|
|
67
|
+
return async () => {
|
|
68
|
+
if (channel && onStoryChange) {
|
|
69
|
+
channel.off(STORY_CHANGED, onStoryChange);
|
|
70
|
+
}
|
|
71
|
+
await teardown(canvasElement);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function bootstrapAureliaApp(story, args, domElement, component) {
|
|
75
|
+
const aurelia = new Aurelia(story.container);
|
|
76
|
+
if (story.items?.length) {
|
|
77
|
+
aurelia.register(...story.items);
|
|
78
|
+
}
|
|
79
|
+
if (story.components?.length) {
|
|
80
|
+
aurelia.register(...story.components);
|
|
81
|
+
}
|
|
82
|
+
let { template } = story;
|
|
83
|
+
if (component) {
|
|
84
|
+
template = template ?? createComponentTemplate(component, story.innerHtml);
|
|
85
|
+
aurelia.register(component);
|
|
86
|
+
}
|
|
87
|
+
const App = CustomElement.define({
|
|
88
|
+
name: 'au-storybook',
|
|
89
|
+
template,
|
|
90
|
+
containerless: true,
|
|
91
|
+
}, class {
|
|
92
|
+
});
|
|
93
|
+
const app = Object.assign(new App(), args);
|
|
94
|
+
return aurelia.app({
|
|
95
|
+
host: domElement,
|
|
96
|
+
component: app,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function createComponentTemplate(component, innerHtml) {
|
|
100
|
+
const def = CustomElement.getDefinition(component);
|
|
101
|
+
return `<${def.name} ${Object.values(def.bindables)
|
|
102
|
+
.map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
|
|
103
|
+
.join(' ')}>${innerHtml ?? ''}</${def.name}>`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const render = renderToCanvas;
|
|
107
|
+
|
|
108
|
+
export { render, renderToCanvas };
|
|
109
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/preview/render.ts","../src/index.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 } from './preview/render';\n\nexport { renderToCanvas };\nexport const render = renderToCanvas;\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,CAAC,GAAG,CAAC,OAAO,CAAC;QAC/B,IAAI,GAAG,EAAE;AACP,YAAA,MAAM,GAAG,CAAC,IAAI,EAAE;AAChB,YAAA,MAAM,CAAC,MAAM,CAAC,OAAO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AA,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;AAEgB,SAAA,uBAAuB,CACrC,SAAwB,EACxB,SAAkB,EAAA;IAElB,MAAM,GAAG,GAAG,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC;AAElD,IAAA,OAAO,CAAI,CAAA,EAAA,GAAG,CAAC,IAAI,CAAI,CAAA,EAAA,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS;AAC/C,SAAA,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAA,EAAG,QAAQ,CAAC,SAAS,CAAU,OAAA,EAAA,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;;ACzKO,MAAM,MAAM,GAAG;;;;"}
|
package/dist/preset.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
1
5
|
// src/preset.ts
|
|
2
6
|
// Minimal preset for Storybook-Aurelia2
|
|
3
7
|
/**
|
|
4
8
|
* Optionally adjust the Vite configuration.
|
|
5
9
|
*/
|
|
6
|
-
|
|
10
|
+
async function viteFinal(config) {
|
|
7
11
|
// For now, return the config unchanged.
|
|
8
12
|
return config;
|
|
9
13
|
}
|
|
10
14
|
// Export a default for compatibility.
|
|
11
|
-
|
|
15
|
+
var preset = { viteFinal };
|
|
16
|
+
|
|
17
|
+
exports.default = preset;
|
|
18
|
+
exports.viteFinal = viteFinal;
|
|
19
|
+
//# sourceMappingURL=preset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.js","sources":["../src/preset.ts"],"sourcesContent":["// src/preset.ts\n// Minimal preset for Storybook-Aurelia2\n\n/**\n * Optionally adjust the Vite configuration.\n */\nexport async function viteFinal(config: any): Promise<any> {\n // For now, return the config unchanged.\n return config;\n }\n \n // Export a default for compatibility.\n export default { viteFinal };\n "],"names":[],"mappings":";;;;AAAA;AACA;AAEA;;AAEG;AACI,eAAe,SAAS,CAAC,MAAW,EAAA;;AAEvC,IAAA,OAAO,MAAM;AACf;AAEA;AACA,aAAe,EAAE,SAAS,EAAE;;;;;"}
|
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Optionally adjust the Vite configuration.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
async function viteFinal(config) {
|
|
7
7
|
// For now, return the config unchanged.
|
|
8
8
|
return config;
|
|
9
9
|
}
|
|
10
10
|
// Export a default for compatibility.
|
|
11
|
-
|
|
11
|
+
var preset = { viteFinal };
|
|
12
|
+
|
|
13
|
+
export { preset as default, viteFinal };
|
|
14
|
+
//# sourceMappingURL=preset.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.mjs","sources":["../src/preset.ts"],"sourcesContent":["// src/preset.ts\n// Minimal preset for Storybook-Aurelia2\n\n/**\n * Optionally adjust the Vite configuration.\n */\nexport async function viteFinal(config: any): Promise<any> {\n // For now, return the config unchanged.\n return config;\n }\n \n // Export a default for compatibility.\n export default { viteFinal };\n "],"names":[],"mappings":"AAAA;AACA;AAEA;;AAEG;AACI,eAAe,SAAS,CAAC,MAAW,EAAA;;AAEvC,IAAA,OAAO,MAAM;AACf;AAEA;AACA,aAAe,EAAE,SAAS,EAAE;;;;"}
|
package/dist/preview/render.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ interface AureliaStoryResult {
|
|
|
11
11
|
props?: Record<string, any>;
|
|
12
12
|
}
|
|
13
13
|
export declare const render: ArgsStoryFn<AureliaRenderer>;
|
|
14
|
-
export declare function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }: RenderContext<AureliaRenderer>, canvasElement: HTMLElement): Promise<() => void>;
|
|
14
|
+
export declare function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }: RenderContext<AureliaRenderer>, canvasElement: HTMLElement, bootstrapAppFn?: typeof bootstrapAureliaApp): Promise<() => void>;
|
|
15
15
|
export declare function bootstrapAureliaApp(story: AureliaStoryResult, args: Record<string, any>, domElement: HTMLElement, component?: Constructable): Omit<Aurelia, "enhance" | "register" | "app">;
|
|
16
16
|
export declare function createComponentTemplate(component: Constructable, innerHtml?: string): string;
|
|
17
17
|
export {};
|
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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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":";;;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AAA,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAA,EAAG,QAAQ,CAAC,SAAS,CAAU,OAAA,EAAA,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;;;;"}
|
package/dist/preview/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurelia/storybook",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A Storybook plugin to render Aurelia 2 components using Vite",
|
|
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
|
-
"
|
|
12
|
+
"build": "rollup -c",
|
|
13
|
+
"build:types": "tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
14
|
+
"watch": "rollup -c -w",
|
|
13
15
|
"test": "jest"
|
|
14
16
|
},
|
|
15
17
|
"peerDependencies": {
|
|
@@ -22,14 +24,29 @@
|
|
|
22
24
|
"aurelia": "^2.0.0-beta.23"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
27
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
28
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
29
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
25
30
|
"@storybook/builder-vite": "^8.5.3",
|
|
26
31
|
"@storybook/core-common": "^8.5.3",
|
|
27
32
|
"@storybook/preview-api": "^8.5.3",
|
|
28
33
|
"@storybook/types": "^8.5.3",
|
|
29
34
|
"@types/jest": "^29.5.14",
|
|
35
|
+
"glob": "^11.0.1",
|
|
30
36
|
"jest": "^29.7.0",
|
|
31
37
|
"jest-environment-jsdom": "^29.7.0",
|
|
38
|
+
"rollup": "^4.34.2",
|
|
32
39
|
"ts-jest": "^29.2.5",
|
|
33
40
|
"typescript": "^5.7.3"
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"require": "./dist/index.js",
|
|
45
|
+
"import": "./dist/index.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./preset": {
|
|
48
|
+
"require": "./dist/preset.js",
|
|
49
|
+
"import": "./dist/preset.mjs"
|
|
50
|
+
}
|
|
34
51
|
}
|
|
35
52
|
}
|
|
@@ -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/tsconfig.json
CHANGED
|
File without changes
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { STORY_CHANGED } from '@storybook/core-events';
|
|
2
|
-
import { render, renderToCanvas, bootstrapAureliaApp, createComponentTemplate, } from '../src/preview/render';
|
|
3
|
-
// Add this at the very top of the file, before any imports.
|
|
4
|
-
jest.mock('aurelia', () => {
|
|
5
|
-
const actual = jest.requireActual('aurelia');
|
|
6
|
-
return {
|
|
7
|
-
...actual,
|
|
8
|
-
CustomElement: {
|
|
9
|
-
...actual.CustomElement,
|
|
10
|
-
getDefinition: jest.fn().mockReturnValue({
|
|
11
|
-
name: 'dummy-comp',
|
|
12
|
-
bindables: { prop: { attribute: 'prop', name: 'prop' } },
|
|
13
|
-
}),
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
describe('render', () => {
|
|
18
|
-
it('throws an error when no component is provided', () => {
|
|
19
|
-
expect(() => render({}, { id: 'story-1', component: undefined })).toThrowError('Unable to render story story-1 as the component annotation is missing from the default export');
|
|
20
|
-
});
|
|
21
|
-
it('returns the expected object when a component is provided', () => {
|
|
22
|
-
const DummyComponent = () => { };
|
|
23
|
-
const args = { foo: 'bar' };
|
|
24
|
-
const result = render(args, { id: 'story-1', component: DummyComponent });
|
|
25
|
-
expect(result).toEqual({ Component: DummyComponent, props: args, template: '' });
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe('renderToCanvas', () => {
|
|
29
|
-
let canvas;
|
|
30
|
-
let dummyChannel;
|
|
31
|
-
const DummyComponent = class {
|
|
32
|
-
};
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
canvas = document.createElement('div');
|
|
35
|
-
dummyChannel = { on: jest.fn(), off: jest.fn() };
|
|
36
|
-
});
|
|
37
|
-
it('calls showError when the story function returns a falsy value', async () => {
|
|
38
|
-
const storyFn = jest.fn(() => null);
|
|
39
|
-
const showError = jest.fn();
|
|
40
|
-
const showMain = jest.fn();
|
|
41
|
-
const context = {
|
|
42
|
-
storyFn,
|
|
43
|
-
title: 'Test Title',
|
|
44
|
-
name: 'Test Story',
|
|
45
|
-
showMain,
|
|
46
|
-
showError,
|
|
47
|
-
storyContext: {
|
|
48
|
-
parameters: {},
|
|
49
|
-
component: DummyComponent,
|
|
50
|
-
args: {},
|
|
51
|
-
viewMode: 'story',
|
|
52
|
-
channel: dummyChannel,
|
|
53
|
-
},
|
|
54
|
-
forceRemount: false,
|
|
55
|
-
};
|
|
56
|
-
const cleanup = await renderToCanvas(context, canvas);
|
|
57
|
-
expect(showError).toHaveBeenCalled();
|
|
58
|
-
expect(typeof cleanup).toBe('function');
|
|
59
|
-
});
|
|
60
|
-
it('bootstraps an Aurelia app when none exists or forceRemount is true', async () => {
|
|
61
|
-
const fakeAurelia = {
|
|
62
|
-
start: jest.fn().mockResolvedValue(undefined),
|
|
63
|
-
stop: jest.fn().mockResolvedValue(undefined),
|
|
64
|
-
root: { controller: { viewModel: {} } },
|
|
65
|
-
};
|
|
66
|
-
const story = { template: '<div></div>', props: { test: 'value' } };
|
|
67
|
-
const storyFn = jest.fn(() => story);
|
|
68
|
-
const showError = jest.fn();
|
|
69
|
-
const showMain = jest.fn();
|
|
70
|
-
// Spy on bootstrapAureliaApp to simulate app creation.
|
|
71
|
-
const bootstrapSpy = jest
|
|
72
|
-
.spyOn(require('../src/preview/render'), 'bootstrapAureliaApp')
|
|
73
|
-
.mockReturnValue(fakeAurelia);
|
|
74
|
-
const context = {
|
|
75
|
-
storyFn,
|
|
76
|
-
title: 'Test Title',
|
|
77
|
-
name: 'Test Story',
|
|
78
|
-
showMain,
|
|
79
|
-
showError,
|
|
80
|
-
storyContext: {
|
|
81
|
-
parameters: { args: { param: 'foo' } },
|
|
82
|
-
component: DummyComponent,
|
|
83
|
-
args: { test: 'bar' },
|
|
84
|
-
viewMode: 'story',
|
|
85
|
-
channel: dummyChannel,
|
|
86
|
-
},
|
|
87
|
-
forceRemount: false,
|
|
88
|
-
};
|
|
89
|
-
const cleanup = await renderToCanvas(context, canvas, bootstrapAureliaApp);
|
|
90
|
-
expect(showError).not.toHaveBeenCalled();
|
|
91
|
-
expect(showMain).toHaveBeenCalled();
|
|
92
|
-
expect(bootstrapSpy).toHaveBeenCalled();
|
|
93
|
-
// Simulate cleanup (which should remove the STORY_CHANGED listener)
|
|
94
|
-
await cleanup();
|
|
95
|
-
expect(dummyChannel.off).toHaveBeenCalledWith(STORY_CHANGED, expect.any(Function));
|
|
96
|
-
bootstrapSpy.mockRestore();
|
|
97
|
-
});
|
|
98
|
-
it('updates the existing app viewModel when re-rendering without forceRemount', async () => {
|
|
99
|
-
// Create a fake Aurelia app with a mutable viewModel.
|
|
100
|
-
const fakeViewModel = {};
|
|
101
|
-
const fakeAurelia = {
|
|
102
|
-
start: jest.fn().mockResolvedValue(undefined),
|
|
103
|
-
stop: jest.fn().mockResolvedValue(undefined),
|
|
104
|
-
root: { controller: { viewModel: fakeViewModel } },
|
|
105
|
-
};
|
|
106
|
-
const story = { template: '<div></div>', props: { test: 'initial' } };
|
|
107
|
-
const storyFn = jest.fn(() => story);
|
|
108
|
-
const showError = jest.fn();
|
|
109
|
-
const showMain = jest.fn();
|
|
110
|
-
const bootstrapSpy = jest
|
|
111
|
-
.spyOn(require('../src/preview/render'), 'bootstrapAureliaApp')
|
|
112
|
-
.mockReturnValue(fakeAurelia);
|
|
113
|
-
// First render: bootstrap the app.
|
|
114
|
-
const context = {
|
|
115
|
-
storyFn,
|
|
116
|
-
title: 'Title',
|
|
117
|
-
name: 'Name',
|
|
118
|
-
showMain,
|
|
119
|
-
showError,
|
|
120
|
-
storyContext: {
|
|
121
|
-
parameters: { args: { param: 'foo' } },
|
|
122
|
-
component: DummyComponent,
|
|
123
|
-
args: { test: 'bar' },
|
|
124
|
-
viewMode: 'story',
|
|
125
|
-
channel: dummyChannel,
|
|
126
|
-
},
|
|
127
|
-
forceRemount: false,
|
|
128
|
-
};
|
|
129
|
-
await renderToCanvas(context, canvas, bootstrapAureliaApp);
|
|
130
|
-
expect(bootstrapSpy).toHaveBeenCalledTimes(1);
|
|
131
|
-
// Second render with new args; should update viewModel instead of re-bootstrap.
|
|
132
|
-
const newStory = { template: '<div></div>', props: { test: 'updated' } };
|
|
133
|
-
storyFn.mockReturnValueOnce(newStory);
|
|
134
|
-
const newContext = {
|
|
135
|
-
...context,
|
|
136
|
-
storyContext: {
|
|
137
|
-
...context.storyContext,
|
|
138
|
-
parameters: { args: { param: 'baz' } },
|
|
139
|
-
args: { test: 'qux' },
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
await renderToCanvas(newContext, canvas, bootstrapAureliaApp);
|
|
143
|
-
expect(bootstrapSpy).toHaveBeenCalledTimes(1);
|
|
144
|
-
expect(fakeViewModel).toEqual({ param: 'baz', test: 'qux' });
|
|
145
|
-
bootstrapSpy.mockRestore();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe('createComponentTemplate', () => {
|
|
149
|
-
it('generates the correct template string', () => {
|
|
150
|
-
const DummyComponent = class {
|
|
151
|
-
};
|
|
152
|
-
// The definition is already provided via module mocking.
|
|
153
|
-
const template = createComponentTemplate(DummyComponent, '<span>inner</span>');
|
|
154
|
-
expect(template).toBe('<dummy-comp prop.bind="prop"><span>inner</span></dummy-comp>');
|
|
155
|
-
});
|
|
156
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { render, renderToCanvas, createComponentTemplate } from './render';
|
|
2
|
-
import { STORY_CHANGED } from '@storybook/core-events';
|
|
3
|
-
import { CustomElement } from 'aurelia';
|
|
4
|
-
// Dummy component for testing
|
|
5
|
-
class DummyComponent {
|
|
6
|
-
}
|
|
7
|
-
// ----------------------
|
|
8
|
-
// Tests for render()
|
|
9
|
-
// ----------------------
|
|
10
|
-
describe('render()', () => {
|
|
11
|
-
test('should return object with component, props, and empty template', () => {
|
|
12
|
-
const args = { foo: 'bar' };
|
|
13
|
-
const context = { id: 'story-1', component: DummyComponent };
|
|
14
|
-
const result = render(args, context);
|
|
15
|
-
expect(result).toEqual({ Component: DummyComponent, props: args, template: '' });
|
|
16
|
-
});
|
|
17
|
-
test('should throw error if component is missing', () => {
|
|
18
|
-
const args = {};
|
|
19
|
-
const context = { id: 'story-2', component: undefined };
|
|
20
|
-
expect(() => render(args, context)).toThrowError(/Unable to render story/);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
// ----------------------
|
|
24
|
-
// Tests for createComponentTemplate()
|
|
25
|
-
// ----------------------
|
|
26
|
-
describe('createComponentTemplate()', () => {
|
|
27
|
-
test('should return a proper template string', () => {
|
|
28
|
-
// Create a fake definition for the dummy component
|
|
29
|
-
const fakeDefinition = {
|
|
30
|
-
name: 'dummy-comp',
|
|
31
|
-
bindables: {
|
|
32
|
-
prop1: { attribute: 'data-prop', name: 'prop1' },
|
|
33
|
-
prop2: { attribute: 'data-attr', name: 'prop2' }
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
// Spy on CustomElement.getDefinition to return our fake definition
|
|
37
|
-
const getDefinitionSpy = jest
|
|
38
|
-
.spyOn(CustomElement, 'getDefinition')
|
|
39
|
-
.mockReturnValue(fakeDefinition);
|
|
40
|
-
const template = createComponentTemplate(DummyComponent, 'inner content');
|
|
41
|
-
expect(template).toBe('<dummy-comp data-prop.bind="prop1" data-attr.bind="prop2">inner content</dummy-comp>');
|
|
42
|
-
// Restore the original function
|
|
43
|
-
getDefinitionSpy.mockRestore();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
// ----------------------
|
|
47
|
-
// Tests for renderToCanvas()
|
|
48
|
-
// ----------------------
|
|
49
|
-
describe('renderToCanvas()', () => {
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
// If needed, clear/reset any globals here.
|
|
52
|
-
});
|
|
53
|
-
test('should call showError if the story is undefined', async () => {
|
|
54
|
-
const canvasElement = document.createElement('div');
|
|
55
|
-
const showError = jest.fn();
|
|
56
|
-
const showMain = jest.fn();
|
|
57
|
-
// storyFn returns undefined to simulate missing Aurelia story result
|
|
58
|
-
const storyFn = jest.fn(() => undefined);
|
|
59
|
-
const storyContext = {
|
|
60
|
-
parameters: { args: { a: 1 } },
|
|
61
|
-
args: { b: 2 },
|
|
62
|
-
component: DummyComponent,
|
|
63
|
-
viewMode: 'story',
|
|
64
|
-
channel: { on: jest.fn(), off: jest.fn() }
|
|
65
|
-
};
|
|
66
|
-
const context = {
|
|
67
|
-
storyFn,
|
|
68
|
-
title: 'Test Title',
|
|
69
|
-
name: 'Test Story',
|
|
70
|
-
showMain,
|
|
71
|
-
showError,
|
|
72
|
-
forceRemount: false,
|
|
73
|
-
storyContext
|
|
74
|
-
};
|
|
75
|
-
// Calling renderToCanvas should immediately call showError.
|
|
76
|
-
const teardownFn = await renderToCanvas(context, canvasElement);
|
|
77
|
-
expect(showError).toHaveBeenCalled();
|
|
78
|
-
// Teardown function exists even if error occurred.
|
|
79
|
-
await teardownFn();
|
|
80
|
-
});
|
|
81
|
-
test('should bootstrap Aurelia app and execute teardown properly', async () => {
|
|
82
|
-
const canvasElement = document.createElement('div');
|
|
83
|
-
const showError = jest.fn();
|
|
84
|
-
const showMain = jest.fn();
|
|
85
|
-
const fakeChannel = { on: jest.fn(), off: jest.fn() };
|
|
86
|
-
// A valid Aurelia story result
|
|
87
|
-
const storyResult = { template: '<div></div>', container: {} };
|
|
88
|
-
const storyFn = jest.fn(() => storyResult);
|
|
89
|
-
const storyContext = {
|
|
90
|
-
parameters: { args: { testProp: true } },
|
|
91
|
-
args: { testProp: false },
|
|
92
|
-
component: DummyComponent,
|
|
93
|
-
viewMode: 'story',
|
|
94
|
-
channel: fakeChannel
|
|
95
|
-
};
|
|
96
|
-
const context = {
|
|
97
|
-
storyFn,
|
|
98
|
-
title: 'Success Title',
|
|
99
|
-
name: 'Success Story',
|
|
100
|
-
showMain,
|
|
101
|
-
showError,
|
|
102
|
-
forceRemount: false,
|
|
103
|
-
storyContext
|
|
104
|
-
};
|
|
105
|
-
// Fake Aurelia instance with start and stop methods
|
|
106
|
-
const fakeAurelia = {
|
|
107
|
-
start: jest.fn().mockResolvedValue(undefined),
|
|
108
|
-
stop: jest.fn().mockResolvedValue(undefined),
|
|
109
|
-
root: { controller: { viewModel: {} } }
|
|
110
|
-
};
|
|
111
|
-
// Stub bootstrapAureliaApp to return our fake Aurelia instance.
|
|
112
|
-
const { bootstrapAureliaApp } = await import('./render');
|
|
113
|
-
const bootstrapSpy = jest
|
|
114
|
-
.spyOn(require('./render'), 'bootstrapAureliaApp')
|
|
115
|
-
.mockResolvedValue(fakeAurelia);
|
|
116
|
-
const teardown = await renderToCanvas(context, canvasElement);
|
|
117
|
-
expect(showMain).toHaveBeenCalled();
|
|
118
|
-
expect(fakeChannel.on).toHaveBeenCalledWith(STORY_CHANGED, expect.any(Function));
|
|
119
|
-
expect(fakeAurelia.start).toHaveBeenCalled();
|
|
120
|
-
// Call the teardown function and verify cleanup calls.
|
|
121
|
-
await teardown();
|
|
122
|
-
expect(fakeChannel.off).toHaveBeenCalledWith(STORY_CHANGED, expect.any(Function));
|
|
123
|
-
expect(fakeAurelia.stop).toHaveBeenCalled();
|
|
124
|
-
jest.restoreAllMocks();
|
|
125
|
-
});
|
|
126
|
-
});
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.js
DELETED
package/dist/src/preset.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RenderContext, ArgsStoryFn } from '@storybook/types';
|
|
2
|
-
import type { AureliaRenderer } from './types';
|
|
3
|
-
import Aurelia, { Constructable } from 'aurelia';
|
|
4
|
-
interface AureliaStoryResult {
|
|
5
|
-
template: string;
|
|
6
|
-
components?: unknown[];
|
|
7
|
-
Component?: unknown;
|
|
8
|
-
container?: any;
|
|
9
|
-
items?: unknown[];
|
|
10
|
-
innerHtml?: string;
|
|
11
|
-
props?: Record<string, any>;
|
|
12
|
-
}
|
|
13
|
-
export declare const render: ArgsStoryFn<AureliaRenderer>;
|
|
14
|
-
export declare function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }: RenderContext<AureliaRenderer>, canvasElement: HTMLElement, bootstrapAppFn?: typeof bootstrapAureliaApp): Promise<() => void>;
|
|
15
|
-
export declare function bootstrapAureliaApp(story: AureliaStoryResult, args: Record<string, any>, domElement: HTMLElement, component?: Constructable): Omit<Aurelia, "enhance" | "register" | "app">;
|
|
16
|
-
export declare function createComponentTemplate(component: Constructable, innerHtml?: string): string;
|
|
17
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|