@storybook/sveltekit 8.0.0 → 8.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 (2) hide show
  1. package/README.md +2 -186
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,190 +1,6 @@
1
- # Storybook for SvelteKit <!-- omit in toc -->
1
+ # Storybook for SvelteKit
2
2
 
3
- Our goal is to help you use the tools you love together with Storybook. That’s why Storybook has zero-config support for SvelteKit with the `@storybook/sveltekit` package.
4
-
5
- Check out our [Frameworks API](https://storybook.js.org/blog/framework-api/) announcement for what this all means for you and our continued efforts to make Storybook a seamless integration for any project.
6
-
7
- ## Table of Contents <!-- omit in toc -->
8
-
9
- - [Supported features](#supported-features)
10
- - [Requirements](#requirements)
11
- - [Getting Started](#getting-started)
12
- - [In a project without Storybook](#in-a-project-without-storybook)
13
- - [In a project with Storybook](#in-a-project-with-storybook)
14
- - [Automatic migration](#automatic-migration)
15
- - [Manual migration](#manual-migration)
16
- - [How to mock](#how-to-mock)
17
- - [Mocking links](#mocking-links)
18
- - [Troubleshooting](#troubleshooting)
19
- - [Error: `ERR! SyntaxError: Identifier '__esbuild_register_import_meta_url__' has already been declared` when starting Storybook](#error-err-syntaxerror-identifier-__esbuild_register_import_meta_url__-has-already-been-declared-when-starting-storybook)
20
- - [Acknowledgements](#acknowledgements)
21
-
22
- ## Supported features
23
-
24
- All Svelte language features are supported out of the box, as Storybook uses the Svelte compiler underneath.
25
- However SvelteKit has some [Kit-specific modules](https://kit.svelte.dev/docs/modules) that currently aren't supported. It's on our roadmap to support most of them soon:
26
-
27
- | **Module** | **Status** | **Note** |
28
- | ---------------------------------------------------------------------------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
29
- | [`$app/environment`](https://kit.svelte.dev/docs/modules#$app-environment) | ✅ Supported | `version` is always empty in Storybook. |
30
- | [`$app/forms`](https://kit.svelte.dev/docs/modules#$app-forms) | ✅ Supported | See [How to mock](#how-to-mock) |
31
- | [`$app/navigation`](https://kit.svelte.dev/docs/modules#$app-navigation) | ✅ Supported | See [How to mock](#how-to-mock) |
32
- | [`$app/paths`](https://kit.svelte.dev/docs/modules#$app-paths) | ✅ Supported | Requires SvelteKit 1.4.0 or newer |
33
- | [`$app/stores`](https://kit.svelte.dev/docs/modules#$app-stores) | ✅ Supported | See [How to mock](#how-to-mock) |
34
- | [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private) | ⛔ Not supported | They are meant to only be available server-side, and Storybook renders all components on the client. |
35
- | [`$env/dynamic/public`](https://kit.svelte.dev/docs/modules#$env-dynamic-public) | 🚧 Partially supported | Only supported in development mode. Storybook is built as a static app with no server-side API so cannot dynamically serve content. |
36
- | [`$env/static/private`](https://kit.svelte.dev/docs/modules#$env-static-private) | ⛔ Not supported | They are meant to only be available server-side, and Storybook renders all components on the client. |
37
- | [`$env/static/public`](https://kit.svelte.dev/docs/modules#$env-static-public) | ✅ Supported | |
38
- | [`$lib`](https://kit.svelte.dev/docs/modules#$lib) | ✅ Supported | |
39
- | [`$service-worker`](https://kit.svelte.dev/docs/modules#$service-worker) | ⛔ Not supported | They are only meant to be used in service workers |
40
- | [`@sveltejs/kit/*`](https://kit.svelte.dev/docs/modules#sveltejs-kit) | ✅ Supported | |
41
-
42
- This is just the beginning. We're close to adding basic support for many of the SvelteKit features. Longer term we're planning on making it an even better experience to [build](https://storybook.js.org/docs/svelte/writing-stories), [test](https://storybook.js.org/docs/svelte/writing-tests) and [document](https://storybook.js.org/docs/svelte/writing-docs) all the SvelteKit goodies like [pages](https://kit.svelte.dev/docs/routing), [forms](https://kit.svelte.dev/docs/form-actions) and [layouts](https://kit.svelte.dev/docs/routing#layout) in Storybook, while still integrating with all the addons and workflows you know and love.
43
-
44
- ## Requirements
45
-
46
- - [SvelteKit](https://kit.svelte.dev/) >= 1.0.0 (not including beta versions)
47
- - [Storybook](https://storybook.js.org/) >= 7.x
48
-
49
- ## Getting Started
50
-
51
- ### In a project without Storybook
52
-
53
- Run the following command in your SvelteKit project's root directory, and follow the prompts:
54
-
55
- ```bash
56
- npx storybook@latest init
57
- ```
58
-
59
- [More on getting started with Storybook](https://storybook.js.org/docs/svelte/get-started/install)
60
-
61
- ### In a project with Storybook
62
-
63
- This framework is designed to work with Storybook 7. If you’re not already using v7, upgrade with this command:
64
-
65
- ```bash
66
- npx storybook@latest upgrade
67
- ```
68
-
69
- #### Automatic migration
70
-
71
- When running the `upgrade` command above you should get a prompt asking you to migrate to `@storybook/sveltekit`, which should handle everything for you. In some cases it can't migrate for you, eg. if your existing Storybook setup is based on Webpack. In such cases, refer to the manual migration below.
72
-
73
- Storybook 7.0 automatically loads your Vite config, and by extension your Svelte config. If you had a `svelteOptions` property in `.storybook/main.js` the automigration will have removed it, as it is no longer supported.
74
-
75
- #### Manual migration
76
-
77
- Install the framework:
78
-
79
- ```bash
80
- yarn add -D @storybook/sveltekit
81
- ```
82
-
83
- Update your `main.js` to change the framework property:
84
-
85
- ```js
86
- // .storybook/main.js
87
- export default {
88
- ...
89
- framework: '@storybook/sveltekit',
90
- };
91
- ```
92
-
93
- Storybook 7.0 automatically loads your Vite config, and by extension your Svelte config. If you have a `svelteOptions` property in `.storybook/main.js` you need to remove that. See [Troubleshooting](#error-about-__esbuild_register_import_meta_url__-when-starting-storybook) below.
94
-
95
- Remove any redundant dependencies, if you have them:
96
-
97
- ```bash
98
- yarn remove @storybook/svelte-vite
99
- yarn remove @storybook/svelte-webpack5
100
- yarn remove storybook-builder-vite
101
- yarn remove @storybook/builder-vite
102
- ```
103
-
104
- ## How to mock
105
-
106
- To mock a SvelteKit import you can set it on `parameters.sveltekit_experimental`:
107
-
108
- ```ts
109
- export const MyStory = {
110
- parameters: {
111
- sveltekit_experimental: {
112
- stores: {
113
- page: {
114
- data: {
115
- test: 'passed',
116
- },
117
- },
118
- navigating: {
119
- route: {
120
- id: '/storybook',
121
- },
122
- },
123
- updated: true,
124
- },
125
- },
126
- },
127
- };
128
- ```
129
-
130
- You can add the name of the module you want to mock to `parameters.sveltekit_experimental` (in the example above we are mocking the `stores` module which correspond to `$app/stores`) and then pass the following kind of objects:
131
-
132
- | Module | Path in parameters | Kind of objects |
133
- | ------------------------------------------------- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
134
- | `import { page } from "$app/stores"` | `parameters.sveltekit_experimental.stores.page` | A Partial of the page store |
135
- | `import { navigating } from "$app/stores"` | `parameters.sveltekit_experimental.stores.navigating` | A Partial of the navigating store |
136
- | `import { updated } from "$app/stores"` | `parameters.sveltekit_experimental.stores.updated` | A boolean representing the value of updated (you can also access `check()` which will be a noop) |
137
- | `import { goto } from "$app/navigation"` | `parameters.sveltekit_experimental.navigation.goto` | A callback that will be called whenever goto is called, in no function is provided an action will be logged to the Actions panel |
138
- | `import { pushState } from "$app/navigation"` | `parameters.sveltekit_experimental.navigation.pushState` | A callback that will be called whenever pushState is called, in no function is provided an action will be logged to the Actions panel |
139
- | `import { replaceState } from "$app/navigation"` | `parameters.sveltekit_experimental.navigation.replaceState` | A callback that will be called whenever replaceState is called, in no function is provided an action will be logged to the Actions panel |
140
- | `import { invalidate } from "$app/navigation"` | `parameters.sveltekit_experimental.navigation.invalidate` | A callback that will be called whenever invalidate is called, in no function is provided an action will be logged to the Actions panel |
141
- | `import { invalidateAll } from "$app/navigation"` | `parameters.sveltekit_experimental.navigation.invalidateAll` | A callback that will be called whenever invalidateAll is called, in no function is provided an action will be logged to the Actions panel |
142
- | `import { afterNavigate } from "$app/navigation"` | `parameters.sveltekit_experimental.navigation.afterNavigate` | An object that will be passed to the afterNavigate function (which will be invoked onMount) called |
143
- | `import { enhance } from "$app/forms"` | `parameters.sveltekit_experimental.forms.enhance` | A callback that will called when a form with `use:enhance` is submitted |
144
-
145
- All the other functions are still exported as `noop` from the mocked modules so that your application will still work.
146
-
147
- ### Mocking links
148
-
149
- The default link-handling behavior (ie. clicking an `<a />` tag with an `href` attribute) is to log an action to the Actions panel.
150
-
151
- You can override this by setting an object on `parameter.sveltekit_experimental.hrefs`, where the keys are strings representing an href and the values are objects typed as `{ callback: (href, event) => void, asRegex?: boolean }`.
152
-
153
- If you have an `<a />` tag inside your code with the `href` attribute that matches one or more of the links defined (treated as regex based on the `asRegex` property) the corresponding `callback` will be called.
154
-
155
- Example:
156
-
157
- ```ts
158
- export const MyStory = {
159
- parameters: {
160
- sveltekit_experimental: {
161
- hrefs: {
162
- '/basic-href': (to, event) => {
163
- console.log(to, event);
164
- },
165
- '/root.*': {
166
- callback: (to, event) => {
167
- console.log(to, event);
168
- },
169
- asRegex: true,
170
- },
171
- },
172
- },
173
- },
174
- };
175
- ```
176
-
177
- ## Troubleshooting
178
-
179
- ### Error: `ERR! SyntaxError: Identifier '__esbuild_register_import_meta_url__' has already been declared` when starting Storybook
180
-
181
- > When starting Storybook after upgrading to v7.0, it breaks with the following error:
182
- >
183
- > ```
184
- > ERR! SyntaxError: Identifier '__esbuild_register_import_meta_url__' has already been declared
185
- > ```
186
-
187
- You'll get this error when manually upgrading from 6.5 to 7.0. You need to remove the `svelteOptions` property in `.storybook/main.js`, as that is not supported by Storybook 7.0 + SvelteKit. The property is also not necessary anymore because the Vite and Svelte configurations are loaded automatically in Storybook 7.0.
3
+ See [documentation](https://storybook.js.org/docs/8.0/get-started/sveltekit?renderer=svelte) for installation instructions, usage examples, APIs, and more.
188
4
 
189
5
  ## Acknowledgements
190
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/sveltekit",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "Storybook for SvelteKit",
5
5
  "keywords": [
6
6
  "storybook",
@@ -53,10 +53,10 @@
53
53
  "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts"
54
54
  },
55
55
  "dependencies": {
56
- "@storybook/addon-actions": "8.0.0",
57
- "@storybook/builder-vite": "8.0.0",
58
- "@storybook/svelte": "8.0.0",
59
- "@storybook/svelte-vite": "8.0.0"
56
+ "@storybook/addon-actions": "8.0.2",
57
+ "@storybook/builder-vite": "8.0.2",
58
+ "@storybook/svelte": "8.0.2",
59
+ "@storybook/svelte-vite": "8.0.2"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/node": "^18.0.0",