@aurelia/storybook 1.0.0 → 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.
Files changed (36) hide show
  1. package/README.md +29 -33
  2. package/__tests__/render.test.ts +1 -1
  3. package/apps/hello-world/.storybook/main.ts +32 -12
  4. package/apps/hello-world/package-lock.json +7448 -0
  5. package/apps/hello-world/package.json +10 -10
  6. package/apps/hello-world/src/stories/hello-world.stories.ts +11 -10
  7. package/apps/hello-world-webpack/.storybook/main.ts +1 -4
  8. package/apps/hello-world-webpack/package-lock.json +380 -3515
  9. package/apps/hello-world-webpack/package.json +9 -10
  10. package/apps/hello-world-webpack/src/hello-world.html +6 -0
  11. package/apps/hello-world-webpack/src/hello-world.ts +17 -0
  12. package/apps/hello-world-webpack/src/my-app.stories.ts +10 -7
  13. package/apps/hello-world-webpack/src/stories/hello-world.stories.ts +54 -0
  14. package/dist/index.js +65 -38
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +62 -39
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/preset.js +15 -1
  19. package/dist/preset.js.map +1 -1
  20. package/dist/preset.mjs +15 -1
  21. package/dist/preset.mjs.map +1 -1
  22. package/dist/preview/render.js +41 -40
  23. package/dist/preview/render.js.map +1 -1
  24. package/dist/preview/render.mjs +41 -40
  25. package/dist/preview/render.mjs.map +1 -1
  26. package/dist/preview.js +81 -39
  27. package/dist/preview.js.map +1 -1
  28. package/dist/preview.mjs +81 -40
  29. package/dist/preview.mjs.map +1 -1
  30. package/package.json +6 -10
  31. package/rollup.config.mjs +6 -4
  32. package/src/index.ts +28 -0
  33. package/src/preset.ts +19 -1
  34. package/src/preview/render.ts +51 -49
  35. package/src/preview/types.ts +1 -1
  36. package/src/preview.ts +1 -50
@@ -8,17 +8,16 @@
8
8
  },
9
9
  "license": "UNLICENSED",
10
10
  "dependencies": {
11
- "@aurelia/router": "latest",
12
- "aurelia": "2.0.0-beta.14"
11
+ "@aurelia/router": "2.0.0-beta.24",
12
+ "aurelia": "2.0.0-beta.24"
13
13
  },
14
14
  "devDependencies": {
15
- "@aurelia/storybook": "file:../../",
16
- "@aurelia/testing": "latest",
17
- "@aurelia/webpack-loader": "latest",
18
- "@storybook/addon-essentials": "^8.6.14",
19
- "@storybook/addon-links": "^9.0.12",
20
- "@storybook/addon-webpack5-compiler-swc": "^3.0.0",
21
- "@storybook/html-webpack5": "^8.6.14",
15
+ "@aurelia/storybook": "^1.0.2",
16
+ "@aurelia/testing": "2.0.0-beta.24",
17
+ "@aurelia/webpack-loader": "2.0.0-beta.24",
18
+ "@storybook/addon-actions": "^9.0.8",
19
+ "@storybook/addon-links": "^9.0.0",
20
+ "@storybook/test": "^9.0.0-alpha.2",
22
21
  "@types/node": "^22.10.2",
23
22
  "autoprefixer": "^10.4.20",
24
23
  "css-loader": "^7.1.2",
@@ -28,7 +27,7 @@
28
27
  "html-webpack-plugin": "^5.6.3",
29
28
  "postcss": "^8.4.49",
30
29
  "postcss-loader": "^8.1.1",
31
- "storybook": "^9.0.12",
30
+ "storybook": "^9.0.0",
32
31
  "style-loader": "^4.0.0",
33
32
  "stylelint": "^16.12.0",
34
33
  "stylelint-config-standard": "^36.0.1",
@@ -0,0 +1,6 @@
1
+ <div style="border: 1px solid #ccc; padding: 16px; border-radius: 4px;">
2
+ <h1>${message}</h1>
3
+ <p>Counter: ${counter}</p>
4
+ <button click.trigger="increment()">Increment</button>
5
+ <au-slot></au-slot>
6
+ </div>
@@ -0,0 +1,17 @@
1
+ import { bindable } from 'aurelia';
2
+
3
+ export class HelloWorld {
4
+ @bindable() message = 'Hello from Aurelia!';
5
+ // New reactive counter property to track number of clicks
6
+ counter = 0;
7
+ // New bindable event callback for the increment action
8
+ @bindable() onIncrement;
9
+
10
+ // Method to increment the counter and fire the onIncrement callback if provided.
11
+ increment() {
12
+ this.counter++;
13
+ if (this.onIncrement) {
14
+ this.onIncrement(this.counter);
15
+ }
16
+ }
17
+ }
@@ -1,12 +1,15 @@
1
1
  import { MyApp } from './my-app';
2
2
 
3
- export default {
4
- title: 'My-App',
3
+ const meta = {
4
+ title: 'Example/MyApp',
5
5
  component: MyApp,
6
+ render: () => ({
7
+ template: `<my-app></my-app>`,
8
+ }),
6
9
  };
7
10
 
8
- export const Default = () => ({
9
- Component: MyApp,
10
- template: '<my-app></my-app>',
11
- props: {}
12
- });
11
+ export default meta;
12
+
13
+ export const Default = {
14
+ args: {}
15
+ };
@@ -0,0 +1,54 @@
1
+ import { HelloWorld } from '../hello-world';
2
+ import { fn } from '@storybook/test';
3
+ import { userEvent, within } from '@storybook/test';
4
+
5
+ const meta = {
6
+ title: 'Example/HelloWorld',
7
+ component: HelloWorld,
8
+ render: () => ({
9
+ template: `<hello-world message.bind="message" on-increment.bind="onIncrement"></hello-world>`,
10
+ }),
11
+ argTypes: {
12
+ message: { control: 'text' },
13
+ onIncrement: { action: 'increment' }
14
+ }
15
+ };
16
+
17
+ export default meta;
18
+
19
+ export const DefaultHelloWorld = {
20
+ args: {
21
+ message: "Hello frof",
22
+ onIncrement: fn()
23
+ }
24
+ };
25
+
26
+ export const InteractiveHelloWorld = {
27
+ args: {
28
+ message: "kjkjk",
29
+ onIncrement: fn()
30
+ },
31
+ play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
32
+ const canvas = within(canvasElement);
33
+ const button = canvas.getByRole('button');
34
+ // Simulate three button clicks
35
+ await userEvent.click(button);
36
+ await userEvent.click(button);
37
+ await userEvent.click(button);
38
+ }
39
+ };
40
+
41
+ export const NoArgs = {
42
+ render: () => ({
43
+ template: `<hello-world></hello-world>`
44
+ })
45
+ };
46
+
47
+ export const WithCustomTemplate = {
48
+ render: () => ({
49
+ template: `<hello-world message.bind="message">Click me!</hello-world>`
50
+ }),
51
+ args: {
52
+ message: "This is a custom messageddd"
53
+ }
54
+ };
package/dist/index.js CHANGED
@@ -1,15 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var coreEvents = require('@storybook/core-events');
4
3
  var Aurelia = require('aurelia');
5
4
 
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
5
  // Track Aurelia apps for cleanup
14
6
  const appMap = new Map();
15
7
  async function teardown(element) {
@@ -22,10 +14,29 @@ async function teardown(element) {
22
14
  }
23
15
  }
24
16
  async function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }, canvasElement, bootstrapAppFn) {
25
- const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;
17
+ // Store reference to the original storybook root element
18
+ const rootElement = canvasElement;
19
+ // Ensure we have (or create) a single container inside the root where the Aurelia app actually renders
20
+ let hostElement;
21
+ if (rootElement.id === 'storybook-root') {
22
+ hostElement = rootElement.querySelector('.aurelia-story-container');
23
+ if (!hostElement) {
24
+ hostElement = document.createElement('div');
25
+ hostElement.className = 'aurelia-story-container';
26
+ hostElement.style.height = '100%';
27
+ rootElement.appendChild(hostElement);
28
+ }
29
+ }
30
+ else {
31
+ hostElement = rootElement;
32
+ }
33
+ // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe
34
+ const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;
26
35
  const { parameters, component, args } = storyContext;
27
- let app = appMap.get(canvasElement);
36
+ let app = appMap.get(rootElement);
28
37
  const story = storyFn();
38
+ // Temporary debug logging
39
+ console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);
29
40
  if (!story) {
30
41
  showError({
31
42
  title: `Expecting an Aurelia component from the story: "${name}" of "${title}".`,
@@ -37,43 +48,32 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
37
48
  return () => { };
38
49
  }
39
50
  showMain();
40
- let mergedProps;
41
- // Use full merge (including story.props) when bootstrapping a new app or force remounting.
42
51
  if (!app || forceRemount) {
43
- mergedProps = mergeStoryProps(parameters?.args, args, story.props);
44
- if (app) {
45
- await teardown(canvasElement);
52
+ if (forceRemount && app) {
53
+ await teardown(rootElement);
54
+ app = undefined;
46
55
  }
47
- app = appBootstrapFn(story, mergedProps, canvasElement, component);
48
- await app.start();
49
- appMap.set(canvasElement, app);
56
+ // Clear container before mounting new app
57
+ hostElement.innerHTML = '';
58
+ const mergedProps = { ...parameters?.args, ...args, ...story.props };
59
+ const aureliaApp = appBootstrapFn(story, mergedProps, hostElement, component);
60
+ await aureliaApp.start();
61
+ appMap.set(rootElement, aureliaApp);
62
+ app = aureliaApp;
50
63
  }
51
64
  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) {
65
+ // update existing app props
66
+ const mergedProps = { ...parameters?.args, ...args, ...story.props };
67
+ if (app?.root?.controller?.viewModel) {
55
68
  Object.assign(app.root.controller.viewModel, mergedProps);
56
69
  }
57
70
  }
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
71
+ // Return cleanup fn
69
72
  return async () => {
70
- if (channel && onStoryChange) {
71
- channel.off(coreEvents.STORY_CHANGED, onStoryChange);
72
- }
73
- await teardown(canvasElement);
73
+ await teardown(rootElement);
74
74
  };
75
75
  }
76
- function bootstrapAureliaApp(story, args, domElement, component) {
76
+ function createAureliaApp(story, args, domElement, component) {
77
77
  const aurelia = new Aurelia(story.container);
78
78
  if (story.items?.length) {
79
79
  aurelia.register(...story.items);
@@ -87,7 +87,7 @@ function bootstrapAureliaApp(story, args, domElement, component) {
87
87
  aurelia.register(component);
88
88
  }
89
89
  const App = Aurelia.CustomElement.define({
90
- name: 'au-storybook',
90
+ name: 'sb-app',
91
91
  template,
92
92
  containerless: true,
93
93
  }, class {
@@ -106,7 +106,34 @@ function createComponentTemplate(component, innerHtml) {
106
106
  }
107
107
 
108
108
  const render = renderToCanvas;
109
+ // Define the framework
110
+ const framework = {
111
+ name: '@aurelia/storybook',
112
+ options: {}
113
+ };
114
+ // Framework configuration for Storybook
115
+ const frameworkOptions = {
116
+ builder: {
117
+ name: '@storybook/builder-vite',
118
+ options: {}
119
+ }
120
+ };
121
+ // Export a complete framework configuration
122
+ const aureliaFramework = {
123
+ name: '@aurelia/storybook',
124
+ options: {},
125
+ builder: '@storybook/builder-vite'
126
+ };
127
+ // Provide external dependencies configuration
128
+ const externals = {
129
+ 'react': 'React',
130
+ 'react-dom': 'ReactDOM'
131
+ };
109
132
 
133
+ exports.aureliaFramework = aureliaFramework;
134
+ exports.externals = externals;
135
+ exports.framework = framework;
136
+ exports.frameworkOptions = frameworkOptions;
110
137
  exports.render = render;
111
138
  exports.renderToCanvas = renderToCanvas;
112
139
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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,E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AAE,EAAE,IAAI,CAAC;IAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;AACjB,QAAA,IAAI,EAAE,UAAU;AAChB,QAAA,SAAS,EAAE,GAAG;AACf,KAAA,CAAC;AACJ;AAEM,SAAU,uBAAuB,CACrC,SAAwB,EACxB,SAAkB,EAAA;IAElB,MAAM,GAAG,GAAGA,qBAAa,CAAC,aAAa,CAAC,SAAS,CAAC;AAElD,IAAA,OAAO,CAAA,CAAA,EAAI,GAAG,CAAC,IAAI,CAAA,CAAA,EAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS;AAC/C,SAAA,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAA,EAAG,QAAQ,CAAC,SAAS,CAAA,OAAA,EAAU,QAAQ,CAAC,IAAI,GAAG;AACjE,SAAA,IAAI,CAAC,GAAG,CAAC,CAAA,CAAA,EAAI,SAAS,IAAI,EAAE,CAAA,EAAA,EAAK,GAAG,CAAC,IAAI,CAAA,CAAA,CAAG;AACjD;;ACzKO,MAAM,MAAM,GAAG;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/preview/render.ts","../src/index.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}","import type { StorybookConfig } from 'storybook/internal/types';\nimport { renderToCanvas } from './preview/render';\n\nexport { renderToCanvas };\nexport const render = renderToCanvas;\n\n// Define the framework\nexport const framework = {\n name: '@aurelia/storybook',\n options: {}\n};\n\n// Framework configuration for Storybook\nexport const frameworkOptions = {\n builder: {\n name: '@storybook/builder-vite',\n options: {}\n }\n};\n\n// Export a complete framework configuration\nexport const aureliaFramework = {\n name: '@aurelia/storybook',\n options: {},\n builder: '@storybook/builder-vite'\n};\n\n// Provide external dependencies configuration\nexport const externals = {\n 'react': 'React',\n 'react-dom': 'ReactDOM'\n};\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;AAC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ACjD;;AC1KO,MAAM,MAAM,GAAG;AAEtB;AACO,MAAM,SAAS,GAAG;AACvB,IAAA,IAAI,EAAE,oBAAoB;AAC1B,IAAA,OAAO,EAAE;;AAGX;AACO,MAAM,gBAAgB,GAAG;AAC9B,IAAA,OAAO,EAAE;AACP,QAAA,IAAI,EAAE,yBAAyB;AAC/B,QAAA,OAAO,EAAE;AACV;;AAGH;AACO,MAAM,gBAAgB,GAAG;AAC9B,IAAA,IAAI,EAAE,oBAAoB;AAC1B,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,OAAO,EAAE;;AAGX;AACO,MAAM,SAAS,GAAG;AACvB,IAAA,OAAO,EAAE,OAAO;AAChB,IAAA,WAAW,EAAE;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -1,13 +1,5 @@
1
- import { STORY_CHANGED } from '@storybook/core-events';
2
1
  import Aurelia, { CustomElement } from 'aurelia';
3
2
 
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
3
  // Track Aurelia apps for cleanup
12
4
  const appMap = new Map();
13
5
  async function teardown(element) {
@@ -20,10 +12,29 @@ async function teardown(element) {
20
12
  }
21
13
  }
22
14
  async function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }, canvasElement, bootstrapAppFn) {
23
- const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;
15
+ // Store reference to the original storybook root element
16
+ const rootElement = canvasElement;
17
+ // Ensure we have (or create) a single container inside the root where the Aurelia app actually renders
18
+ let hostElement;
19
+ if (rootElement.id === 'storybook-root') {
20
+ hostElement = rootElement.querySelector('.aurelia-story-container');
21
+ if (!hostElement) {
22
+ hostElement = document.createElement('div');
23
+ hostElement.className = 'aurelia-story-container';
24
+ hostElement.style.height = '100%';
25
+ rootElement.appendChild(hostElement);
26
+ }
27
+ }
28
+ else {
29
+ hostElement = rootElement;
30
+ }
31
+ // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe
32
+ const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;
24
33
  const { parameters, component, args } = storyContext;
25
- let app = appMap.get(canvasElement);
34
+ let app = appMap.get(rootElement);
26
35
  const story = storyFn();
36
+ // Temporary debug logging
37
+ console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);
27
38
  if (!story) {
28
39
  showError({
29
40
  title: `Expecting an Aurelia component from the story: "${name}" of "${title}".`,
@@ -35,43 +46,32 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
35
46
  return () => { };
36
47
  }
37
48
  showMain();
38
- let mergedProps;
39
- // Use full merge (including story.props) when bootstrapping a new app or force remounting.
40
49
  if (!app || forceRemount) {
41
- mergedProps = mergeStoryProps(parameters?.args, args, story.props);
42
- if (app) {
43
- await teardown(canvasElement);
50
+ if (forceRemount && app) {
51
+ await teardown(rootElement);
52
+ app = undefined;
44
53
  }
45
- app = appBootstrapFn(story, mergedProps, canvasElement, component);
46
- await app.start();
47
- appMap.set(canvasElement, app);
54
+ // Clear container before mounting new app
55
+ hostElement.innerHTML = '';
56
+ const mergedProps = { ...parameters?.args, ...args, ...story.props };
57
+ const aureliaApp = appBootstrapFn(story, mergedProps, hostElement, component);
58
+ await aureliaApp.start();
59
+ appMap.set(rootElement, aureliaApp);
60
+ app = aureliaApp;
48
61
  }
49
62
  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) {
63
+ // update existing app props
64
+ const mergedProps = { ...parameters?.args, ...args, ...story.props };
65
+ if (app?.root?.controller?.viewModel) {
53
66
  Object.assign(app.root.controller.viewModel, mergedProps);
54
67
  }
55
68
  }
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
69
+ // Return cleanup fn
67
70
  return async () => {
68
- if (channel && onStoryChange) {
69
- channel.off(STORY_CHANGED, onStoryChange);
70
- }
71
- await teardown(canvasElement);
71
+ await teardown(rootElement);
72
72
  };
73
73
  }
74
- function bootstrapAureliaApp(story, args, domElement, component) {
74
+ function createAureliaApp(story, args, domElement, component) {
75
75
  const aurelia = new Aurelia(story.container);
76
76
  if (story.items?.length) {
77
77
  aurelia.register(...story.items);
@@ -85,7 +85,7 @@ function bootstrapAureliaApp(story, args, domElement, component) {
85
85
  aurelia.register(component);
86
86
  }
87
87
  const App = CustomElement.define({
88
- name: 'au-storybook',
88
+ name: 'sb-app',
89
89
  template,
90
90
  containerless: true,
91
91
  }, class {
@@ -104,6 +104,29 @@ function createComponentTemplate(component, innerHtml) {
104
104
  }
105
105
 
106
106
  const render = renderToCanvas;
107
+ // Define the framework
108
+ const framework = {
109
+ name: '@aurelia/storybook',
110
+ options: {}
111
+ };
112
+ // Framework configuration for Storybook
113
+ const frameworkOptions = {
114
+ builder: {
115
+ name: '@storybook/builder-vite',
116
+ options: {}
117
+ }
118
+ };
119
+ // Export a complete framework configuration
120
+ const aureliaFramework = {
121
+ name: '@aurelia/storybook',
122
+ options: {},
123
+ builder: '@storybook/builder-vite'
124
+ };
125
+ // Provide external dependencies configuration
126
+ const externals = {
127
+ 'react': 'React',
128
+ 'react-dom': 'ReactDOM'
129
+ };
107
130
 
108
- export { render, renderToCanvas };
131
+ export { aureliaFramework, externals, framework, frameworkOptions, render, renderToCanvas };
109
132
  //# sourceMappingURL=index.mjs.map
@@ -1 +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,GAA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,QAAQ,EAAE,GAAG,KAAK;IAExB,IAAI,SAAS,EAAE;QACb,QAAQ,GAAG,QAAQ,IAAI,uBAAuB,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC;AAC1E,QAAA,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;;AAG7B,IAAA,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAC9B;AACE,QAAA,IAAI,EAAE,cAAc;QACpB,QAAQ;AACR,QAAA,aAAa,EAAE,IAAI;KACpB,EACD,MAAA;AAAQ,KAAA,CACT;AAED,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,IAAI,CAAC;IAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;AACjB,QAAA,IAAI,EAAE,UAAU;AAChB,QAAA,SAAS,EAAE,GAAG;AACf,KAAA,CAAC;AACJ;AAEM,SAAU,uBAAuB,CACrC,SAAwB,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;;ACzKO,MAAM,MAAM,GAAG;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/preview/render.ts","../src/index.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}","import type { StorybookConfig } from 'storybook/internal/types';\nimport { renderToCanvas } from './preview/render';\n\nexport { renderToCanvas };\nexport const render = renderToCanvas;\n\n// Define the framework\nexport const framework = {\n name: '@aurelia/storybook',\n options: {}\n};\n\n// Framework configuration for Storybook\nexport const frameworkOptions = {\n builder: {\n name: '@storybook/builder-vite',\n options: {}\n }\n};\n\n// Export a complete framework configuration\nexport const aureliaFramework = {\n name: '@aurelia/storybook',\n options: {},\n builder: '@storybook/builder-vite'\n};\n\n// Provide external dependencies configuration\nexport const externals = {\n 'react': 'React',\n 'react-dom': 'ReactDOM'\n};\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;AAaO,eAAe,cAAc,CAClC,EACE,OAAO,EACP,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACmB,EACjC,aAA0B,EAC1B,cAAwC,EAAA;;IAGxC,MAAM,WAAW,GAAG,aAAa;;AAGjC,IAAA,IAAI,WAAwB;AAC5B,IAAA,IAAI,WAAW,CAAC,EAAE,KAAK,gBAAgB,EAAE;AACvC,QAAA,WAAW,GAAG,WAAW,CAAC,aAAa,CAAC,0BAA0B,CAAgB;QAClF,IAAI,CAAC,WAAW,EAAE;AAChB,YAAA,WAAW,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;AAC3C,YAAA,WAAW,CAAC,SAAS,GAAG,yBAAyB;AACjD,YAAA,WAAW,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM;AACjC,YAAA,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC;;;SAEjC;QACL,WAAW,GAAG,WAAW;;;AAI3B,IAAA,MAAM,cAAc,GAAG,cAAc,IAAI,gBAAgB;IACzD,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,YAAY;IAEpD,IAAI,GAA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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;;AC1KO,MAAM,MAAM,GAAG;AAEtB;AACO,MAAM,SAAS,GAAG;AACvB,IAAA,IAAI,EAAE,oBAAoB;AAC1B,IAAA,OAAO,EAAE;;AAGX;AACO,MAAM,gBAAgB,GAAG;AAC9B,IAAA,OAAO,EAAE;AACP,QAAA,IAAI,EAAE,yBAAyB;AAC/B,QAAA,OAAO,EAAE;AACV;;AAGH;AACO,MAAM,gBAAgB,GAAG;AAC9B,IAAA,IAAI,EAAE,oBAAoB;AAC1B,IAAA,OAAO,EAAE,EAAE;AACX,IAAA,OAAO,EAAE;;AAGX;AACO,MAAM,SAAS,GAAG;AACvB,IAAA,OAAO,EAAE,OAAO;AAChB,IAAA,WAAW,EAAE;;;;;"}
package/dist/preset.js CHANGED
@@ -27,7 +27,21 @@ function getRules() {
27
27
  * Optionally adjust the Vite configuration.
28
28
  */
29
29
  async function viteFinal(config) {
30
- // For now, return the config unchanged.
30
+ // Configure Vite to properly handle dependencies
31
+ config.define = config.define || {};
32
+ config.define['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV || 'development');
33
+ // Configure optimization deps
34
+ config.optimizeDeps = config.optimizeDeps || {};
35
+ config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
36
+ // Only exclude Aurelia-specific dependencies that cause issues
37
+ const excludeList = [
38
+ '@aurelia/runtime-html'
39
+ ];
40
+ excludeList.forEach(dep => {
41
+ if (!config.optimizeDeps.exclude.includes(dep)) {
42
+ config.optimizeDeps.exclude.push(dep);
43
+ }
44
+ });
31
45
  return config;
32
46
  }
33
47
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"preset.js","sources":["../src/webpack.ts","../src/preset.ts"],"sourcesContent":["// src/webpack.ts\nimport type { RuleSetRule } from 'webpack';\n\n/**\n * A set of rules to be added to the webpack configuration.\n * @returns\n */\nexport function getRules(): RuleSetRule[] {\n return [\n {\n test: /\\.ts$/i,\n use: ['ts-loader', '@aurelia/webpack-loader'],\n exclude: /node_modules/,\n },\n {\n test: /\\.html$/i,\n use: '@aurelia/webpack-loader',\n exclude: /node_modules/,\n },\n ];\n}\n","// src/preset.ts\n// Minimal preset for Storybook-Aurelia2\n\nimport { getRules } from './webpack';\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/**\n * A function to configure webpack.\n * @param config\n * @returns\n */\nexport async function webpackFinal(config: any): Promise<any> {\n const rules = config.module?.rules;\n if (rules) {\n rules.push(...getRules());\n }\n\n return config;\n}\n\n// Export a default for compatibility.\nexport default { viteFinal, webpackFinal };\n\nexport const previewAnnotations = [require.resolve('./preview')];\n"],"names":[],"mappings":";;;;AAGA;;;AAGG;SACa,QAAQ,GAAA;IACtB,OAAO;AACL,QAAA;AACE,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,GAAG,EAAE,CAAC,WAAW,EAAE,yBAAyB,CAAC;AAC7C,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;AACD,QAAA;AACE,YAAA,IAAI,EAAE,UAAU;AAChB,YAAA,GAAG,EAAE,yBAAyB;AAC9B,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;KACF;AACH;;ACpBA;AACA;AAIA;;AAEG;AACI,eAAe,SAAS,CAAC,MAAW,EAAA;;AAEvC,IAAA,OAAO,MAAM;AACjB;AAEA;;;;AAIG;AACI,eAAe,YAAY,CAAC,MAAW,EAAA;AAC1C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK;IAClC,IAAI,KAAK,EAAE;AACP,QAAA,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE,CAAC;;AAG7B,IAAA,OAAO,MAAM;AACjB;AAEA;AACA,aAAe,EAAE,SAAS,EAAE,YAAY,EAAE;AAEnC,MAAM,kBAAkB,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;;;;;;;"}
1
+ {"version":3,"file":"preset.js","sources":["../src/webpack.ts","../src/preset.ts"],"sourcesContent":["// src/webpack.ts\nimport type { RuleSetRule } from 'webpack';\n\n/**\n * A set of rules to be added to the webpack configuration.\n * @returns\n */\nexport function getRules(): RuleSetRule[] {\n return [\n {\n test: /\\.ts$/i,\n use: ['ts-loader', '@aurelia/webpack-loader'],\n exclude: /node_modules/,\n },\n {\n test: /\\.html$/i,\n use: '@aurelia/webpack-loader',\n exclude: /node_modules/,\n },\n ];\n}\n","// src/preset.ts\n// Minimal preset for Storybook-Aurelia2\n\nimport { getRules } from './webpack';\n\n/**\n * Optionally adjust the Vite configuration.\n */\nexport async function viteFinal(config: any): Promise<any> {\n // Configure Vite to properly handle dependencies\n config.define = config.define || {};\n config.define['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV || 'development');\n \n // Configure optimization deps\n config.optimizeDeps = config.optimizeDeps || {};\n config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];\n \n // Only exclude Aurelia-specific dependencies that cause issues\n const excludeList = [\n '@aurelia/runtime-html'\n ];\n \n excludeList.forEach(dep => {\n if (!config.optimizeDeps.exclude.includes(dep)) {\n config.optimizeDeps.exclude.push(dep);\n }\n });\n \n return config;\n}\n\n/**\n * A function to configure webpack.\n * @param config\n * @returns\n */\nexport async function webpackFinal(config: any): Promise<any> {\n const rules = config.module?.rules;\n if (rules) {\n rules.push(...getRules());\n }\n\n return config;\n}\n\n// Export a default for compatibility.\nexport default { viteFinal, webpackFinal };\n\nexport const previewAnnotations = [require.resolve('./preview')];\n"],"names":[],"mappings":";;;;AAGA;;;AAGG;SACa,QAAQ,GAAA;IACtB,OAAO;AACL,QAAA;AACE,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,GAAG,EAAE,CAAC,WAAW,EAAE,yBAAyB,CAAC;AAC7C,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;AACD,QAAA;AACE,YAAA,IAAI,EAAE,UAAU;AAChB,YAAA,GAAG,EAAE,yBAAyB;AAC9B,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;KACF;AACH;;ACpBA;AACA;AAIA;;AAEG;AACI,eAAe,SAAS,CAAC,MAAW,EAAA;;IAEvC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE;AACnC,IAAA,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;;IAG7F,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE;AAC/C,IAAA,MAAM,CAAC,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,IAAI,EAAE;;AAG/D,IAAA,MAAM,WAAW,GAAG;QAChB;KACH;AAED,IAAA,WAAW,CAAC,OAAO,CAAC,GAAG,IAAG;AACtB,QAAA,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAC5C,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;;AAE7C,KAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACjB;AAEA;;;;AAIG;AACI,eAAe,YAAY,CAAC,MAAW,EAAA;AAC1C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK;IAClC,IAAI,KAAK,EAAE;AACP,QAAA,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE,CAAC;;AAG7B,IAAA,OAAO,MAAM;AACjB;AAEA;AACA,aAAe,EAAE,SAAS,EAAE,YAAY,EAAE;AAEnC,MAAM,kBAAkB,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;;;;;;;"}
package/dist/preset.mjs CHANGED
@@ -23,7 +23,21 @@ function getRules() {
23
23
  * Optionally adjust the Vite configuration.
24
24
  */
25
25
  async function viteFinal(config) {
26
- // For now, return the config unchanged.
26
+ // Configure Vite to properly handle dependencies
27
+ config.define = config.define || {};
28
+ config.define['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV || 'development');
29
+ // Configure optimization deps
30
+ config.optimizeDeps = config.optimizeDeps || {};
31
+ config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
32
+ // Only exclude Aurelia-specific dependencies that cause issues
33
+ const excludeList = [
34
+ '@aurelia/runtime-html'
35
+ ];
36
+ excludeList.forEach(dep => {
37
+ if (!config.optimizeDeps.exclude.includes(dep)) {
38
+ config.optimizeDeps.exclude.push(dep);
39
+ }
40
+ });
27
41
  return config;
28
42
  }
29
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"preset.mjs","sources":["../src/webpack.ts","../src/preset.ts"],"sourcesContent":["// src/webpack.ts\nimport type { RuleSetRule } from 'webpack';\n\n/**\n * A set of rules to be added to the webpack configuration.\n * @returns\n */\nexport function getRules(): RuleSetRule[] {\n return [\n {\n test: /\\.ts$/i,\n use: ['ts-loader', '@aurelia/webpack-loader'],\n exclude: /node_modules/,\n },\n {\n test: /\\.html$/i,\n use: '@aurelia/webpack-loader',\n exclude: /node_modules/,\n },\n ];\n}\n","// src/preset.ts\n// Minimal preset for Storybook-Aurelia2\n\nimport { getRules } from './webpack';\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/**\n * A function to configure webpack.\n * @param config\n * @returns\n */\nexport async function webpackFinal(config: any): Promise<any> {\n const rules = config.module?.rules;\n if (rules) {\n rules.push(...getRules());\n }\n\n return config;\n}\n\n// Export a default for compatibility.\nexport default { viteFinal, webpackFinal };\n\nexport const previewAnnotations = [require.resolve('./preview')];\n"],"names":[],"mappings":"AAGA;;;AAGG;SACa,QAAQ,GAAA;IACtB,OAAO;AACL,QAAA;AACE,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,GAAG,EAAE,CAAC,WAAW,EAAE,yBAAyB,CAAC;AAC7C,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;AACD,QAAA;AACE,YAAA,IAAI,EAAE,UAAU;AAChB,YAAA,GAAG,EAAE,yBAAyB;AAC9B,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;KACF;AACH;;ACpBA;AACA;AAIA;;AAEG;AACI,eAAe,SAAS,CAAC,MAAW,EAAA;;AAEvC,IAAA,OAAO,MAAM;AACjB;AAEA;;;;AAIG;AACI,eAAe,YAAY,CAAC,MAAW,EAAA;AAC1C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK;IAClC,IAAI,KAAK,EAAE;AACP,QAAA,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE,CAAC;;AAG7B,IAAA,OAAO,MAAM;AACjB;AAEA;AACA,aAAe,EAAE,SAAS,EAAE,YAAY,EAAE;AAEnC,MAAM,kBAAkB,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;;;;"}
1
+ {"version":3,"file":"preset.mjs","sources":["../src/webpack.ts","../src/preset.ts"],"sourcesContent":["// src/webpack.ts\nimport type { RuleSetRule } from 'webpack';\n\n/**\n * A set of rules to be added to the webpack configuration.\n * @returns\n */\nexport function getRules(): RuleSetRule[] {\n return [\n {\n test: /\\.ts$/i,\n use: ['ts-loader', '@aurelia/webpack-loader'],\n exclude: /node_modules/,\n },\n {\n test: /\\.html$/i,\n use: '@aurelia/webpack-loader',\n exclude: /node_modules/,\n },\n ];\n}\n","// src/preset.ts\n// Minimal preset for Storybook-Aurelia2\n\nimport { getRules } from './webpack';\n\n/**\n * Optionally adjust the Vite configuration.\n */\nexport async function viteFinal(config: any): Promise<any> {\n // Configure Vite to properly handle dependencies\n config.define = config.define || {};\n config.define['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV || 'development');\n \n // Configure optimization deps\n config.optimizeDeps = config.optimizeDeps || {};\n config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];\n \n // Only exclude Aurelia-specific dependencies that cause issues\n const excludeList = [\n '@aurelia/runtime-html'\n ];\n \n excludeList.forEach(dep => {\n if (!config.optimizeDeps.exclude.includes(dep)) {\n config.optimizeDeps.exclude.push(dep);\n }\n });\n \n return config;\n}\n\n/**\n * A function to configure webpack.\n * @param config\n * @returns\n */\nexport async function webpackFinal(config: any): Promise<any> {\n const rules = config.module?.rules;\n if (rules) {\n rules.push(...getRules());\n }\n\n return config;\n}\n\n// Export a default for compatibility.\nexport default { viteFinal, webpackFinal };\n\nexport const previewAnnotations = [require.resolve('./preview')];\n"],"names":[],"mappings":"AAGA;;;AAGG;SACa,QAAQ,GAAA;IACtB,OAAO;AACL,QAAA;AACE,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,GAAG,EAAE,CAAC,WAAW,EAAE,yBAAyB,CAAC;AAC7C,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;AACD,QAAA;AACE,YAAA,IAAI,EAAE,UAAU;AAChB,YAAA,GAAG,EAAE,yBAAyB;AAC9B,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;KACF;AACH;;ACpBA;AACA;AAIA;;AAEG;AACI,eAAe,SAAS,CAAC,MAAW,EAAA;;IAEvC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE;AACnC,IAAA,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,GAAG,IAAI,CAA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