@aurelia/storybook 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +18 -14
  3. package/dist/index.js +34 -14
  4. package/dist/index.js.map +1 -1
  5. package/dist/preset.js +30 -20
  6. package/dist/preset.js.map +1 -1
  7. package/dist/preview/render.d.ts +1 -1
  8. package/dist/preview/render.js +34 -14
  9. package/dist/preview/render.js.map +1 -1
  10. package/dist/preview.js +34 -14
  11. package/dist/preview.js.map +1 -1
  12. package/package.json +30 -15
  13. package/preset.js +2 -1
  14. package/.github/workflows/ci.yml +0 -61
  15. package/.github/workflows/publish.yml +0 -82
  16. package/.github/workflows/storybook-preview.yml +0 -62
  17. package/__tests__/create-aurelia-app.test.ts +0 -94
  18. package/__tests__/preset.test.ts +0 -78
  19. package/__tests__/preview.test.ts +0 -17
  20. package/__tests__/render.test.ts +0 -176
  21. package/__tests__/webpack.test.ts +0 -21
  22. package/apps/hello-world/.storybook/main.ts +0 -49
  23. package/apps/hello-world/.storybook/preview.ts +0 -1
  24. package/apps/hello-world/.stylelintrc.json +0 -5
  25. package/apps/hello-world/README.md +0 -28
  26. package/apps/hello-world/eslint.config.mjs +0 -25
  27. package/apps/hello-world/favicon.ico +0 -0
  28. package/apps/hello-world/index.html +0 -17
  29. package/apps/hello-world/package-lock.json +0 -9424
  30. package/apps/hello-world/package.json +0 -55
  31. package/apps/hello-world/src/components/feedback-form.html +0 -111
  32. package/apps/hello-world/src/components/feedback-form.ts +0 -45
  33. package/apps/hello-world/src/components/notification-center.html +0 -119
  34. package/apps/hello-world/src/components/notification-center.ts +0 -27
  35. package/apps/hello-world/src/components/stat-card.html +0 -107
  36. package/apps/hello-world/src/components/stat-card.ts +0 -41
  37. package/apps/hello-world/src/components/weather-widget.html +0 -89
  38. package/apps/hello-world/src/components/weather-widget.ts +0 -31
  39. package/apps/hello-world/src/hello-world.html +0 -48
  40. package/apps/hello-world/src/hello-world.ts +0 -17
  41. package/apps/hello-world/src/main.ts +0 -6
  42. package/apps/hello-world/src/my-app.html +0 -1
  43. package/apps/hello-world/src/my-app.ts +0 -3
  44. package/apps/hello-world/src/resource.d.ts +0 -15
  45. package/apps/hello-world/src/services/weather-service.ts +0 -15
  46. package/apps/hello-world/src/stories/feedback-form.stories.ts +0 -58
  47. package/apps/hello-world/src/stories/hello-world.stories.ts +0 -64
  48. package/apps/hello-world/src/stories/notification-center.stories.ts +0 -88
  49. package/apps/hello-world/src/stories/stat-card.stories.ts +0 -75
  50. package/apps/hello-world/src/stories/weather-widget.stories.ts +0 -62
  51. package/apps/hello-world/test/my-app.spec.ts +0 -15
  52. package/apps/hello-world/test/setup.ts +0 -29
  53. package/apps/hello-world/tsconfig.json +0 -19
  54. package/apps/hello-world/tsconfig.vitest.json +0 -11
  55. package/apps/hello-world/vite.config.ts +0 -17
  56. package/apps/hello-world/vitest.config.ts +0 -15
  57. package/apps/hello-world-rsbuild/.storybook/main.ts +0 -16
  58. package/apps/hello-world-rsbuild/.storybook/preview.ts +0 -1
  59. package/apps/hello-world-rsbuild/.stylelintrc.json +0 -5
  60. package/apps/hello-world-rsbuild/README.md +0 -28
  61. package/apps/hello-world-rsbuild/eslint.config.mjs +0 -25
  62. package/apps/hello-world-rsbuild/favicon.ico +0 -0
  63. package/apps/hello-world-rsbuild/index.html +0 -17
  64. package/apps/hello-world-rsbuild/package-lock.json +0 -11131
  65. package/apps/hello-world-rsbuild/package.json +0 -56
  66. package/apps/hello-world-rsbuild/src/components/feedback-form.html +0 -111
  67. package/apps/hello-world-rsbuild/src/components/feedback-form.ts +0 -45
  68. package/apps/hello-world-rsbuild/src/components/notification-center.html +0 -119
  69. package/apps/hello-world-rsbuild/src/components/notification-center.ts +0 -27
  70. package/apps/hello-world-rsbuild/src/components/stat-card.html +0 -107
  71. package/apps/hello-world-rsbuild/src/components/stat-card.ts +0 -41
  72. package/apps/hello-world-rsbuild/src/components/weather-widget.html +0 -89
  73. package/apps/hello-world-rsbuild/src/components/weather-widget.ts +0 -31
  74. package/apps/hello-world-rsbuild/src/hello-world.html +0 -48
  75. package/apps/hello-world-rsbuild/src/hello-world.ts +0 -17
  76. package/apps/hello-world-rsbuild/src/main.ts +0 -6
  77. package/apps/hello-world-rsbuild/src/my-app.html +0 -1
  78. package/apps/hello-world-rsbuild/src/my-app.ts +0 -3
  79. package/apps/hello-world-rsbuild/src/resource.d.ts +0 -15
  80. package/apps/hello-world-rsbuild/src/services/weather-service.ts +0 -15
  81. package/apps/hello-world-rsbuild/src/stories/feedback-form.stories.ts +0 -58
  82. package/apps/hello-world-rsbuild/src/stories/hello-world.stories.ts +0 -64
  83. package/apps/hello-world-rsbuild/src/stories/notification-center.stories.ts +0 -88
  84. package/apps/hello-world-rsbuild/src/stories/stat-card.stories.ts +0 -75
  85. package/apps/hello-world-rsbuild/src/stories/weather-widget.stories.ts +0 -62
  86. package/apps/hello-world-rsbuild/test/my-app.spec.ts +0 -15
  87. package/apps/hello-world-rsbuild/test/setup.ts +0 -29
  88. package/apps/hello-world-rsbuild/tsconfig.json +0 -19
  89. package/apps/hello-world-rsbuild/tsconfig.vitest.json +0 -11
  90. package/apps/hello-world-rsbuild/vite.config.ts +0 -17
  91. package/apps/hello-world-rsbuild/vitest.config.ts +0 -15
  92. package/apps/hello-world-webpack/.env.development +0 -0
  93. package/apps/hello-world-webpack/.storybook/main.ts +0 -14
  94. package/apps/hello-world-webpack/.storybook/preview.ts +0 -3
  95. package/apps/hello-world-webpack/.stylelintrc.json +0 -5
  96. package/apps/hello-world-webpack/README.md +0 -29
  97. package/apps/hello-world-webpack/eslint.config.mjs +0 -25
  98. package/apps/hello-world-webpack/favicon.ico +0 -0
  99. package/apps/hello-world-webpack/index.html +0 -15
  100. package/apps/hello-world-webpack/package-lock.json +0 -9828
  101. package/apps/hello-world-webpack/package.json +0 -52
  102. package/apps/hello-world-webpack/src/components/feedback-form.html +0 -111
  103. package/apps/hello-world-webpack/src/components/feedback-form.ts +0 -45
  104. package/apps/hello-world-webpack/src/components/notification-center.html +0 -119
  105. package/apps/hello-world-webpack/src/components/notification-center.ts +0 -27
  106. package/apps/hello-world-webpack/src/components/stat-card.html +0 -107
  107. package/apps/hello-world-webpack/src/components/stat-card.ts +0 -41
  108. package/apps/hello-world-webpack/src/components/weather-widget.html +0 -89
  109. package/apps/hello-world-webpack/src/components/weather-widget.ts +0 -31
  110. package/apps/hello-world-webpack/src/hello-world.html +0 -48
  111. package/apps/hello-world-webpack/src/hello-world.ts +0 -17
  112. package/apps/hello-world-webpack/src/main.ts +0 -6
  113. package/apps/hello-world-webpack/src/my-app.css +0 -3
  114. package/apps/hello-world-webpack/src/my-app.html +0 -1
  115. package/apps/hello-world-webpack/src/my-app.stories.ts +0 -17
  116. package/apps/hello-world-webpack/src/my-app.ts +0 -3
  117. package/apps/hello-world-webpack/src/resource.d.ts +0 -13
  118. package/apps/hello-world-webpack/src/services/weather-service.ts +0 -15
  119. package/apps/hello-world-webpack/src/stories/feedback-form.stories.ts +0 -58
  120. package/apps/hello-world-webpack/src/stories/hello-world.stories.ts +0 -64
  121. package/apps/hello-world-webpack/src/stories/notification-center.stories.ts +0 -88
  122. package/apps/hello-world-webpack/src/stories/stat-card.stories.ts +0 -75
  123. package/apps/hello-world-webpack/src/stories/weather-widget.stories.ts +0 -62
  124. package/apps/hello-world-webpack/tsconfig.json +0 -18
  125. package/apps/hello-world-webpack/webpack.config.js +0 -111
  126. package/jest.config.cjs +0 -9
  127. package/rollup.config.mjs +0 -52
  128. package/scripts/sync-versions.cjs +0 -55
  129. package/src/index.ts +0 -42
  130. package/src/preset.ts +0 -79
  131. package/src/preview/helpers.ts +0 -7
  132. package/src/preview/render.ts +0 -243
  133. package/src/preview/storybook-types-runtime.ts +0 -2
  134. package/src/preview/storybook-types.ts +0 -34
  135. package/src/preview/types-runtime.ts +0 -2
  136. package/src/preview/types.ts +0 -62
  137. package/src/preview.ts +0 -11
  138. package/src/webpack.ts +0 -40
  139. package/tsconfig.build.json +0 -5
  140. package/tsconfig.json +0 -15
package/dist/preview.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import Aurelia, { CustomElement } from 'aurelia';
2
2
 
3
- // Track Aurelia apps for cleanup
4
3
  const appMap = new Map();
5
4
  function mergeStoryProps(parameters, storyArgs, storyProps) {
6
5
  return { ...parameters?.args, ...storyArgs, ...storyProps };
@@ -21,13 +20,17 @@ function normalizeRegistrations(parameters) {
21
20
  const items = Array.isArray(parameters.items) ? parameters.items : [];
22
21
  return [...register, ...components, ...items].filter(Boolean);
23
22
  }
24
- async function teardown(element) {
25
- if (appMap.has(element)) {
26
- const app = appMap.get(element);
27
- if (app) {
28
- await app.stop();
29
- appMap.delete(element);
30
- }
23
+ async function teardown(element, expectedApp) {
24
+ const mounted = appMap.get(element);
25
+ if (!mounted) {
26
+ return;
27
+ }
28
+ if (expectedApp && mounted.app !== expectedApp) {
29
+ return;
30
+ }
31
+ appMap.delete(element);
32
+ if (typeof mounted.app?.stop === 'function') {
33
+ await mounted.app.stop();
31
34
  }
32
35
  }
33
36
  const render = (args, context) => {
@@ -58,7 +61,9 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
58
61
  // All app instances are now tracked by the *root* element, ensuring we only ever have one per story iframe
59
62
  const appBootstrapFn = bootstrapAppFn ?? createAureliaApp;
60
63
  const { parameters, component, args } = storyContext;
61
- let app = appMap.get(rootElement);
64
+ const storyId = storyContext.id ?? `${title}--${name}`;
65
+ const mounted = appMap.get(rootElement);
66
+ let app = mounted?.app;
62
67
  const story = storyFn();
63
68
  if (!story) {
64
69
  showError({
@@ -70,10 +75,24 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
70
75
  });
71
76
  return () => { };
72
77
  }
78
+ if (!component && !story.template) {
79
+ showError({
80
+ title: `Expecting a template or component from the story: "${name}" of "${title}".`,
81
+ description: `
82
+ Provide a component on the default export or return "{ template: '<custom-component></custom-component>' }" from the story.
83
+ `,
84
+ });
85
+ return () => { };
86
+ }
73
87
  showMain();
74
- if (!app || forceRemount) {
88
+ const shouldRemount = !app || forceRemount || mounted?.id !== storyId;
89
+ if (shouldRemount) {
75
90
  if (forceRemount && app) {
76
- await teardown(rootElement);
91
+ await teardown(rootElement, app);
92
+ app = undefined;
93
+ }
94
+ if (mounted?.id !== storyId && app) {
95
+ await teardown(rootElement, app);
77
96
  app = undefined;
78
97
  }
79
98
  // Clear container before mounting new app
@@ -81,7 +100,7 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
81
100
  const mergedProps = mergeStoryProps(parameters, args, story.props);
82
101
  const aureliaApp = appBootstrapFn(story, mergedProps, hostElement, component, storyContext);
83
102
  await aureliaApp.start();
84
- appMap.set(rootElement, aureliaApp);
103
+ appMap.set(rootElement, { id: storyId, app: aureliaApp });
85
104
  app = aureliaApp;
86
105
  }
87
106
  else {
@@ -92,8 +111,9 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
92
111
  }
93
112
  }
94
113
  // Return cleanup fn
114
+ const appForCleanup = app;
95
115
  return async () => {
96
- await teardown(rootElement);
116
+ await teardown(rootElement, appForCleanup);
97
117
  };
98
118
  }
99
119
  function createAureliaApp(story, args, domElement, component, storyContext) {
@@ -154,7 +174,7 @@ function createAureliaApp(story, args, domElement, component, storyContext) {
154
174
  }
155
175
  function createComponentTemplate(component, innerHtml) {
156
176
  const def = CustomElement.getDefinition(component);
157
- const bindings = Object.values(def.bindables)
177
+ const bindings = Object.values(def.bindables ?? {})
158
178
  .map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
159
179
  .join(' ');
160
180
  const bindingAttributes = bindings ? ` ${bindings}` : '';
@@ -1 +1 @@
1
- {"version":3,"file":"preview.js","sources":["../src/preview/render.ts","../src/preview/helpers.ts"],"sourcesContent":["import type { RenderContext, ArgsStoryFn } from './storybook-types';\nimport type {\n AureliaRenderer,\n AureliaStoryResult,\n AureliaParameters,\n AureliaStoryContext,\n} from './types';\nimport Aurelia, { Constructable, CustomElement } from 'aurelia';\n\n// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, any>();\n\nfunction mergeStoryProps(\n parameters: { args?: Record<string, any> } | undefined,\n storyArgs: Record<string, any> | undefined,\n storyProps: Record<string, any> | undefined\n) {\n return { ...parameters?.args, ...storyArgs, ...storyProps };\n}\n\nfunction getAureliaParameters(\n storyContext?: AureliaStoryContext\n): AureliaParameters | undefined {\n const parameters = storyContext?.parameters?.aurelia;\n if (!parameters || typeof parameters !== 'object') {\n return undefined;\n }\n return parameters as AureliaParameters;\n}\n\nfunction normalizeRegistrations(\n parameters: AureliaParameters | undefined\n): unknown[] {\n if (!parameters) {\n return [];\n }\n\n const register = Array.isArray(parameters.register) ? parameters.register : [];\n const components = Array.isArray(parameters.components) ? parameters.components : [];\n const items = Array.isArray(parameters.items) ? parameters.items : [];\n\n return [...register, ...components, ...items].filter(Boolean);\n}\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 const label = context.title && context.name ? `${context.title} / ${context.name}` : id;\n throw new Error(\n `Unable to render story ${label} as the component annotation is missing from the default export`\n );\n }\n return { Component, props: args };\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 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 = mergeStoryProps(parameters, args, story.props);\n\n const aureliaApp = appBootstrapFn(\n story,\n mergedProps,\n hostElement,\n component as Constructable,\n storyContext\n );\n await aureliaApp.start();\n appMap.set(rootElement, aureliaApp);\n app = aureliaApp;\n } else {\n // update existing app props\n const mergedProps = mergeStoryProps(parameters, 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 storyContext?: AureliaStoryContext\n) {\n const aurelia = new Aurelia(story.container);\n const { container } = aurelia;\n const aureliaParameters = getAureliaParameters(storyContext);\n\n const registerIfNeeded = (resource: unknown) => {\n if (!resource) {\n return;\n }\n\n if (CustomElement.isType(resource)) {\n const definition = CustomElement.getDefinition(resource);\n if (container.has(definition.key, false)) {\n return;\n }\n }\n\n aurelia.register(resource);\n };\n\n const registerAll = (resources?: unknown[]) => {\n if (!resources?.length) {\n return;\n }\n\n for (const resource of resources) {\n registerIfNeeded(resource);\n }\n };\n\n if (aureliaParameters?.configureContainer && storyContext) {\n aureliaParameters.configureContainer(container, storyContext);\n }\n\n registerAll(normalizeRegistrations(aureliaParameters));\n registerAll(story.items);\n\n const storyComponents = (story.components ?? []).filter(Boolean);\n const dedupedComponents = component\n ? storyComponents.filter((entry) => entry !== component)\n : storyComponents;\n\n for (const entry of dedupedComponents) {\n registerIfNeeded(entry);\n }\n\n let { template } = story;\n\n if (component) {\n template = template ?? createComponentTemplate(component, story.innerHtml);\n registerIfNeeded(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 if (aureliaParameters?.configure && storyContext) {\n aureliaParameters.configure(aurelia, storyContext);\n }\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 const bindings = Object.values(def.bindables)\n .map((bindable) => `${bindable.attribute}.bind=\"${bindable.name}\"`)\n .join(' ');\n const bindingAttributes = bindings ? ` ${bindings}` : '';\n\n return `<${def.name}${bindingAttributes}>${innerHtml ?? ''}</${def.name}>`;\n}\n","import type { AureliaStoryResult } from './types';\n\nexport function defineAureliaStory<TArgs = Record<string, unknown>>(\n story: AureliaStoryResult<TArgs>\n): AureliaStoryResult<TArgs> {\n return story;\n}\n"],"names":[],"mappings":";;AASA;AACA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB;AAE1C,SAAS,eAAe,CACtB,UAAsD,EACtD,SAA0C,EAC1C,UAA2C,EAAA;AAE3C,IAAA,OAAO,EAAE,GAAG,UAAU,EAAE,IAAI,EAAE,GAAG,SAAS,EAAE,GAAG,UAAU,EAAE;AAC7D;AAEA,SAAS,oBAAoB,CAC3B,YAAkC,EAAA;AAElC,IAAA,MAAM,UAAU,GAAG,YAAY,EAAE,UAAU,EAAE,OAAO;IACpD,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;AACjD,QAAA,OAAO,SAAS;IAClB;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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;AAE1C,IAAA,IAAI,iBAAiB,EAAE,SAAS,IAAI,YAAY,EAAE;AAChD,QAAA,iBAAiB,CAAC,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;IACpD;IAEA,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;IAElD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS;AACzC,SAAA,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAA,EAAG,QAAQ,CAAC,SAAS,CAAA,OAAA,EAAU,QAAQ,CAAC,IAAI,GAAG;SACjE,IAAI,CAAC,GAAG,CAAC;AACZ,IAAA,MAAM,iBAAiB,GAAG,QAAQ,GAAG,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAE,GAAG,EAAE;AAExD,IAAA,OAAO,CAAA,CAAA,EAAI,GAAG,CAAC,IAAI,GAAG,iBAAiB,CAAA,CAAA,EAAI,SAAS,IAAI,EAAE,CAAA,EAAA,EAAK,GAAG,CAAC,IAAI,GAAG;AAC5E;;AChPM,SAAU,kBAAkB,CAChC,KAAgC,EAAA;AAEhC,IAAA,OAAO,KAAK;AACd;;;;"}
1
+ {"version":3,"file":"preview.js","sources":["../src/preview/render.ts","../src/preview/helpers.ts"],"sourcesContent":["import type { RenderContext, ArgsStoryFn } from './storybook-types';\nimport type {\n AureliaRenderer,\n AureliaStoryResult,\n AureliaParameters,\n AureliaStoryContext,\n} from './types';\nimport Aurelia, { Constructable, CustomElement } from 'aurelia';\n\ninterface MountedAureliaApp {\n id?: string;\n app: any;\n}\n\nconst appMap = new Map<HTMLElement, MountedAureliaApp>();\n\nfunction mergeStoryProps(\n parameters: { args?: Record<string, any> } | undefined,\n storyArgs: Record<string, any> | undefined,\n storyProps: Record<string, any> | undefined\n) {\n return { ...parameters?.args, ...storyArgs, ...storyProps };\n}\n\nfunction getAureliaParameters(\n storyContext?: AureliaStoryContext\n): AureliaParameters | undefined {\n const parameters = storyContext?.parameters?.aurelia;\n if (!parameters || typeof parameters !== 'object') {\n return undefined;\n }\n return parameters as AureliaParameters;\n}\n\nfunction normalizeRegistrations(\n parameters: AureliaParameters | undefined\n): unknown[] {\n if (!parameters) {\n return [];\n }\n\n const register = Array.isArray(parameters.register) ? parameters.register : [];\n const components = Array.isArray(parameters.components) ? parameters.components : [];\n const items = Array.isArray(parameters.items) ? parameters.items : [];\n\n return [...register, ...components, ...items].filter(Boolean);\n}\n\nasync function teardown(element: HTMLElement, expectedApp?: any) {\n const mounted = appMap.get(element);\n if (!mounted) {\n return;\n }\n\n if (expectedApp && mounted.app !== expectedApp) {\n return;\n }\n\n appMap.delete(element);\n\n if (typeof mounted.app?.stop === 'function') {\n await mounted.app.stop();\n }\n}\n\nexport const render: ArgsStoryFn<AureliaRenderer> = (args, context) => {\n const { id, component: Component } = context;\n \n if (!Component) {\n const label = context.title && context.name ? `${context.title} / ${context.name}` : id;\n throw new Error(\n `Unable to render story ${label} as the component annotation is missing from the default export`\n );\n }\n return { Component, props: args };\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 const storyId = storyContext.id ?? `${title}--${name}`;\n \n const mounted = appMap.get(rootElement);\n let app = mounted?.app;\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 if (!component && !story.template) {\n showError({\n title: `Expecting a template or component from the story: \"${name}\" of \"${title}\".`,\n description: `\n Provide a component on the default export or return \"{ template: '<custom-component></custom-component>' }\" from the story.\n `,\n });\n return () => {};\n }\n\n showMain();\n\n const shouldRemount = !app || forceRemount || mounted?.id !== storyId;\n\n if (shouldRemount) {\n if (forceRemount && app) {\n await teardown(rootElement, app);\n app = undefined;\n }\n if (mounted?.id !== storyId && app) {\n await teardown(rootElement, app);\n app = undefined;\n }\n\n // Clear container before mounting new app\n hostElement.innerHTML = '';\n\n const mergedProps = mergeStoryProps(parameters, args, story.props);\n\n const aureliaApp = appBootstrapFn(\n story,\n mergedProps,\n hostElement,\n component as Constructable,\n storyContext\n );\n await aureliaApp.start();\n appMap.set(rootElement, { id: storyId, app: aureliaApp });\n app = aureliaApp;\n } else {\n // update existing app props\n const mergedProps = mergeStoryProps(parameters, 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 const appForCleanup = app;\n return async () => {\n await teardown(rootElement, appForCleanup);\n };\n}\n\nexport function createAureliaApp(\n story: AureliaStoryResult,\n args: Record<string, any>,\n domElement: HTMLElement,\n component?: Constructable,\n storyContext?: AureliaStoryContext\n) {\n const aurelia = new Aurelia(story.container);\n const { container } = aurelia;\n const aureliaParameters = getAureliaParameters(storyContext);\n\n const registerIfNeeded = (resource: unknown) => {\n if (!resource) {\n return;\n }\n\n if (CustomElement.isType(resource)) {\n const definition = CustomElement.getDefinition(resource);\n if (container.has(definition.key, false)) {\n return;\n }\n }\n\n aurelia.register(resource);\n };\n\n const registerAll = (resources?: unknown[]) => {\n if (!resources?.length) {\n return;\n }\n\n for (const resource of resources) {\n registerIfNeeded(resource);\n }\n };\n\n if (aureliaParameters?.configureContainer && storyContext) {\n aureliaParameters.configureContainer(container, storyContext);\n }\n\n registerAll(normalizeRegistrations(aureliaParameters));\n registerAll(story.items);\n\n const storyComponents = (story.components ?? []).filter(Boolean);\n const dedupedComponents = component\n ? storyComponents.filter((entry) => entry !== component)\n : storyComponents;\n\n for (const entry of dedupedComponents) {\n registerIfNeeded(entry);\n }\n\n let { template } = story;\n\n if (component) {\n template = template ?? createComponentTemplate(component, story.innerHtml);\n registerIfNeeded(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 if (aureliaParameters?.configure && storyContext) {\n aureliaParameters.configure(aurelia, storyContext);\n }\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 const bindings = Object.values(def.bindables ?? {})\n .map((bindable) => `${bindable.attribute}.bind=\"${bindable.name}\"`)\n .join(' ');\n const bindingAttributes = bindings ? ` ${bindings}` : '';\n\n return `<${def.name}${bindingAttributes}>${innerHtml ?? ''}</${def.name}>`;\n}\n","import type { AureliaStoryResult } from './types';\n\nexport function defineAureliaStory<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,IAAA,OAAO,KAAK;AACd;;;;"}
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "@aurelia/storybook",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "A Storybook plugin to render Aurelia 2 components using Vite, Webpack, or Rsbuild/Rspack",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "sideEffects": false,
9
+ "files": [
10
+ "dist",
11
+ "preset.js",
12
+ "README.md",
13
+ "CHANGELOG.md",
14
+ "LICENSE"
15
+ ],
9
16
  "publishConfig": {
10
17
  "access": "public"
11
18
  },
@@ -22,14 +29,14 @@
22
29
  "test": "NODE_OPTIONS=--no-deprecation jest"
23
30
  },
24
31
  "peerDependencies": {
25
- "@aurelia/runtime-html": "^2.0.0-rc.0",
26
- "@aurelia/vite-plugin": "^2.0.0-rc.0",
27
- "@rsbuild/core": "^1.7.2",
28
- "@storybook/builder-vite": "^10.2.0",
29
- "@storybook/builder-webpack5": "^10.2.0",
30
- "aurelia": "^2.0.0-rc.0",
31
- "storybook": "^10.2.0",
32
- "storybook-builder-rsbuild": "^3.2.2"
32
+ "@aurelia/runtime-html": "^2.0.0-rc.1",
33
+ "@aurelia/vite-plugin": "^2.0.0-rc.1",
34
+ "@rsbuild/core": "^1.7.2 || ^2.0.0",
35
+ "@storybook/builder-vite": "^10.4.1",
36
+ "@storybook/builder-webpack5": "^10.4.1",
37
+ "aurelia": "^2.0.0-rc.1",
38
+ "storybook": "^10.4.1",
39
+ "storybook-builder-rsbuild": "^3.3.4"
33
40
  },
34
41
  "peerDependenciesMeta": {
35
42
  "@rsbuild/core": {
@@ -46,23 +53,31 @@
46
53
  }
47
54
  },
48
55
  "devDependencies": {
49
- "@aurelia/webpack-loader": "^2.0.0-rc.0",
56
+ "@aurelia/webpack-loader": "^2.0.0-rc.1",
50
57
  "@rollup/plugin-commonjs": "^28.0.6",
51
58
  "@rollup/plugin-node-resolve": "^16.0.1",
52
59
  "@rollup/plugin-typescript": "^12.1.3",
53
- "@rsbuild/core": "^1.7.2",
54
- "@storybook/builder-vite": "^10.2.0",
60
+ "@rsbuild/core": "^2.0.9",
61
+ "@storybook/builder-vite": "^10.4.1",
55
62
  "@types/jest": "^30.0.0",
56
63
  "conventional-changelog-cli": "^5.0.0",
57
64
  "conventional-changelog-conventionalcommits": "^8.0.0",
58
65
  "glob": "^11.0.3",
59
66
  "jest": "^30.0.2",
60
67
  "jest-environment-jsdom": "^30.0.2",
61
- "rollup": "^4.44.0",
62
- "storybook": "^10.2.0",
68
+ "postcss": "^8.5.15",
69
+ "rollup": "^4.61.0",
70
+ "storybook": "^10.4.1",
63
71
  "ts-jest": "^29.4.0",
64
72
  "ts-loader": "^9.5.2",
65
- "typescript": "^5.8.3"
73
+ "typescript": "^5.8.3",
74
+ "vite": "^7.3.5"
75
+ },
76
+ "overrides": {
77
+ "picomatch": "^4.0.4",
78
+ "postcss": "^8.5.15",
79
+ "rollup": "^4.61.0",
80
+ "vite": "^7.3.5"
66
81
  },
67
82
  "exports": {
68
83
  ".": {
package/preset.js CHANGED
@@ -1 +1,2 @@
1
- module.exports = require('./dist/preset');
1
+ export * from './dist/preset.js';
2
+ export { default } from './dist/preset.js';
@@ -1,61 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- pull_request:
6
-
7
- jobs:
8
- build:
9
- runs-on: ubuntu-latest
10
-
11
- steps:
12
- - name: Checkout
13
- uses: actions/checkout@v4
14
-
15
- - name: Setup Node
16
- uses: actions/setup-node@v4
17
- with:
18
- node-version: 20.19.0
19
- cache: npm
20
-
21
- - name: Install root deps
22
- run: npm install
23
-
24
- - name: Verify example versions are aligned
25
- run: npm run sync:versions:check
26
-
27
- - name: Build package
28
- run: npm run build
29
-
30
- - name: Build types
31
- run: npm run build:types
32
-
33
- - name: Test package
34
- run: npm test
35
-
36
- - name: Build hello-world (Vite)
37
- working-directory: apps/hello-world
38
- run: |
39
- npm pkg set "devDependencies.@aurelia/storybook=file:../.."
40
- npm install
41
- npx tsc --noEmit -p tsconfig.json
42
- npm run build
43
- npm run build-storybook
44
-
45
- - name: Build hello-world-webpack
46
- working-directory: apps/hello-world-webpack
47
- run: |
48
- npm pkg set "devDependencies.@aurelia/storybook=file:../.."
49
- npm install
50
- npx tsc --noEmit -p tsconfig.json
51
- npm run build
52
- npm run build-storybook
53
-
54
- - name: Build hello-world-rsbuild
55
- working-directory: apps/hello-world-rsbuild
56
- run: |
57
- npm pkg set "devDependencies.@aurelia/storybook=file:../.."
58
- npm install
59
- npx tsc --noEmit -p tsconfig.json
60
- npm run build
61
- npm run build-storybook
@@ -1,82 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- push:
5
- tags:
6
- - 'v*'
7
- workflow_dispatch:
8
- inputs:
9
- tag:
10
- description: 'Tag to publish (e.g., v2.2.1)'
11
- required: true
12
- type: string
13
-
14
- jobs:
15
- publish:
16
- runs-on: ubuntu-latest
17
- permissions:
18
- contents: read
19
- id-token: write
20
-
21
- steps:
22
- - name: Checkout
23
- uses: actions/checkout@v4
24
- with:
25
- ref: ${{ inputs.tag || github.ref }}
26
-
27
- - name: Setup Node
28
- uses: actions/setup-node@v4
29
- with:
30
- node-version: 20.19.0
31
- registry-url: https://registry.npmjs.org
32
- cache: npm
33
-
34
- - name: Install deps
35
- run: npm install
36
-
37
- - name: Verify versions aligned
38
- run: npm run sync:versions:check
39
-
40
- - name: Verify tag matches package version
41
- run: |
42
- TAG_INPUT="${{ inputs.tag }}"
43
- if [ -n "$TAG_INPUT" ]; then
44
- TAG="${TAG_INPUT#v}"
45
- else
46
- TAG="${GITHUB_REF_NAME#v}"
47
- fi
48
- VERSION="$(node -p "require('./package.json').version")"
49
- if [ "$TAG" != "$VERSION" ]; then
50
- echo "Tag ($TAG) does not match package.json version ($VERSION)"
51
- exit 1
52
- fi
53
-
54
- - name: Build package
55
- run: npm run build
56
-
57
- - name: Build types
58
- run: npm run build:types
59
-
60
- - name: Test package
61
- run: npm test
62
-
63
- - name: Verify changelog exists
64
- run: |
65
- if [ ! -s CHANGELOG.md ]; then
66
- echo "CHANGELOG.md is empty. Run npm run changelog before tagging."
67
- exit 1
68
- fi
69
-
70
- - name: Verify changelog version matches package
71
- run: |
72
- VERSION="$(node -p "require('./package.json').version")"
73
- CHANGELOG_VERSION="$(node -e "const fs=require('fs');const m=fs.readFileSync('CHANGELOG.md','utf8').match(/## \\[(\\d+\\.\\d+\\.\\d+(?:-[^\\]]+)?)\\]/);console.log(m?m[1]:'')")"
74
- if [ "$VERSION" != "$CHANGELOG_VERSION" ]; then
75
- echo "CHANGELOG.md latest version ($CHANGELOG_VERSION) does not match package.json ($VERSION)"
76
- exit 1
77
- fi
78
-
79
- - name: Publish to npm
80
- run: npm publish --access public
81
- env:
82
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -1,62 +0,0 @@
1
- name: Storybook Preview
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
- workflow_dispatch:
8
-
9
- permissions:
10
- contents: read
11
- pages: write
12
- id-token: write
13
-
14
- concurrency:
15
- group: pages
16
- cancel-in-progress: true
17
-
18
- jobs:
19
- build:
20
- runs-on: ubuntu-latest
21
-
22
- steps:
23
- - name: Checkout
24
- uses: actions/checkout@v4
25
-
26
- - name: Setup Node
27
- uses: actions/setup-node@v4
28
- with:
29
- node-version: 20.19.0
30
- cache: npm
31
-
32
- - name: Install root deps
33
- run: npm install
34
-
35
- - name: Build package
36
- run: npm run build
37
-
38
- - name: Build Storybook (hello-world)
39
- working-directory: apps/hello-world
40
- run: |
41
- npm pkg set "devDependencies.@aurelia/storybook=file:../.."
42
- npm install
43
- npm run build-storybook
44
-
45
- - name: Configure Pages
46
- uses: actions/configure-pages@v5
47
-
48
- - name: Upload Pages artifact
49
- uses: actions/upload-pages-artifact@v3
50
- with:
51
- path: apps/hello-world/storybook-static
52
-
53
- deploy:
54
- runs-on: ubuntu-latest
55
- needs: build
56
- environment:
57
- name: github-pages
58
- url: ${{ steps.deployment.outputs.page_url }}
59
- steps:
60
- - name: Deploy to GitHub Pages
61
- id: deployment
62
- uses: actions/deploy-pages@v4
@@ -1,94 +0,0 @@
1
- import { createAureliaApp } from '../src/preview/render';
2
-
3
- jest.mock('aurelia', () => {
4
- let lastInstance: any;
5
-
6
- class Aurelia {
7
- public container: { has: jest.Mock };
8
- public register = jest.fn();
9
- public app = jest.fn(() => ({}));
10
-
11
- constructor(container?: unknown) {
12
- this.container = (container as any) ?? { has: jest.fn(() => false) };
13
- lastInstance = this;
14
- }
15
- }
16
-
17
- const CustomElement = {
18
- define: jest.fn((definition: unknown, Type: new () => unknown) => Type),
19
- getDefinition: jest.fn(() => ({ name: 'dummy', bindables: {}, key: 'au:ce:dummy' })),
20
- isType: jest.fn(() => true),
21
- };
22
-
23
- return {
24
- __esModule: true,
25
- default: Aurelia,
26
- CustomElement,
27
- __getLastInstance: () => lastInstance,
28
- };
29
- });
30
-
31
- describe('createAureliaApp', () => {
32
- it('does not double-register the component when included in components', () => {
33
- const Component = class {};
34
- const host = document.createElement('div');
35
-
36
- createAureliaApp(
37
- { template: '<dummy></dummy>', components: [Component] } as any,
38
- {},
39
- host,
40
- Component as any
41
- );
42
-
43
- const aurelia = (jest.requireMock('aurelia') as any).__getLastInstance();
44
- const registerArgs = aurelia.register.mock.calls.flat();
45
- const registrations = registerArgs.filter((entry: unknown) => entry === Component);
46
- expect(registrations).toHaveLength(1);
47
- });
48
-
49
- it('skips registration when the container already has the component key', () => {
50
- const Component = class {};
51
- const host = document.createElement('div');
52
- const container = { has: jest.fn(() => true) };
53
-
54
- createAureliaApp(
55
- { template: '<dummy></dummy>', components: [] as any, container } as any,
56
- {},
57
- host,
58
- Component as any
59
- );
60
-
61
- const aurelia = (jest.requireMock('aurelia') as any).__getLastInstance();
62
- expect(container.has).toHaveBeenCalled();
63
- expect(aurelia.register).not.toHaveBeenCalled();
64
- });
65
-
66
- it('applies parameters.aurelia registrations and hooks', () => {
67
- const GlobalComponent = class {};
68
- const host = document.createElement('div');
69
- const configureContainer = jest.fn();
70
- const configure = jest.fn();
71
- const storyContext = {
72
- parameters: {
73
- aurelia: {
74
- register: [GlobalComponent],
75
- configureContainer,
76
- configure,
77
- },
78
- },
79
- } as any;
80
-
81
- createAureliaApp(
82
- { template: '<dummy></dummy>' } as any,
83
- {},
84
- host,
85
- undefined,
86
- storyContext
87
- );
88
-
89
- const aurelia = (jest.requireMock('aurelia') as any).__getLastInstance();
90
- expect(configureContainer).toHaveBeenCalledWith(aurelia.container, storyContext);
91
- expect(aurelia.register).toHaveBeenCalledWith(GlobalComponent);
92
- expect(configure).toHaveBeenCalledWith(aurelia, storyContext);
93
- });
94
- });
@@ -1,78 +0,0 @@
1
- import { rsbuildFinal, webpackFinal, viteFinal } from '../src/preset';
2
- import { getRsbuildRules, getRules } from '../src/webpack';
3
-
4
- jest.mock('../src/webpack', () => ({
5
- getRules: jest.fn(() => [
6
- { test: /\.ts$/, use: 'ts-loader' },
7
- { test: /\.html$/, use: 'html-loader' },
8
- ]),
9
- getRsbuildRules: jest.fn(() => [
10
- { test: /\.ts$/, use: '@aurelia/webpack-loader' },
11
- { test: /\.html$/, use: '@aurelia/webpack-loader' },
12
- ]),
13
- }));
14
-
15
- const mergeRsbuildConfig = jest.fn((base, extra) => ({
16
- ...base,
17
- ...extra,
18
- tools: {
19
- ...base?.tools,
20
- ...extra?.tools,
21
- },
22
- }));
23
-
24
- jest.mock('@rsbuild/core', () => ({
25
- mergeRsbuildConfig,
26
- }));
27
-
28
- describe('preset', () => {
29
- describe('webpackFinal', () => {
30
- it('should add rules to the webpack config', async () => {
31
- const config = {
32
- module: {
33
- rules: [],
34
- },
35
- };
36
- const result = await webpackFinal(config);
37
- expect(result.module.rules).toEqual(getRules());
38
- expect(getRules).toHaveBeenCalled();
39
- });
40
-
41
- it('should handle a config with no module.rules', async () => {
42
- const config = {};
43
- const result = await webpackFinal(config);
44
- expect(result).toEqual(config);
45
- });
46
-
47
- it('should handle a config with existing rules', async () => {
48
- const existingRule = { test: /\.js$/, use: 'babel-loader' };
49
- const config = {
50
- module: {
51
- rules: [existingRule],
52
- },
53
- };
54
- const result = await webpackFinal(config);
55
- expect(result.module.rules).toEqual([existingRule, ...getRules()]);
56
- });
57
- });
58
-
59
- describe('viteFinal', () => {
60
- it('should return the config unchanged', async () => {
61
- const config = { some: 'property' };
62
- const result = await viteFinal(config);
63
- expect(result).toBe(config);
64
- });
65
- });
66
-
67
- describe('rsbuildFinal', () => {
68
- it('should merge rsbuild config and add Aurelia rules', async () => {
69
- const config = { tools: {} };
70
- const result = await rsbuildFinal(config);
71
- expect(mergeRsbuildConfig).toHaveBeenCalledWith(config, expect.any(Object));
72
-
73
- const rspackConfig = { module: { rules: [] as any[] } };
74
- result.tools.rspack(rspackConfig);
75
- expect(rspackConfig.module.rules).toEqual(getRsbuildRules());
76
- });
77
- });
78
- });
@@ -1,17 +0,0 @@
1
- import { defineAureliaStory, render, renderToCanvas } from '../src/preview';
2
- import * as renderUtils from '../src/preview/render';
3
-
4
- describe('preview', () => {
5
- it('re-exports render', () => {
6
- expect(render).toBe(renderUtils.render);
7
- });
8
-
9
- it('re-exports renderToCanvas', () => {
10
- expect(renderToCanvas).toBe(renderUtils.renderToCanvas);
11
- });
12
-
13
- it('returns the provided story result from defineAureliaStory', () => {
14
- const story = { template: '<div></div>' };
15
- expect(defineAureliaStory(story)).toBe(story);
16
- });
17
- });