@aurelia/storybook 2.0.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +61 -0
- package/.github/workflows/publish.yml +82 -0
- package/.github/workflows/storybook-preview.yml +62 -0
- package/CHANGELOG.md +5 -0
- package/README.md +381 -148
- package/__tests__/create-aurelia-app.test.ts +94 -0
- package/__tests__/preset.test.ts +32 -3
- package/__tests__/preview.test.ts +9 -131
- package/__tests__/render.test.ts +15 -26
- package/apps/hello-world/.storybook/main.ts +0 -1
- package/apps/hello-world/package-lock.json +4585 -2609
- package/apps/hello-world/package.json +13 -23
- package/apps/hello-world/src/components/feedback-form.html +111 -0
- package/apps/hello-world/src/components/feedback-form.ts +45 -0
- package/apps/hello-world/src/components/notification-center.html +119 -0
- package/apps/hello-world/src/components/notification-center.ts +27 -0
- package/apps/hello-world/src/components/stat-card.html +107 -0
- package/apps/hello-world/src/components/stat-card.ts +41 -0
- package/apps/hello-world/src/components/weather-widget.html +89 -0
- package/apps/hello-world/src/components/weather-widget.ts +31 -0
- package/apps/hello-world/src/hello-world.html +44 -2
- package/apps/hello-world/src/services/weather-service.ts +15 -0
- package/apps/hello-world/src/stories/feedback-form.stories.ts +58 -0
- package/apps/hello-world/src/stories/hello-world.stories.ts +24 -14
- package/apps/hello-world/src/stories/notification-center.stories.ts +88 -0
- package/apps/hello-world/src/stories/stat-card.stories.ts +75 -0
- package/apps/hello-world/src/stories/weather-widget.stories.ts +62 -0
- package/apps/hello-world/tsconfig.json +4 -3
- package/apps/hello-world/vite.config.ts +0 -2
- package/apps/hello-world-rsbuild/.storybook/main.ts +16 -0
- package/apps/hello-world-rsbuild/.storybook/preview.ts +1 -0
- package/apps/hello-world-rsbuild/.stylelintrc.json +5 -0
- package/apps/hello-world-rsbuild/README.md +28 -0
- package/apps/hello-world-rsbuild/eslint.config.mjs +25 -0
- package/apps/hello-world-rsbuild/favicon.ico +0 -0
- package/apps/hello-world-rsbuild/index.html +17 -0
- package/apps/hello-world-rsbuild/package-lock.json +11131 -0
- package/apps/hello-world-rsbuild/package.json +56 -0
- package/apps/hello-world-rsbuild/src/components/feedback-form.html +111 -0
- package/apps/hello-world-rsbuild/src/components/feedback-form.ts +45 -0
- package/apps/hello-world-rsbuild/src/components/notification-center.html +119 -0
- package/apps/hello-world-rsbuild/src/components/notification-center.ts +27 -0
- package/apps/hello-world-rsbuild/src/components/stat-card.html +107 -0
- package/apps/hello-world-rsbuild/src/components/stat-card.ts +41 -0
- package/apps/hello-world-rsbuild/src/components/weather-widget.html +89 -0
- package/apps/hello-world-rsbuild/src/components/weather-widget.ts +31 -0
- package/apps/hello-world-rsbuild/src/hello-world.html +48 -0
- package/apps/hello-world-rsbuild/src/hello-world.ts +17 -0
- package/apps/hello-world-rsbuild/src/main.ts +6 -0
- package/apps/hello-world-rsbuild/src/my-app.html +1 -0
- package/apps/hello-world-rsbuild/src/my-app.ts +3 -0
- package/apps/hello-world-rsbuild/src/resource.d.ts +15 -0
- package/apps/hello-world-rsbuild/src/services/weather-service.ts +15 -0
- package/apps/hello-world-rsbuild/src/stories/feedback-form.stories.ts +58 -0
- package/apps/hello-world-rsbuild/src/stories/hello-world.stories.ts +64 -0
- package/apps/hello-world-rsbuild/src/stories/notification-center.stories.ts +88 -0
- package/apps/hello-world-rsbuild/src/stories/stat-card.stories.ts +75 -0
- package/apps/hello-world-rsbuild/src/stories/weather-widget.stories.ts +62 -0
- package/apps/hello-world-rsbuild/test/my-app.spec.ts +15 -0
- package/apps/hello-world-rsbuild/test/setup.ts +29 -0
- package/apps/hello-world-rsbuild/tsconfig.json +19 -0
- package/apps/hello-world-rsbuild/tsconfig.vitest.json +11 -0
- package/apps/hello-world-rsbuild/vite.config.ts +17 -0
- package/apps/hello-world-rsbuild/vitest.config.ts +15 -0
- package/apps/hello-world-webpack/.storybook/main.ts +0 -1
- package/apps/hello-world-webpack/package-lock.json +3553 -768
- package/apps/hello-world-webpack/package.json +8 -10
- package/apps/hello-world-webpack/src/components/feedback-form.html +111 -0
- package/apps/hello-world-webpack/src/components/feedback-form.ts +45 -0
- package/apps/hello-world-webpack/src/components/notification-center.html +119 -0
- package/apps/hello-world-webpack/src/components/notification-center.ts +27 -0
- package/apps/hello-world-webpack/src/components/stat-card.html +107 -0
- package/apps/hello-world-webpack/src/components/stat-card.ts +41 -0
- package/apps/hello-world-webpack/src/components/weather-widget.html +89 -0
- package/apps/hello-world-webpack/src/components/weather-widget.ts +31 -0
- package/apps/hello-world-webpack/src/hello-world.html +44 -2
- package/apps/hello-world-webpack/src/my-app.stories.ts +6 -4
- package/apps/hello-world-webpack/src/services/weather-service.ts +15 -0
- package/apps/hello-world-webpack/src/stories/feedback-form.stories.ts +58 -0
- package/apps/hello-world-webpack/src/stories/hello-world.stories.ts +25 -15
- package/apps/hello-world-webpack/src/stories/notification-center.stories.ts +88 -0
- package/apps/hello-world-webpack/src/stories/stat-card.stories.ts +75 -0
- package/apps/hello-world-webpack/src/stories/weather-widget.stories.ts +62 -0
- package/apps/hello-world-webpack/tsconfig.json +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/index.js +68 -14
- package/dist/index.js.map +1 -1
- package/dist/preset.d.ts +21 -0
- package/dist/preset.js +46 -2
- package/dist/preset.js.map +1 -1
- package/dist/preview/helpers.d.ts +2 -0
- package/dist/preview/helpers.js +6 -0
- package/dist/preview/helpers.js.map +1 -0
- package/dist/preview/render.d.ts +7 -0
- package/dist/preview/render.js +66 -15
- package/dist/preview/render.js.map +1 -1
- package/dist/preview/storybook-types-runtime.d.ts +1 -0
- package/dist/preview/storybook-types-runtime.js +5 -0
- package/dist/preview/storybook-types-runtime.js.map +1 -0
- package/dist/preview/storybook-types.d.ts +27 -0
- package/dist/preview/types-runtime.d.ts +1 -0
- package/dist/preview/types-runtime.js +5 -0
- package/dist/preview/types-runtime.js.map +1 -0
- package/dist/preview/types.d.ts +44 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +71 -16
- package/dist/preview.js.map +1 -1
- package/dist/webpack.d.ts +10 -0
- package/dist/webpack.js +19 -1
- package/dist/webpack.js.map +1 -1
- package/package.json +58 -13
- package/rollup.config.mjs +5 -3
- package/scripts/sync-versions.cjs +55 -0
- package/src/index.ts +11 -1
- package/src/preset.ts +32 -2
- package/src/preview/helpers.ts +7 -0
- package/src/preview/render.ts +98 -30
- package/src/preview/storybook-types-runtime.ts +2 -0
- package/src/preview/storybook-types.ts +34 -0
- package/src/preview/types-runtime.ts +2 -0
- package/src/preview/types.ts +57 -2
- package/src/preview.ts +11 -1
- package/src/webpack.ts +19 -0
- package/apps/hello-world/.yarnrc.yml +0 -2
- package/apps/hello-world-webpack/.yarnrc.yml +0 -2
- package/dist/index.mjs +0 -132
- package/dist/index.mjs.map +0 -1
- package/dist/preset.mjs +0 -60
- package/dist/preset.mjs.map +0 -1
- package/dist/preview/render.mjs +0 -114
- package/dist/preview/render.mjs.map +0 -1
- package/dist/preview/types.js +0 -2
- package/dist/preview/types.js.map +0 -1
- package/dist/preview/types.mjs +0 -2
- package/dist/preview/types.mjs.map +0 -1
- package/dist/preview.mjs +0 -114
- package/dist/preview.mjs.map +0 -1
- package/dist/webpack.mjs +0 -21
- package/dist/webpack.mjs.map +0 -1
- /package/{jest.config.js → jest.config.cjs} +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DI } from 'aurelia';
|
|
2
|
+
|
|
3
|
+
export interface WeatherSummary {
|
|
4
|
+
location: string;
|
|
5
|
+
condition: string;
|
|
6
|
+
temperature: number;
|
|
7
|
+
high: number;
|
|
8
|
+
low: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface WeatherService {
|
|
12
|
+
getWeather(location: string): Promise<WeatherSummary>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const IWeatherService = DI.createInterface<WeatherService>('IWeatherService');
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { defineAureliaStory } from '@aurelia/storybook';
|
|
2
|
+
import { fn, userEvent, within } from 'storybook/test';
|
|
3
|
+
import { FeedbackForm } from '../components/feedback-form';
|
|
4
|
+
|
|
5
|
+
type FeedbackFormArgs = {
|
|
6
|
+
topics: string[];
|
|
7
|
+
submitting?: boolean;
|
|
8
|
+
onSubmit?: (payload: unknown) => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
title: 'Dashboard/FeedbackForm',
|
|
13
|
+
component: FeedbackForm,
|
|
14
|
+
parameters: {
|
|
15
|
+
layout: 'centered',
|
|
16
|
+
},
|
|
17
|
+
render: (args: FeedbackFormArgs) =>
|
|
18
|
+
defineAureliaStory({
|
|
19
|
+
template: `<feedback-form topics.bind="topics"
|
|
20
|
+
submitting.bind="submitting"
|
|
21
|
+
on-submit.bind="onSubmit"></feedback-form>`,
|
|
22
|
+
props: args,
|
|
23
|
+
components: [FeedbackForm],
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
export const DefaultForm = {
|
|
30
|
+
args: {
|
|
31
|
+
topics: ['Bug report', 'Feature request', 'General question'],
|
|
32
|
+
onSubmit: fn(),
|
|
33
|
+
submitting: false,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const SubmittingState = {
|
|
38
|
+
args: {
|
|
39
|
+
topics: ['Design review', 'Accessibility', 'Performance'],
|
|
40
|
+
submitting: true,
|
|
41
|
+
onSubmit: fn(),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const FillAndSubmit = {
|
|
46
|
+
args: {
|
|
47
|
+
topics: ['Beta feedback', 'Success story'],
|
|
48
|
+
onSubmit: fn(),
|
|
49
|
+
},
|
|
50
|
+
play: async ({ canvasElement }) => {
|
|
51
|
+
const canvas = within(canvasElement);
|
|
52
|
+
await userEvent.type(canvas.getByLabelText('Name'), 'Jordan');
|
|
53
|
+
await userEvent.type(canvas.getByLabelText('Email'), 'jordan@example.com');
|
|
54
|
+
await userEvent.selectOptions(canvas.getByLabelText('Topic'), 'Success story');
|
|
55
|
+
await userEvent.type(canvas.getByLabelText('Message'), 'The new timeline view is great');
|
|
56
|
+
await userEvent.click(canvas.getByRole('button', { name: /send feedback/i }));
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
import { defineAureliaStory } from '@aurelia/storybook';
|
|
1
2
|
import { HelloWorld } from '../hello-world';
|
|
2
|
-
import { fn } from '
|
|
3
|
-
|
|
3
|
+
import { fn, userEvent, within } from 'storybook/test';
|
|
4
|
+
|
|
5
|
+
type HelloWorldArgs = {
|
|
6
|
+
message?: string;
|
|
7
|
+
onIncrement?: () => void;
|
|
8
|
+
};
|
|
4
9
|
|
|
5
10
|
const meta = {
|
|
6
11
|
title: 'Example/HelloWorld',
|
|
7
12
|
component: HelloWorld,
|
|
8
|
-
render: () =>
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
render: (args: HelloWorldArgs) =>
|
|
14
|
+
defineAureliaStory({
|
|
15
|
+
template: `<hello-world message.bind="message" on-increment.bind="onIncrement"></hello-world>`,
|
|
16
|
+
props: args,
|
|
17
|
+
}),
|
|
11
18
|
argTypes: {
|
|
12
19
|
message: { control: 'text' },
|
|
13
20
|
onIncrement: { action: 'increment' }
|
|
@@ -18,14 +25,14 @@ export default meta;
|
|
|
18
25
|
|
|
19
26
|
export const DefaultHelloWorld = {
|
|
20
27
|
args: {
|
|
21
|
-
message:
|
|
28
|
+
message: 'Hello from Aurelia Storybook',
|
|
22
29
|
onIncrement: fn()
|
|
23
30
|
}
|
|
24
31
|
};
|
|
25
32
|
|
|
26
33
|
export const InteractiveHelloWorld = {
|
|
27
34
|
args: {
|
|
28
|
-
message:
|
|
35
|
+
message: 'Try clicking the button!',
|
|
29
36
|
onIncrement: fn()
|
|
30
37
|
},
|
|
31
38
|
play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
|
|
@@ -39,16 +46,19 @@ export const InteractiveHelloWorld = {
|
|
|
39
46
|
};
|
|
40
47
|
|
|
41
48
|
export const NoArgs = {
|
|
42
|
-
render: () =>
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
render: () =>
|
|
50
|
+
defineAureliaStory({
|
|
51
|
+
template: `<hello-world></hello-world>`,
|
|
52
|
+
})
|
|
45
53
|
};
|
|
46
54
|
|
|
47
55
|
export const WithCustomTemplate = {
|
|
48
|
-
render: () =>
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
render: (args: HelloWorldArgs) =>
|
|
57
|
+
defineAureliaStory({
|
|
58
|
+
template: `<hello-world message.bind="message">Click me!</hello-world>`,
|
|
59
|
+
props: args,
|
|
60
|
+
}),
|
|
51
61
|
args: {
|
|
52
|
-
message:
|
|
62
|
+
message: 'This is a custom message'
|
|
53
63
|
}
|
|
54
|
-
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { defineAureliaStory } from '@aurelia/storybook';
|
|
2
|
+
import { fn, userEvent, within } from 'storybook/test';
|
|
3
|
+
import { NotificationCenter, NotificationItem } from '../components/notification-center';
|
|
4
|
+
|
|
5
|
+
type NotificationCenterArgs = {
|
|
6
|
+
notifications: NotificationItem[];
|
|
7
|
+
maxVisible?: number;
|
|
8
|
+
showTimestamp?: boolean;
|
|
9
|
+
onDismiss?: (item: NotificationItem) => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const baseNotifications: NotificationItem[] = [
|
|
13
|
+
{
|
|
14
|
+
id: 1,
|
|
15
|
+
title: 'Build succeeded',
|
|
16
|
+
message: 'Main pipeline finished in 4m 12s.',
|
|
17
|
+
level: 'success',
|
|
18
|
+
timestamp: 'Today - 09:24',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: 2,
|
|
22
|
+
title: 'New comment',
|
|
23
|
+
message: 'Samira replied to your review on PR #512.',
|
|
24
|
+
level: 'info',
|
|
25
|
+
timestamp: 'Today - 08:51',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 3,
|
|
29
|
+
title: 'Usage warning',
|
|
30
|
+
message: 'API quota is at 85% of the monthly allocation.',
|
|
31
|
+
level: 'warning',
|
|
32
|
+
timestamp: 'Yesterday - 17:05',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 4,
|
|
36
|
+
title: 'Error spike',
|
|
37
|
+
message: 'Synthetic tests detected an uptick in 500s.',
|
|
38
|
+
level: 'error',
|
|
39
|
+
timestamp: 'Yesterday - 15:33',
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const meta = {
|
|
44
|
+
title: 'Dashboard/NotificationCenter',
|
|
45
|
+
component: NotificationCenter,
|
|
46
|
+
render: (args: NotificationCenterArgs) =>
|
|
47
|
+
defineAureliaStory({
|
|
48
|
+
template: `<notification-center notifications.bind="notifications"
|
|
49
|
+
max-visible.bind="maxVisible"
|
|
50
|
+
on-dismiss.bind="onDismiss"
|
|
51
|
+
show-timestamp.bind="showTimestamp"></notification-center>`,
|
|
52
|
+
props: args,
|
|
53
|
+
components: [NotificationCenter],
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default meta;
|
|
58
|
+
|
|
59
|
+
export const DefaultNotifications = {
|
|
60
|
+
args: {
|
|
61
|
+
notifications: baseNotifications,
|
|
62
|
+
maxVisible: 3,
|
|
63
|
+
showTimestamp: true,
|
|
64
|
+
onDismiss: fn(),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const CompactList = {
|
|
69
|
+
args: {
|
|
70
|
+
notifications: baseNotifications.slice(0, 2),
|
|
71
|
+
maxVisible: 2,
|
|
72
|
+
onDismiss: fn(),
|
|
73
|
+
showTimestamp: false,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const Interactions = {
|
|
78
|
+
args: {
|
|
79
|
+
notifications: baseNotifications,
|
|
80
|
+
maxVisible: 4,
|
|
81
|
+
onDismiss: fn(),
|
|
82
|
+
},
|
|
83
|
+
play: async ({ canvasElement }) => {
|
|
84
|
+
const canvas = within(canvasElement);
|
|
85
|
+
const dismissButtons = await canvas.findAllByRole('button', { name: /dismiss/i });
|
|
86
|
+
await userEvent.click(dismissButtons[0]);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { defineAureliaStory } from '@aurelia/storybook';
|
|
2
|
+
import { fn, userEvent, within } from 'storybook/test';
|
|
3
|
+
import { StatCard } from '../components/stat-card';
|
|
4
|
+
|
|
5
|
+
type StatCardArgs = {
|
|
6
|
+
title: string;
|
|
7
|
+
value: number | string;
|
|
8
|
+
unit?: string;
|
|
9
|
+
change?: number;
|
|
10
|
+
changeCopy?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
onRefresh?: () => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const meta = {
|
|
16
|
+
title: 'Dashboard/StatCard',
|
|
17
|
+
component: StatCard,
|
|
18
|
+
parameters: {
|
|
19
|
+
layout: 'centered',
|
|
20
|
+
},
|
|
21
|
+
render: (args: StatCardArgs) =>
|
|
22
|
+
defineAureliaStory({
|
|
23
|
+
components: [StatCard],
|
|
24
|
+
template: `<stat-card title.bind="title"
|
|
25
|
+
value.bind="value"
|
|
26
|
+
unit.bind="unit"
|
|
27
|
+
change.bind="change"
|
|
28
|
+
change-copy.bind="changeCopy"
|
|
29
|
+
description.bind="description"
|
|
30
|
+
on-refresh.bind="onRefresh"></stat-card>`,
|
|
31
|
+
props: args,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default meta;
|
|
36
|
+
|
|
37
|
+
export const DefaultCard = {
|
|
38
|
+
args: {
|
|
39
|
+
title: 'Active users',
|
|
40
|
+
value: 1284,
|
|
41
|
+
unit: '',
|
|
42
|
+
change: 12.5,
|
|
43
|
+
changeCopy: 'vs last week',
|
|
44
|
+
description: 'Rolling 7-day average of unique user sessions.',
|
|
45
|
+
onRefresh: fn(),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const NegativeTrend = {
|
|
50
|
+
args: {
|
|
51
|
+
title: 'NPS score',
|
|
52
|
+
value: 42,
|
|
53
|
+
change: -6.3,
|
|
54
|
+
changeCopy: 'vs previous survey',
|
|
55
|
+
description: 'Direct feedback collected from in-app survey responses.',
|
|
56
|
+
onRefresh: fn(),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const ManualRefreshDemo = {
|
|
61
|
+
args: {
|
|
62
|
+
title: 'Deploy success rate',
|
|
63
|
+
value: '99.2',
|
|
64
|
+
unit: '%',
|
|
65
|
+
change: 1.1,
|
|
66
|
+
changeCopy: 'vs last 24h',
|
|
67
|
+
description: 'Completed deploys without rollbacks.',
|
|
68
|
+
onRefresh: fn(),
|
|
69
|
+
},
|
|
70
|
+
play: async ({ canvasElement }) => {
|
|
71
|
+
const canvas = within(canvasElement);
|
|
72
|
+
const refreshButton = await canvas.findByRole('button', { name: /refresh metric/i });
|
|
73
|
+
await userEvent.click(refreshButton);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defineAureliaStory } from '@aurelia/storybook';
|
|
2
|
+
import { Registration } from 'aurelia';
|
|
3
|
+
import { fn, userEvent, within } from 'storybook/test';
|
|
4
|
+
import { WeatherWidget } from '../components/weather-widget';
|
|
5
|
+
import { IWeatherService, WeatherService, WeatherSummary } from '../services/weather-service';
|
|
6
|
+
|
|
7
|
+
type WeatherWidgetArgs = {
|
|
8
|
+
location: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const mockService: WeatherService = {
|
|
12
|
+
async getWeather(location: string): Promise<WeatherSummary> {
|
|
13
|
+
const safeLocation = location ?? '';
|
|
14
|
+
return {
|
|
15
|
+
location: safeLocation,
|
|
16
|
+
condition: safeLocation.includes('Berlin') ? 'Cloudy' : 'Sunny',
|
|
17
|
+
temperature: safeLocation.includes('Berlin') ? 16 : 24,
|
|
18
|
+
high: safeLocation.includes('Berlin') ? 18 : 27,
|
|
19
|
+
low: safeLocation.includes('Berlin') ? 11 : 19,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const meta = {
|
|
25
|
+
title: 'Dashboard/WeatherWidget',
|
|
26
|
+
component: WeatherWidget,
|
|
27
|
+
parameters: {
|
|
28
|
+
layout: 'centered',
|
|
29
|
+
},
|
|
30
|
+
render: (args: WeatherWidgetArgs) =>
|
|
31
|
+
defineAureliaStory({
|
|
32
|
+
template: `<weather-widget location.bind="location"></weather-widget>`,
|
|
33
|
+
props: args,
|
|
34
|
+
components: [WeatherWidget],
|
|
35
|
+
items: [Registration.instance(IWeatherService, mockService)],
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default meta;
|
|
40
|
+
|
|
41
|
+
export const DefaultWeather = {
|
|
42
|
+
args: {
|
|
43
|
+
location: 'Seattle, WA',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const EuropeanCity = {
|
|
48
|
+
args: {
|
|
49
|
+
location: 'Berlin, Germany',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const RefreshInteraction = {
|
|
54
|
+
args: {
|
|
55
|
+
location: 'Lisbon, Portugal',
|
|
56
|
+
},
|
|
57
|
+
play: async ({ canvasElement }) => {
|
|
58
|
+
const canvas = within(canvasElement);
|
|
59
|
+
const refreshButton = await canvas.findByRole('button', { name: /refresh/i });
|
|
60
|
+
await userEvent.click(refreshButton);
|
|
61
|
+
},
|
|
62
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { renderToCanvas } from './preview/render';
|
|
2
|
+
import { defineAureliaStory } from './preview/helpers';
|
|
3
|
+
export { renderToCanvas };
|
|
4
|
+
export declare const render: typeof renderToCanvas;
|
|
5
|
+
export { defineAureliaStory };
|
|
6
|
+
export type { AureliaRenderer, AureliaStoryResult, AureliaArgsStoryFn, AureliaRenderContext, AureliaStoryContext, AureliaParameters, AureliaStoryParameters } from './preview/types';
|
|
7
|
+
export declare const framework: {
|
|
8
|
+
name: string;
|
|
9
|
+
options: {};
|
|
10
|
+
};
|
|
11
|
+
export declare const frameworkOptions: {
|
|
12
|
+
builder: {
|
|
13
|
+
name: string;
|
|
14
|
+
options: {};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare const aureliaFramework: {
|
|
18
|
+
name: string;
|
|
19
|
+
options: {};
|
|
20
|
+
builder: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const externals: {
|
|
23
|
+
react: string;
|
|
24
|
+
'react-dom': string;
|
|
25
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,25 @@ import Aurelia, { CustomElement } from 'aurelia';
|
|
|
2
2
|
|
|
3
3
|
// Track Aurelia apps for cleanup
|
|
4
4
|
const appMap = new Map();
|
|
5
|
+
function mergeStoryProps(parameters, storyArgs, storyProps) {
|
|
6
|
+
return { ...parameters?.args, ...storyArgs, ...storyProps };
|
|
7
|
+
}
|
|
8
|
+
function getAureliaParameters(storyContext) {
|
|
9
|
+
const parameters = storyContext?.parameters?.aurelia;
|
|
10
|
+
if (!parameters || typeof parameters !== 'object') {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return parameters;
|
|
14
|
+
}
|
|
15
|
+
function normalizeRegistrations(parameters) {
|
|
16
|
+
if (!parameters) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const register = Array.isArray(parameters.register) ? parameters.register : [];
|
|
20
|
+
const components = Array.isArray(parameters.components) ? parameters.components : [];
|
|
21
|
+
const items = Array.isArray(parameters.items) ? parameters.items : [];
|
|
22
|
+
return [...register, ...components, ...items].filter(Boolean);
|
|
23
|
+
}
|
|
5
24
|
async function teardown(element) {
|
|
6
25
|
if (appMap.has(element)) {
|
|
7
26
|
const app = appMap.get(element);
|
|
@@ -33,8 +52,6 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
|
|
|
33
52
|
const { parameters, component, args } = storyContext;
|
|
34
53
|
let app = appMap.get(rootElement);
|
|
35
54
|
const story = storyFn();
|
|
36
|
-
// Temporary debug logging
|
|
37
|
-
console.log(`[DEBUG] Story: ${name}, forceRemount: ${forceRemount}, hasExistingApp: ${!!app}, canvasId: ${canvasElement.className}`);
|
|
38
55
|
if (!story) {
|
|
39
56
|
showError({
|
|
40
57
|
title: `Expecting an Aurelia component from the story: "${name}" of "${title}".`,
|
|
@@ -53,15 +70,15 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
|
|
|
53
70
|
}
|
|
54
71
|
// Clear container before mounting new app
|
|
55
72
|
hostElement.innerHTML = '';
|
|
56
|
-
const mergedProps =
|
|
57
|
-
const aureliaApp = appBootstrapFn(story, mergedProps, hostElement, component);
|
|
73
|
+
const mergedProps = mergeStoryProps(parameters, args, story.props);
|
|
74
|
+
const aureliaApp = appBootstrapFn(story, mergedProps, hostElement, component, storyContext);
|
|
58
75
|
await aureliaApp.start();
|
|
59
76
|
appMap.set(rootElement, aureliaApp);
|
|
60
77
|
app = aureliaApp;
|
|
61
78
|
}
|
|
62
79
|
else {
|
|
63
80
|
// update existing app props
|
|
64
|
-
const mergedProps =
|
|
81
|
+
const mergedProps = mergeStoryProps(parameters, args, story.props);
|
|
65
82
|
if (app?.root?.controller?.viewModel) {
|
|
66
83
|
Object.assign(app.root.controller.viewModel, mergedProps);
|
|
67
84
|
}
|
|
@@ -71,18 +88,46 @@ async function renderToCanvas({ storyFn, title, name, showMain, showError, story
|
|
|
71
88
|
await teardown(rootElement);
|
|
72
89
|
};
|
|
73
90
|
}
|
|
74
|
-
function createAureliaApp(story, args, domElement, component) {
|
|
91
|
+
function createAureliaApp(story, args, domElement, component, storyContext) {
|
|
75
92
|
const aurelia = new Aurelia(story.container);
|
|
76
|
-
|
|
77
|
-
|
|
93
|
+
const { container } = aurelia;
|
|
94
|
+
const aureliaParameters = getAureliaParameters(storyContext);
|
|
95
|
+
const registerIfNeeded = (resource) => {
|
|
96
|
+
if (!resource) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (CustomElement.isType(resource)) {
|
|
100
|
+
const definition = CustomElement.getDefinition(resource);
|
|
101
|
+
if (container.has(definition.key, false)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
aurelia.register(resource);
|
|
106
|
+
};
|
|
107
|
+
const registerAll = (resources) => {
|
|
108
|
+
if (!resources?.length) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for (const resource of resources) {
|
|
112
|
+
registerIfNeeded(resource);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
if (aureliaParameters?.configureContainer && storyContext) {
|
|
116
|
+
aureliaParameters.configureContainer(container, storyContext);
|
|
78
117
|
}
|
|
79
|
-
|
|
80
|
-
|
|
118
|
+
registerAll(normalizeRegistrations(aureliaParameters));
|
|
119
|
+
registerAll(story.items);
|
|
120
|
+
const storyComponents = (story.components ?? []).filter(Boolean);
|
|
121
|
+
const dedupedComponents = component
|
|
122
|
+
? storyComponents.filter((entry) => entry !== component)
|
|
123
|
+
: storyComponents;
|
|
124
|
+
for (const entry of dedupedComponents) {
|
|
125
|
+
registerIfNeeded(entry);
|
|
81
126
|
}
|
|
82
127
|
let { template } = story;
|
|
83
128
|
if (component) {
|
|
84
129
|
template = template ?? createComponentTemplate(component, story.innerHtml);
|
|
85
|
-
|
|
130
|
+
registerIfNeeded(component);
|
|
86
131
|
}
|
|
87
132
|
const App = CustomElement.define({
|
|
88
133
|
name: 'sb-app',
|
|
@@ -91,6 +136,9 @@ function createAureliaApp(story, args, domElement, component) {
|
|
|
91
136
|
}, class {
|
|
92
137
|
});
|
|
93
138
|
const app = Object.assign(new App(), args);
|
|
139
|
+
if (aureliaParameters?.configure && storyContext) {
|
|
140
|
+
aureliaParameters.configure(aurelia, storyContext);
|
|
141
|
+
}
|
|
94
142
|
return aurelia.app({
|
|
95
143
|
host: domElement,
|
|
96
144
|
component: app,
|
|
@@ -98,9 +146,15 @@ function createAureliaApp(story, args, domElement, component) {
|
|
|
98
146
|
}
|
|
99
147
|
function createComponentTemplate(component, innerHtml) {
|
|
100
148
|
const def = CustomElement.getDefinition(component);
|
|
101
|
-
|
|
149
|
+
const bindings = Object.values(def.bindables)
|
|
102
150
|
.map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
|
|
103
|
-
.join(' ')
|
|
151
|
+
.join(' ');
|
|
152
|
+
const bindingAttributes = bindings ? ` ${bindings}` : '';
|
|
153
|
+
return `<${def.name}${bindingAttributes}>${innerHtml ?? ''}</${def.name}>`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function defineAureliaStory(story) {
|
|
157
|
+
return story;
|
|
104
158
|
}
|
|
105
159
|
|
|
106
160
|
const render = renderToCanvas;
|
|
@@ -128,5 +182,5 @@ const externals = {
|
|
|
128
182
|
'react-dom': 'ReactDOM'
|
|
129
183
|
};
|
|
130
184
|
|
|
131
|
-
export { aureliaFramework, externals, framework, frameworkOptions, render, renderToCanvas };
|
|
185
|
+
export { aureliaFramework, defineAureliaStory, externals, framework, frameworkOptions, render, renderToCanvas };
|
|
132
186
|
//# 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/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 config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AAC;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;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/preview/render.ts","../src/preview/helpers.ts","../src/index.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","import { renderToCanvas } from './preview/render';\nimport { defineAureliaStory } from './preview/helpers';\n\nexport { renderToCanvas };\nexport const render = renderToCanvas;\nexport { defineAureliaStory };\nexport type {\n AureliaRenderer,\n AureliaStoryResult,\n AureliaArgsStoryFn,\n AureliaRenderContext,\n AureliaStoryContext,\n AureliaParameters,\n AureliaStoryParameters\n} from './preview/types';\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":";;AASA;AACA,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB;AAE1C,SAAS,eAAe,CACtB,UAAsD,EACtD,SAA0C,EAC1C,UAA2C,EAAA;AAE3C,IAAA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AI,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.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optionally adjust the Vite configuration.
|
|
3
|
+
*/
|
|
4
|
+
export declare function viteFinal(config: any): Promise<any>;
|
|
5
|
+
/**
|
|
6
|
+
* Optionally adjust the Rsbuild configuration (Rspack-based).
|
|
7
|
+
*/
|
|
8
|
+
export declare function rsbuildFinal(config: any): Promise<any>;
|
|
9
|
+
/**
|
|
10
|
+
* A function to configure webpack.
|
|
11
|
+
* @param config
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare function webpackFinal(config: any): Promise<any>;
|
|
15
|
+
declare const _default: {
|
|
16
|
+
viteFinal: typeof viteFinal;
|
|
17
|
+
rsbuildFinal: typeof rsbuildFinal;
|
|
18
|
+
webpackFinal: typeof webpackFinal;
|
|
19
|
+
};
|
|
20
|
+
export default _default;
|
|
21
|
+
export declare const previewAnnotations: string[];
|