@aurelia/storybook 1.0.1 → 1.0.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"render.mjs","sources":["../../node_modules/storybook/dist/core-events/index.js","../../src/preview/render.ts"],"sourcesContent":["// src/core-events/index.ts\nvar R = /* @__PURE__ */ ((E) => (E.CHANNEL_WS_DISCONNECT = \"channelWSDisconnect\", E.CHANNEL_CREATED = \"channelCreated\", E.CONFIG_ERROR = \"co\\\nnfigError\", E.STORY_INDEX_INVALIDATED = \"storyIndexInvalidated\", E.STORY_SPECIFIED = \"storySpecified\", E.SET_CONFIG = \"setConfig\", E.SET_STORIES =\n\"setStories\", E.SET_INDEX = \"setIndex\", E.SET_CURRENT_STORY = \"setCurrentStory\", E.CURRENT_STORY_WAS_SET = \"currentStoryWasSet\", E.FORCE_RE_RENDER =\n\"forceReRender\", E.FORCE_REMOUNT = \"forceRemount\", E.PRELOAD_ENTRIES = \"preloadStories\", E.STORY_PREPARED = \"storyPrepared\", E.DOCS_PREPARED =\n\"docsPrepared\", E.STORY_CHANGED = \"storyChanged\", E.STORY_UNCHANGED = \"storyUnchanged\", E.STORY_RENDERED = \"storyRendered\", E.STORY_FINISHED =\n\"storyFinished\", E.STORY_MISSING = \"storyMissing\", E.STORY_ERRORED = \"storyErrored\", E.STORY_THREW_EXCEPTION = \"storyThrewException\", E.STORY_RENDER_PHASE_CHANGED =\n\"storyRenderPhaseChanged\", E.STORY_HOT_UPDATED = \"storyHotUpdated\", E.PLAY_FUNCTION_THREW_EXCEPTION = \"playFunctionThrewException\", E.UNHANDLED_ERRORS_WHILE_PLAYING =\n\"unhandledErrorsWhilePlaying\", E.UPDATE_STORY_ARGS = \"updateStoryArgs\", E.STORY_ARGS_UPDATED = \"storyArgsUpdated\", E.RESET_STORY_ARGS = \"res\\\netStoryArgs\", E.SET_FILTER = \"setFilter\", E.SET_GLOBALS = \"setGlobals\", E.UPDATE_GLOBALS = \"updateGlobals\", E.GLOBALS_UPDATED = \"globalsUpda\\\nted\", E.REGISTER_SUBSCRIPTION = \"registerSubscription\", E.PREVIEW_KEYDOWN = \"previewKeydown\", E.PREVIEW_BUILDER_PROGRESS = \"preview_builder_\\\nprogress\", E.SELECT_STORY = \"selectStory\", E.STORIES_COLLAPSE_ALL = \"storiesCollapseAll\", E.STORIES_EXPAND_ALL = \"storiesExpandAll\", E.DOCS_RENDERED =\n\"docsRendered\", E.SHARED_STATE_CHANGED = \"sharedStateChanged\", E.SHARED_STATE_SET = \"sharedStateSet\", E.NAVIGATE_URL = \"navigateUrl\", E.UPDATE_QUERY_PARAMS =\n\"updateQueryParams\", E.REQUEST_WHATS_NEW_DATA = \"requestWhatsNewData\", E.RESULT_WHATS_NEW_DATA = \"resultWhatsNewData\", E.SET_WHATS_NEW_CACHE =\n\"setWhatsNewCache\", E.TOGGLE_WHATS_NEW_NOTIFICATIONS = \"toggleWhatsNewNotifications\", E.TELEMETRY_ERROR = \"telemetryError\", E.FILE_COMPONENT_SEARCH_REQUEST =\n\"fileComponentSearchRequest\", E.FILE_COMPONENT_SEARCH_RESPONSE = \"fileComponentSearchResponse\", E.SAVE_STORY_REQUEST = \"saveStoryRequest\", E.\nSAVE_STORY_RESPONSE = \"saveStoryResponse\", E.ARGTYPES_INFO_REQUEST = \"argtypesInfoRequest\", E.ARGTYPES_INFO_RESPONSE = \"argtypesInfoResponse\",\nE.CREATE_NEW_STORYFILE_REQUEST = \"createNewStoryfileRequest\", E.CREATE_NEW_STORYFILE_RESPONSE = \"createNewStoryfileResponse\", E))(R || {}), S = R,\n{\n CHANNEL_WS_DISCONNECT: _,\n CHANNEL_CREATED: T,\n CONFIG_ERROR: O,\n CREATE_NEW_STORYFILE_REQUEST: A,\n CREATE_NEW_STORYFILE_RESPONSE: N,\n CURRENT_STORY_WAS_SET: r,\n DOCS_PREPARED: D,\n DOCS_RENDERED: I,\n FILE_COMPONENT_SEARCH_REQUEST: o,\n FILE_COMPONENT_SEARCH_RESPONSE: C,\n FORCE_RE_RENDER: P,\n FORCE_REMOUNT: L,\n GLOBALS_UPDATED: Y,\n NAVIGATE_URL: a,\n PLAY_FUNCTION_THREW_EXCEPTION: U,\n UNHANDLED_ERRORS_WHILE_PLAYING: H,\n PRELOAD_ENTRIES: G,\n PREVIEW_BUILDER_PROGRESS: W,\n PREVIEW_KEYDOWN: d,\n REGISTER_SUBSCRIPTION: t,\n RESET_STORY_ARGS: p,\n SELECT_STORY: i,\n SET_CONFIG: F,\n SET_CURRENT_STORY: l,\n SET_FILTER: y,\n SET_GLOBALS: e,\n SET_INDEX: c,\n SET_STORIES: h,\n SHARED_STATE_CHANGED: f,\n SHARED_STATE_SET: g,\n STORIES_COLLAPSE_ALL: u,\n STORIES_EXPAND_ALL: s,\n STORY_ARGS_UPDATED: x,\n STORY_CHANGED: m,\n STORY_ERRORED: M,\n STORY_INDEX_INVALIDATED: Q,\n STORY_MISSING: V,\n STORY_PREPARED: w,\n STORY_RENDER_PHASE_CHANGED: B,\n STORY_RENDERED: X,\n STORY_FINISHED: b,\n STORY_SPECIFIED: q,\n STORY_THREW_EXCEPTION: K,\n STORY_UNCHANGED: j,\n STORY_HOT_UPDATED: k,\n UPDATE_GLOBALS: z,\n UPDATE_QUERY_PARAMS: J,\n UPDATE_STORY_ARGS: Z,\n REQUEST_WHATS_NEW_DATA: $,\n RESULT_WHATS_NEW_DATA: n,\n SET_WHATS_NEW_CACHE: v,\n TOGGLE_WHATS_NEW_NOTIFICATIONS: EE,\n TELEMETRY_ERROR: RE,\n SAVE_STORY_REQUEST: SE,\n SAVE_STORY_RESPONSE: _E,\n ARGTYPES_INFO_REQUEST: TE,\n ARGTYPES_INFO_RESPONSE: OE\n} = R;\nexport {\n TE as ARGTYPES_INFO_REQUEST,\n OE as ARGTYPES_INFO_RESPONSE,\n T as CHANNEL_CREATED,\n _ as CHANNEL_WS_DISCONNECT,\n O as CONFIG_ERROR,\n A as CREATE_NEW_STORYFILE_REQUEST,\n N as CREATE_NEW_STORYFILE_RESPONSE,\n r as CURRENT_STORY_WAS_SET,\n D as DOCS_PREPARED,\n I as DOCS_RENDERED,\n o as FILE_COMPONENT_SEARCH_REQUEST,\n C as FILE_COMPONENT_SEARCH_RESPONSE,\n L as FORCE_REMOUNT,\n P as FORCE_RE_RENDER,\n Y as GLOBALS_UPDATED,\n a as NAVIGATE_URL,\n U as PLAY_FUNCTION_THREW_EXCEPTION,\n G as PRELOAD_ENTRIES,\n W as PREVIEW_BUILDER_PROGRESS,\n d as PREVIEW_KEYDOWN,\n t as REGISTER_SUBSCRIPTION,\n $ as REQUEST_WHATS_NEW_DATA,\n p as RESET_STORY_ARGS,\n n as RESULT_WHATS_NEW_DATA,\n SE as SAVE_STORY_REQUEST,\n _E as SAVE_STORY_RESPONSE,\n i as SELECT_STORY,\n F as SET_CONFIG,\n l as SET_CURRENT_STORY,\n y as SET_FILTER,\n e as SET_GLOBALS,\n c as SET_INDEX,\n h as SET_STORIES,\n v as SET_WHATS_NEW_CACHE,\n f as SHARED_STATE_CHANGED,\n g as SHARED_STATE_SET,\n u as STORIES_COLLAPSE_ALL,\n s as STORIES_EXPAND_ALL,\n x as STORY_ARGS_UPDATED,\n m as STORY_CHANGED,\n M as STORY_ERRORED,\n b as STORY_FINISHED,\n k as STORY_HOT_UPDATED,\n Q as STORY_INDEX_INVALIDATED,\n V as STORY_MISSING,\n w as STORY_PREPARED,\n X as STORY_RENDERED,\n B as STORY_RENDER_PHASE_CHANGED,\n q as STORY_SPECIFIED,\n K as STORY_THREW_EXCEPTION,\n j as STORY_UNCHANGED,\n RE as TELEMETRY_ERROR,\n EE as TOGGLE_WHATS_NEW_NOTIFICATIONS,\n H as UNHANDLED_ERRORS_WHILE_PLAYING,\n z as UPDATE_GLOBALS,\n J as UPDATE_QUERY_PARAMS,\n Z as UPDATE_STORY_ARGS,\n S as default\n};\n","import { STORY_CHANGED } from 'storybook/internal/core-events';\nimport type { RenderContext, ArgsStoryFn } from 'storybook/internal/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"],"mappings":";;AAAA;AACG,IAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,qBAAqB,GAAG,qBAAqB,EAAE,CAAC,CAAC,eAAe,GAAG,gBAAgB,EAAE,CAAC,CAAC,YAAY,GAAG;AACzI,UAAU,EAAE,CAAC,CAAC,uB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AAChB,QAAA,SAAS,EAAE,GAAG;AACf,KAAA,CAAC;AACJ;AAEM,SAAU,uBAAuB,CACrC,SAAwB,EACxB,SAAkB,EAAA;IAElB,MAAM,GAAG,GAAG,aAAa,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;;;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"render.mjs","sources":["../../src/preview/render.ts"],"sourcesContent":["import { STORY_CHANGED } from 'storybook/internal/core-events';\nimport type { RenderContext, ArgsStoryFn } from 'storybook/internal/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// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, any>();\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, context) => {\n const { id, component: Component } = context;\n \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 createAureliaApp\n) {\n // Store reference to the original storybook root element\n const rootElement = canvasElement;\n\n // Ensure we have (or create) a single container inside the root where the Aurelia app actually renders\n let hostElement: HTMLElement;\n if (rootElement.id === 'storybook-root') {\n hostElement = rootElement.querySelector('.aurelia-story-container') as HTMLElement;\n if (!hostElement) {\n hostElement = document.createElement('div');\n hostElement.className = 'aurelia-story-container';\n hostElement.style.height = '100%';\n rootElement.appendChild(hostElement);\n }\n } else {\n hostElement = rootElement;\n }\n\n // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe\n const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;\n const { parameters, component, args } = storyContext;\n \n let app = appMap.get(rootElement);\n const story = storyFn() as AureliaStoryResult;\n \n // Temporary debug logging\n console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);\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 if (!app || forceRemount) {\n if (forceRemount && app) {\n await teardown(rootElement);\n app = undefined;\n }\n // Clear container before mounting new app\n hostElement.innerHTML = '';\n\n const mergedProps = { ...parameters?.args, ...args, ...story.props };\n\n const aureliaApp = appBootstrapFn(\n story,\n mergedProps,\n hostElement,\n component as Constructable\n );\n await aureliaApp.start();\n appMap.set(rootElement, aureliaApp);\n app = aureliaApp;\n } else {\n // update existing app props\n const mergedProps = { ...parameters?.args, ...args, ...story.props };\n if (app?.root?.controller?.viewModel) {\n Object.assign(app.root.controller.viewModel, mergedProps);\n }\n }\n\n // Return cleanup fn\n return async () => {\n await teardown(rootElement);\n };\n}\n\nexport function createAureliaApp(\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: 'sb-app',\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;AACA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB;AAE1C,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;MAEa,MAAM,GAAiC,CAAC,IAAI,EAAE,OAAO,KAAI;IACpE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO;IAE5C,IAAI,CAAC,SAAS,EAAE;AACd,QAAA,MAAM,IAAI,KAAK,CACb,0BAA0B,EAAE,CAAA,+DAAA,CAAiE,CAC9F;;IAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;AACjD;AAEO,eAAe,cAAc,CAClC,EACE,OAAO,EACP,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,Y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AA,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,QAAQ;QACd,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,GAAG,aAAa,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;;;;"}
package/dist/preview.js CHANGED
@@ -2,7 +2,85 @@
2
2
 
3
3
  var Aurelia = require('aurelia');
4
4
 
5
- function bootstrapAureliaApp(story, args, domElement, component) {
5
+ // Track Aurelia apps for cleanup
6
+ const appMap = new Map();
7
+ async function teardown(element) {
8
+ if (appMap.has(element)) {
9
+ const app = appMap.get(element);
10
+ if (app) {
11
+ await app.stop();
12
+ appMap.delete(element);
13
+ }
14
+ }
15
+ }
16
+ const render = (args, context) => {
17
+ const { id, component: Component } = context;
18
+ if (!Component) {
19
+ throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);
20
+ }
21
+ return { Component, props: args, template: '' };
22
+ };
23
+ async function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }, canvasElement, bootstrapAppFn) {
24
+ // Store reference to the original storybook root element
25
+ const rootElement = canvasElement;
26
+ // Ensure we have (or create) a single container inside the root where the Aurelia app actually renders
27
+ let hostElement;
28
+ if (rootElement.id === 'storybook-root') {
29
+ hostElement = rootElement.querySelector('.aurelia-story-container');
30
+ if (!hostElement) {
31
+ hostElement = document.createElement('div');
32
+ hostElement.className = 'aurelia-story-container';
33
+ hostElement.style.height = '100%';
34
+ rootElement.appendChild(hostElement);
35
+ }
36
+ }
37
+ else {
38
+ hostElement = rootElement;
39
+ }
40
+ // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe
41
+ const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;
42
+ const { parameters, component, args } = storyContext;
43
+ let app = appMap.get(rootElement);
44
+ const story = storyFn();
45
+ // Temporary debug logging
46
+ console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);
47
+ if (!story) {
48
+ showError({
49
+ title: `Expecting an Aurelia component from the story: "${name}" of "${title}".`,
50
+ description: `
51
+ Did you forget to return the Aurelia component from the story?
52
+ Use "() => ({ template: '<custom-component></custom-component>' })" when defining the story.
53
+ `,
54
+ });
55
+ return () => { };
56
+ }
57
+ showMain();
58
+ if (!app || forceRemount) {
59
+ if (forceRemount && app) {
60
+ await teardown(rootElement);
61
+ app = undefined;
62
+ }
63
+ // Clear container before mounting new app
64
+ hostElement.innerHTML = '';
65
+ const mergedProps = { ...parameters?.args, ...args, ...story.props };
66
+ const aureliaApp = appBootstrapFn(story, mergedProps, hostElement, component);
67
+ await aureliaApp.start();
68
+ appMap.set(rootElement, aureliaApp);
69
+ app = aureliaApp;
70
+ }
71
+ else {
72
+ // update existing app props
73
+ const mergedProps = { ...parameters?.args, ...args, ...story.props };
74
+ if (app?.root?.controller?.viewModel) {
75
+ Object.assign(app.root.controller.viewModel, mergedProps);
76
+ }
77
+ }
78
+ // Return cleanup fn
79
+ return async () => {
80
+ await teardown(rootElement);
81
+ };
82
+ }
83
+ function createAureliaApp(story, args, domElement, component) {
6
84
  const aurelia = new Aurelia(story.container);
7
85
  if (story.items?.length) {
8
86
  aurelia.register(...story.items);
@@ -16,7 +94,7 @@ function bootstrapAureliaApp(story, args, domElement, component) {
16
94
  aurelia.register(component);
17
95
  }
18
96
  const App = Aurelia.CustomElement.define({
19
- name: 'au-storybook',
97
+ name: 'sb-app',
20
98
  template,
21
99
  containerless: true,
22
100
  }, class {
@@ -34,41 +112,6 @@ function createComponentTemplate(component, innerHtml) {
34
112
  .join(' ')}>${innerHtml ?? ''}</${def.name}>`;
35
113
  }
36
114
 
37
- // Track the current story's cleanup function
38
- let currentCleanup = null;
39
- const render = (args, context) => {
40
- // Clean up previous story if exists
41
- if (currentCleanup) {
42
- currentCleanup();
43
- currentCleanup = null;
44
- }
45
- // Create a container element
46
- const container = document.createElement('div');
47
- // Get the story function result
48
- const story = context.storyFn();
49
- // Bootstrap Aurelia app immediately
50
- if (story && (story.Component || story.template)) {
51
- const app = bootstrapAureliaApp(story, args, container, story.Component || context.component);
52
- // Start the app asynchronously
53
- const startPromise = app.start();
54
- if (startPromise && typeof startPromise.catch === 'function') {
55
- startPromise.catch((error) => {
56
- console.error('Failed to start Aurelia app:', error);
57
- });
58
- }
59
- // Set cleanup function
60
- currentCleanup = () => {
61
- const stopPromise = app.stop();
62
- if (stopPromise && typeof stopPromise.catch === 'function') {
63
- stopPromise.catch((error) => {
64
- console.error('Failed to stop Aurelia app:', error);
65
- });
66
- }
67
- };
68
- }
69
- // Return the container element immediately
70
- return container;
71
- };
72
-
73
115
  exports.render = render;
116
+ exports.renderToCanvas = renderToCanvas;
74
117
  //# sourceMappingURL=preview.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"preview.js","sources":["../src/preview/render.ts","../src/preview.ts"],"sourcesContent":["import { STORY_CHANGED } from 'storybook/internal/core-events';\nimport type { RenderContext, ArgsStoryFn } from 'storybook/internal/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,OA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KAAK,CAAC,QAAQ,CAAC,EAAE;AAChD,QAAA,MAAM,GAAG,GAAG,mBAAmB,CAC7B,KAAK,EACL,IAAI,EACJ,SAAS,EACT,KAAK,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAC1B;;AAGZ,QAAA,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,EAAE;QAChC,IAAI,YAAY,IAAI,OAAO,YAAY,CAAC,KAAK,KAAK,UAAU,EAAE;AAC5D,YAAA,YAAY,CAAC,KAAK,CAAC,CAAC,KAAU,KAAI;AAChC,gBAAA,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC;AACtD,aAAC,CAAC;;;QAIJ,cAAc,GAAG,MAAK;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;;;;"}
1
+ {"version":3,"file":"preview.js","sources":["../src/preview/render.ts"],"sourcesContent":["import { STORY_CHANGED } from 'storybook/internal/core-events';\nimport type { RenderContext, ArgsStoryFn } from 'storybook/internal/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// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, any>();\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, context) => {\n const { id, component: Component } = context;\n \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 createAureliaApp\n) {\n // Store reference to the original storybook root element\n const rootElement = canvasElement;\n\n // Ensure we have (or create) a single container inside the root where the Aurelia app actually renders\n let hostElement: HTMLElement;\n if (rootElement.id === 'storybook-root') {\n hostElement = rootElement.querySelector('.aurelia-story-container') as HTMLElement;\n if (!hostElement) {\n hostElement = document.createElement('div');\n hostElement.className = 'aurelia-story-container';\n hostElement.style.height = '100%';\n rootElement.appendChild(hostElement);\n }\n } else {\n hostElement = rootElement;\n }\n\n // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe\n const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;\n const { parameters, component, args } = storyContext;\n \n let app = appMap.get(rootElement);\n const story = storyFn() as AureliaStoryResult;\n \n // Temporary debug logging\n console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);\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 if (!app || forceRemount) {\n if (forceRemount && app) {\n await teardown(rootElement);\n app = undefined;\n }\n // Clear container before mounting new app\n hostElement.innerHTML = '';\n\n const mergedProps = { ...parameters?.args, ...args, ...story.props };\n\n const aureliaApp = appBootstrapFn(\n story,\n mergedProps,\n hostElement,\n component as Constructable\n );\n await aureliaApp.start();\n appMap.set(rootElement, aureliaApp);\n app = aureliaApp;\n } else {\n // update existing app props\n const mergedProps = { ...parameters?.args, ...args, ...story.props };\n if (app?.root?.controller?.viewModel) {\n Object.assign(app.root.controller.viewModel, mergedProps);\n }\n }\n\n // Return cleanup fn\n return async () => {\n await teardown(rootElement);\n };\n}\n\nexport function createAureliaApp(\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: 'sb-app',\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":["CustomElement"],"mappings":";;;;AAeA;AACA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB;AAE1C,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;MAEa,MAAM,GAAiC,CAAC,IAAI,EAAE,OAAO,KAAI;IACpE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO;IAE5C,IAAI,CAAC,SAAS,EAAE;AACd,QAAA,MAAM,IAAI,KAAK,CACb,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,CAAC,IAAI,CAAA,CAAA,CAAG;AACjD;;;;;"}
package/dist/preview.mjs CHANGED
@@ -1,6 +1,84 @@
1
1
  import Aurelia, { CustomElement } from 'aurelia';
2
2
 
3
- function bootstrapAureliaApp(story, args, domElement, component) {
3
+ // Track Aurelia apps for cleanup
4
+ const appMap = new Map();
5
+ async function teardown(element) {
6
+ if (appMap.has(element)) {
7
+ const app = appMap.get(element);
8
+ if (app) {
9
+ await app.stop();
10
+ appMap.delete(element);
11
+ }
12
+ }
13
+ }
14
+ const render = (args, context) => {
15
+ const { id, component: Component } = context;
16
+ if (!Component) {
17
+ throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);
18
+ }
19
+ return { Component, props: args, template: '' };
20
+ };
21
+ async function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }, canvasElement, bootstrapAppFn) {
22
+ // Store reference to the original storybook root element
23
+ const rootElement = canvasElement;
24
+ // Ensure we have (or create) a single container inside the root where the Aurelia app actually renders
25
+ let hostElement;
26
+ if (rootElement.id === 'storybook-root') {
27
+ hostElement = rootElement.querySelector('.aurelia-story-container');
28
+ if (!hostElement) {
29
+ hostElement = document.createElement('div');
30
+ hostElement.className = 'aurelia-story-container';
31
+ hostElement.style.height = '100%';
32
+ rootElement.appendChild(hostElement);
33
+ }
34
+ }
35
+ else {
36
+ hostElement = rootElement;
37
+ }
38
+ // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe
39
+ const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;
40
+ const { parameters, component, args } = storyContext;
41
+ let app = appMap.get(rootElement);
42
+ const story = storyFn();
43
+ // Temporary debug logging
44
+ console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);
45
+ if (!story) {
46
+ showError({
47
+ title: `Expecting an Aurelia component from the story: "${name}" of "${title}".`,
48
+ description: `
49
+ Did you forget to return the Aurelia component from the story?
50
+ Use "() => ({ template: '<custom-component></custom-component>' })" when defining the story.
51
+ `,
52
+ });
53
+ return () => { };
54
+ }
55
+ showMain();
56
+ if (!app || forceRemount) {
57
+ if (forceRemount && app) {
58
+ await teardown(rootElement);
59
+ app = undefined;
60
+ }
61
+ // Clear container before mounting new app
62
+ hostElement.innerHTML = '';
63
+ const mergedProps = { ...parameters?.args, ...args, ...story.props };
64
+ const aureliaApp = appBootstrapFn(story, mergedProps, hostElement, component);
65
+ await aureliaApp.start();
66
+ appMap.set(rootElement, aureliaApp);
67
+ app = aureliaApp;
68
+ }
69
+ else {
70
+ // update existing app props
71
+ const mergedProps = { ...parameters?.args, ...args, ...story.props };
72
+ if (app?.root?.controller?.viewModel) {
73
+ Object.assign(app.root.controller.viewModel, mergedProps);
74
+ }
75
+ }
76
+ // Return cleanup fn
77
+ return async () => {
78
+ await teardown(rootElement);
79
+ };
80
+ }
81
+ function createAureliaApp(story, args, domElement, component) {
4
82
  const aurelia = new Aurelia(story.container);
5
83
  if (story.items?.length) {
6
84
  aurelia.register(...story.items);
@@ -14,7 +92,7 @@ function bootstrapAureliaApp(story, args, domElement, component) {
14
92
  aurelia.register(component);
15
93
  }
16
94
  const App = CustomElement.define({
17
- name: 'au-storybook',
95
+ name: 'sb-app',
18
96
  template,
19
97
  containerless: true,
20
98
  }, class {
@@ -32,41 +110,5 @@ function createComponentTemplate(component, innerHtml) {
32
110
  .join(' ')}>${innerHtml ?? ''}</${def.name}>`;
33
111
  }
34
112
 
35
- // Track the current story's cleanup function
36
- let currentCleanup = null;
37
- const render = (args, context) => {
38
- // Clean up previous story if exists
39
- if (currentCleanup) {
40
- currentCleanup();
41
- currentCleanup = null;
42
- }
43
- // Create a container element
44
- const container = document.createElement('div');
45
- // Get the story function result
46
- const story = context.storyFn();
47
- // Bootstrap Aurelia app immediately
48
- if (story && (story.Component || story.template)) {
49
- const app = bootstrapAureliaApp(story, args, container, story.Component || context.component);
50
- // Start the app asynchronously
51
- const startPromise = app.start();
52
- if (startPromise && typeof startPromise.catch === 'function') {
53
- startPromise.catch((error) => {
54
- console.error('Failed to start Aurelia app:', error);
55
- });
56
- }
57
- // Set cleanup function
58
- currentCleanup = () => {
59
- const stopPromise = app.stop();
60
- if (stopPromise && typeof stopPromise.catch === 'function') {
61
- stopPromise.catch((error) => {
62
- console.error('Failed to stop Aurelia app:', error);
63
- });
64
- }
65
- };
66
- }
67
- // Return the container element immediately
68
- return container;
69
- };
70
-
71
- export { render };
113
+ export { render, renderToCanvas };
72
114
  //# sourceMappingURL=preview.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"preview.mjs","sources":["../src/preview/render.ts","../src/preview.ts"],"sourcesContent":["import { STORY_CHANGED } from 'storybook/internal/core-events';\nimport type { RenderContext, ArgsStoryFn } from 'storybook/internal/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,GAA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AAc,GAAG,IAAI;;;IAIvB,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;;AAG/C,IAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE;;AAG/B,IAAA,IAAI,KAAK,KAAK,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAE;AAChD,QAAA,MAAM,GAAG,GAAG,mBAAmB,CAC7B,KAAK,EACL,IAAI,EACJ,SAAS,EACT,KAAK,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAC1B;;AAGZ,QAAA,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,EAAE;QAChC,IAAI,YAAY,IAAI,OAAO,YAAY,CAAC,KAAK,KAAK,UAAU,EAAE;AAC5D,YAAA,YAAY,CAAC,KAAK,CAAC,CAAC,KAAU,KAAI;AAChC,gBAAA,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC;AACtD,aAAC,CAAC;;;QAIJ,cAAc,GAAG,MAAK;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;;;;"}
1
+ {"version":3,"file":"preview.mjs","sources":["../src/preview/render.ts"],"sourcesContent":["import { STORY_CHANGED } from 'storybook/internal/core-events';\nimport type { RenderContext, ArgsStoryFn } from 'storybook/internal/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// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, any>();\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, context) => {\n const { id, component: Component } = context;\n \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 createAureliaApp\n) {\n // Store reference to the original storybook root element\n const rootElement = canvasElement;\n\n // Ensure we have (or create) a single container inside the root where the Aurelia app actually renders\n let hostElement: HTMLElement;\n if (rootElement.id === 'storybook-root') {\n hostElement = rootElement.querySelector('.aurelia-story-container') as HTMLElement;\n if (!hostElement) {\n hostElement = document.createElement('div');\n hostElement.className = 'aurelia-story-container';\n hostElement.style.height = '100%';\n rootElement.appendChild(hostElement);\n }\n } else {\n hostElement = rootElement;\n }\n\n // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe\n const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;\n const { parameters, component, args } = storyContext;\n \n let app = appMap.get(rootElement);\n const story = storyFn() as AureliaStoryResult;\n \n // Temporary debug logging\n console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);\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 if (!app || forceRemount) {\n if (forceRemount && app) {\n await teardown(rootElement);\n app = undefined;\n }\n // Clear container before mounting new app\n hostElement.innerHTML = '';\n\n const mergedProps = { ...parameters?.args, ...args, ...story.props };\n\n const aureliaApp = appBootstrapFn(\n story,\n mergedProps,\n hostElement,\n component as Constructable\n );\n await aureliaApp.start();\n appMap.set(rootElement, aureliaApp);\n app = aureliaApp;\n } else {\n // update existing app props\n const mergedProps = { ...parameters?.args, ...args, ...story.props };\n if (app?.root?.controller?.viewModel) {\n Object.assign(app.root.controller.viewModel, mergedProps);\n }\n }\n\n // Return cleanup fn\n return async () => {\n await teardown(rootElement);\n };\n}\n\nexport function createAureliaApp(\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: 'sb-app',\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;AACA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB;AAE1C,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;;;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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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurelia/storybook",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
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",
package/rollup.config.mjs CHANGED
@@ -7,7 +7,12 @@ const external = [
7
7
  '@aurelia/runtime-html',
8
8
  '@aurelia/vite-plugin',
9
9
  '@storybook/builder-vite',
10
- 'aurelia'
10
+ 'aurelia',
11
+ 'react',
12
+ 'react-dom',
13
+ 'storybook/internal/core-events',
14
+ 'storybook/internal/types',
15
+ 'storybook/theming'
11
16
  ];
12
17
 
13
18
  // Get all TypeScript files from src directory
package/src/index.ts CHANGED
@@ -1,4 +1,32 @@
1
+ import type { StorybookConfig } from 'storybook/internal/types';
1
2
  import { renderToCanvas } from './preview/render';
2
3
 
3
4
  export { renderToCanvas };
4
5
  export const render = renderToCanvas;
6
+
7
+ // Define the framework
8
+ export const framework = {
9
+ name: '@aurelia/storybook',
10
+ options: {}
11
+ };
12
+
13
+ // Framework configuration for Storybook
14
+ export const frameworkOptions = {
15
+ builder: {
16
+ name: '@storybook/builder-vite',
17
+ options: {}
18
+ }
19
+ };
20
+
21
+ // Export a complete framework configuration
22
+ export const aureliaFramework = {
23
+ name: '@aurelia/storybook',
24
+ options: {},
25
+ builder: '@storybook/builder-vite'
26
+ };
27
+
28
+ // Provide external dependencies configuration
29
+ export const externals = {
30
+ 'react': 'React',
31
+ 'react-dom': 'ReactDOM'
32
+ };
package/src/preset.ts CHANGED
@@ -7,7 +7,25 @@ import { getRules } from './webpack';
7
7
  * Optionally adjust the Vite configuration.
8
8
  */
9
9
  export async function viteFinal(config: any): Promise<any> {
10
- // For now, return the config unchanged.
10
+ // Configure Vite to properly handle dependencies
11
+ config.define = config.define || {};
12
+ config.define['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV || 'development');
13
+
14
+ // Configure optimization deps
15
+ config.optimizeDeps = config.optimizeDeps || {};
16
+ config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
17
+
18
+ // Only exclude Aurelia-specific dependencies that cause issues
19
+ const excludeList = [
20
+ '@aurelia/runtime-html'
21
+ ];
22
+
23
+ excludeList.forEach(dep => {
24
+ if (!config.optimizeDeps.exclude.includes(dep)) {
25
+ config.optimizeDeps.exclude.push(dep);
26
+ }
27
+ });
28
+
11
29
  return config;
12
30
  }
13
31