@storybook/sveltekit 11.0.0-beta.0 → 11.0.0-beta.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 (41) hide show
  1. package/dist/_browser-chunks/chunk-3HHKZM2E.js +55 -0
  2. package/dist/_browser-chunks/chunk-VAS652SN.js +88 -0
  3. package/dist/_node-chunks/chunk-GPJZQKOH.js +31 -0
  4. package/dist/chunk-56nWP1O9.d.ts +43 -0
  5. package/dist/chunk-B5frDvvZ.d.ts +64 -0
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +2 -1
  8. package/dist/mocks/app/forms.d.ts +32 -0
  9. package/dist/mocks/app/forms.js +74 -14
  10. package/dist/mocks/app/navigation.d.ts +61 -0
  11. package/dist/mocks/app/navigation.js +63 -60
  12. package/dist/mocks/docs-isolation.d.ts +22 -0
  13. package/dist/mocks/docs-isolation.js +62 -0
  14. package/dist/node/index.d.ts +1 -1
  15. package/dist/node/index.js +6 -6
  16. package/dist/preset.js +11 -10
  17. package/dist/preview.js +2 -1
  18. package/dist/vite-plugin.js +7 -7
  19. package/package.json +20 -8
  20. package/static/app-state-mock.svelte.d.ts +39 -0
  21. package/static/app-state-mock.svelte.js +64 -34
  22. package/template/cli/js/Button.stories.svelte +2 -2
  23. package/template/cli/js/Header.stories.svelte +2 -2
  24. package/template/cli/js/Page.stories.svelte +2 -2
  25. package/template/cli/ts/Button.stories.svelte +2 -2
  26. package/template/cli/ts/Header.stories.svelte +2 -2
  27. package/template/cli/ts/Page.stories.svelte +2 -2
  28. package/template/stories_svelte-kit-skeleton-ts/modules/Forms.svelte +18 -3
  29. package/template/stories_svelte-kit-skeleton-ts/modules/Hrefs.svelte +8 -0
  30. package/template/stories_svelte-kit-skeleton-ts/modules/State.svelte +3 -3
  31. package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-isolated-mocks.stories.js +26 -0
  32. package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-shared-mocks.stories.js +28 -0
  33. package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-user.svelte +5 -0
  34. package/template/stories_svelte-kit-skeleton-ts/modules/forms.stories.js +88 -14
  35. package/template/stories_svelte-kit-skeleton-ts/modules/hrefs.stories.js +42 -33
  36. package/template/stories_svelte-kit-skeleton-ts/modules/navigation.stories.js +52 -111
  37. package/template/stories_svelte-kit-skeleton-ts/modules/state.stories.js +45 -63
  38. package/dist/_browser-chunks/chunk-EB5JBDJD.js +0 -34
  39. package/dist/_node-chunks/chunk-XX3F6BW5.js +0 -31
  40. package/dist/chunk-Curl48fh.d.ts +0 -120
  41. package/static/MockProvider.svelte +0 -123
@@ -0,0 +1,22 @@
1
+ import { Mock } from "storybook/test";
2
+
3
+ //#region code/frameworks/sveltekit/.dts-emit/code/frameworks/sveltekit/src/mocks/docs-isolation.d.ts
4
+ /**
5
+ * Called by the framework `beforeEach` of a story on a docs page, before it resets the mocks.
6
+ * Throws when another story on the page already set the mocks. Returns the cleanup.
7
+ *
8
+ * `mocksChanged` tells if the current values differ from the defaults, such as after `page.data.user
9
+ * = user`, which no setter sees. It counts only while a story is set up, because a rendered story
10
+ * can change them, such as in a play function.
11
+ */
12
+ declare function beginDocsStory(storyId: string, canvasElement: Element, mocksChanged: boolean): () => void;
13
+ /** Called when a story on a docs page mounts, which ends its setup. */
14
+ declare function endDocsSetup(canvasElement: Element, mocksChanged: boolean): void;
15
+ /** Called by every write to a SvelteKit mock. Throws when stories on a docs page would share it. */
16
+ declare function noteMockSet(): void;
17
+ /** Runs the framework's own reset of the mocks, which doesn't count as setting them. */
18
+ declare function resetMocks(reset: () => void): void;
19
+ /** Makes configuring a mock function, such as with `mockResolvedValue`, count as setting it. */
20
+ declare function noteConfiguration<T extends Mock<any>>(mock: T): T;
21
+ //#endregion
22
+ export { beginDocsStory, endDocsSetup, noteConfiguration, noteMockSet, resetMocks };
@@ -0,0 +1,62 @@
1
+ import {
2
+ SvelteKitMocksSharedOnDocsPageError
3
+ } from "../_browser-chunks/chunk-3HHKZM2E.js";
4
+ import "../_browser-chunks/chunk-4BE7D4DS.js";
5
+
6
+ // src/mocks/docs-isolation.ts
7
+ import { STORY_RENDER_PHASE_CHANGED } from "storybook/internal/core-events";
8
+ import { addons } from "storybook/preview-api";
9
+ var renders = /* @__PURE__ */ new Map(), mocksSetOnPage = !1, resetting = !1, forgetRemovedRenders = () => {
10
+ for (let canvasElement of renders.keys())
11
+ canvasElement.isConnected || renders.delete(canvasElement);
12
+ renders.size === 0 && (mocksSetOnPage = !1);
13
+ }, hasOtherStory = (storyId) => [...renders.values()].some((render) => render.storyId !== storyId), isSettingUp = () => [...renders.values()].some((render) => render.settingUp), sharedError = () => new SvelteKitMocksSharedOnDocsPageError(), listening = !1, listenForFailures = () => {
14
+ listening || (listening = !0, addons.getChannel().on(
15
+ STORY_RENDER_PHASE_CHANGED,
16
+ ({ newPhase, storyId }) => {
17
+ if (newPhase === "errored")
18
+ for (let render of renders.values())
19
+ render.storyId === storyId && (render.settingUp = !1);
20
+ }
21
+ ));
22
+ };
23
+ function beginDocsStory(storyId, canvasElement, mocksChanged) {
24
+ if (listenForFailures(), forgetRemovedRenders(), (mocksSetOnPage || mocksChanged && isSettingUp()) && hasOtherStory(storyId))
25
+ throw sharedError();
26
+ return renders.set(canvasElement, { storyId, settingUp: !0 }), () => {
27
+ renders.delete(canvasElement), renders.size === 0 && (mocksSetOnPage = !1);
28
+ };
29
+ }
30
+ function endDocsSetup(canvasElement, mocksChanged) {
31
+ let render = renders.get(canvasElement);
32
+ render?.settingUp && (mocksChanged && noteMockSet(), render.settingUp = !1);
33
+ }
34
+ function noteMockSet() {
35
+ if (forgetRemovedRenders(), !(resetting || !isSettingUp())) {
36
+ if (new Set([...renders.values()].map((render) => render.storyId)).size >= 2)
37
+ throw sharedError();
38
+ mocksSetOnPage = !0;
39
+ }
40
+ }
41
+ function resetMocks(reset) {
42
+ resetting = !0;
43
+ try {
44
+ reset();
45
+ } finally {
46
+ resetting = !1;
47
+ }
48
+ }
49
+ function noteConfiguration(mock) {
50
+ for (let method of ["mockImplementation", "mockImplementationOnce", "withImplementation"]) {
51
+ let original = mock[method];
52
+ mock[method] = (...args) => (noteMockSet(), original(...args));
53
+ }
54
+ return mock;
55
+ }
56
+ export {
57
+ beginDocsStory,
58
+ endDocsSetup,
59
+ noteConfiguration,
60
+ noteMockSet,
61
+ resetMocks
62
+ };
@@ -1,4 +1,4 @@
1
- import { i as StorybookConfig } from "../chunk-Curl48fh.js";
1
+ import { n as StorybookConfig } from "../chunk-56nWP1O9.js";
2
2
 
3
3
  //#region code/frameworks/sveltekit/.dts-emit/code/frameworks/sveltekit/src/node/index.d.ts
4
4
  declare function defineMain(config: StorybookConfig): StorybookConfig;
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_ah69lhomlk from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ah69lhomlk from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ah69lhomlk from "node:module";
1
+ import CJS_COMPAT_NODE_URL_e4wxeb3w5nh from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_e4wxeb3w5nh from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_e4wxeb3w5nh from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_ah69lhomlk.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ah69lhomlk.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ah69lhomlk.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_e4wxeb3w5nh.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_e4wxeb3w5nh.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_e4wxeb3w5nh.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/dist/preset.js CHANGED
@@ -1,17 +1,17 @@
1
- import CJS_COMPAT_NODE_URL_ah69lhomlk from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ah69lhomlk from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ah69lhomlk from "node:module";
1
+ import CJS_COMPAT_NODE_URL_e4wxeb3w5nh from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_e4wxeb3w5nh from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_e4wxeb3w5nh from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_ah69lhomlk.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ah69lhomlk.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ah69lhomlk.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_e4wxeb3w5nh.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_e4wxeb3w5nh.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_e4wxeb3w5nh.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
12
  import {
13
13
  mockSveltekitModules
14
- } from "./_node-chunks/chunk-XX3F6BW5.js";
14
+ } from "./_node-chunks/chunk-GPJZQKOH.js";
15
15
 
16
16
  // src/preset.ts
17
17
  import { existsSync } from "node:fs";
@@ -131,9 +131,10 @@ var core = {
131
131
  ]
132
132
  };
133
133
  }, optimizeViteDeps = [
134
- "@storybook/sveltekit/internal/mocks/app/forms",
135
- "@storybook/sveltekit/internal/mocks/app/navigation",
136
- "@storybook/sveltekit/internal/mocks/app/state.svelte.js"
134
+ "@storybook/sveltekit/forms.mock",
135
+ "@storybook/sveltekit/internal/mocks/app/state.svelte.js",
136
+ "@storybook/sveltekit/internal/mocks/docs-isolation",
137
+ "@storybook/sveltekit/navigation.mock"
137
138
  ];
138
139
  export {
139
140
  core,
package/dist/preview.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  beforeEach,
3
3
  decorators
4
- } from "./_browser-chunks/chunk-EB5JBDJD.js";
4
+ } from "./_browser-chunks/chunk-VAS652SN.js";
5
+ import "./_browser-chunks/chunk-3HHKZM2E.js";
5
6
  import "./_browser-chunks/chunk-4BE7D4DS.js";
6
7
  export {
7
8
  beforeEach,
@@ -1,17 +1,17 @@
1
- import CJS_COMPAT_NODE_URL_ah69lhomlk from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ah69lhomlk from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ah69lhomlk from "node:module";
1
+ import CJS_COMPAT_NODE_URL_e4wxeb3w5nh from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_e4wxeb3w5nh from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_e4wxeb3w5nh from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_ah69lhomlk.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ah69lhomlk.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ah69lhomlk.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_e4wxeb3w5nh.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_e4wxeb3w5nh.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_e4wxeb3w5nh.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
12
  import {
13
13
  mockSveltekitModules
14
- } from "./_node-chunks/chunk-XX3F6BW5.js";
14
+ } from "./_node-chunks/chunk-GPJZQKOH.js";
15
15
 
16
16
  // src/vite-plugin.ts
17
17
  var storybookSveltekitPlugin = () => [mockSveltekitModules()];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/sveltekit",
3
- "version": "11.0.0-beta.0",
3
+ "version": "11.0.0-beta.2",
4
4
  "description": "Storybook for SvelteKit: Develop, document, and test UI components in isolation",
5
5
  "keywords": [
6
6
  "storybook",
@@ -33,10 +33,22 @@
33
33
  "code": "./src/index.ts",
34
34
  "default": "./dist/index.js"
35
35
  },
36
- "./internal/MockProvider.svelte": "./static/MockProvider.svelte",
37
- "./internal/mocks/app/forms": "./dist/mocks/app/forms.js",
38
- "./internal/mocks/app/navigation": "./dist/mocks/app/navigation.js",
36
+ "./forms.mock": {
37
+ "types": "./dist/mocks/app/forms.d.ts",
38
+ "code": "./src/mocks/app/forms.ts",
39
+ "default": "./dist/mocks/app/forms.js"
40
+ },
39
41
  "./internal/mocks/app/state.svelte.js": "./static/app-state-mock.svelte.js",
42
+ "./internal/mocks/docs-isolation": {
43
+ "types": "./dist/mocks/docs-isolation.d.ts",
44
+ "code": "./src/mocks/docs-isolation.ts",
45
+ "default": "./dist/mocks/docs-isolation.js"
46
+ },
47
+ "./navigation.mock": {
48
+ "types": "./dist/mocks/app/navigation.d.ts",
49
+ "code": "./src/mocks/app/navigation.ts",
50
+ "default": "./dist/mocks/app/navigation.js"
51
+ },
40
52
  "./node": {
41
53
  "types": "./dist/node/index.d.ts",
42
54
  "code": "./src/node/index.ts",
@@ -56,9 +68,9 @@
56
68
  "*.d.ts"
57
69
  ],
58
70
  "dependencies": {
59
- "@storybook/builder-vite": "11.0.0-beta.0",
60
- "@storybook/svelte": "11.0.0-beta.0",
61
- "@storybook/svelte-vite": "11.0.0-beta.0"
71
+ "@storybook/builder-vite": "11.0.0-beta.2",
72
+ "@storybook/svelte": "11.0.0-beta.2",
73
+ "@storybook/svelte-vite": "11.0.0-beta.2"
62
74
  },
63
75
  "devDependencies": {
64
76
  "@types/node": "^22.19.1",
@@ -68,7 +80,7 @@
68
80
  },
69
81
  "peerDependencies": {
70
82
  "@sveltejs/kit": "^3.0.0",
71
- "storybook": "^11.0.0-beta.0",
83
+ "storybook": "^11.0.0-beta.2",
72
84
  "svelte": "^5.0.0",
73
85
  "typescript": "^5.9.0 || ^6.0.0 || ^7.0.0",
74
86
  "vite": "^8.0.0"
@@ -0,0 +1,39 @@
1
+ // Types of `app-state-mock.svelte.js`, which ships as JavaScript because Svelte compiles its runes
2
+ // in the user's project
3
+ import type { Mock } from 'storybook/test';
4
+
5
+ interface NavigationTarget {
6
+ params: Record<string, string> | null;
7
+ route: { id: string | null };
8
+ url: URL;
9
+ }
10
+
11
+ export interface Page {
12
+ url: URL;
13
+ params: Record<string, string>;
14
+ route: { id: string | null };
15
+ status: number;
16
+ error: { message: string } | null;
17
+ data: Record<string, any>;
18
+ state: Record<string, any>;
19
+ form: any;
20
+ }
21
+
22
+ export interface Navigating {
23
+ from: NavigationTarget | null;
24
+ to: NavigationTarget | null;
25
+ type: 'form' | 'leave' | 'link' | 'goto' | 'popstate' | null;
26
+ willUnload: boolean | null;
27
+ delta: number | null;
28
+ complete: Promise<void> | null;
29
+ }
30
+
31
+ export declare let page: Page;
32
+ export declare let navigating: Navigating;
33
+ export declare let updated: { current: boolean; check: Mock<() => Promise<boolean>> };
34
+
35
+ /** Resets `page`, `navigating` and `updated` to their defaults. The framework calls it before every story. */
36
+ export declare function resetAppState(): void;
37
+
38
+ /** Tells if a write went into a default value of `page`, which its setters don't see. */
39
+ export declare function pageDefaultsChanged(): boolean;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Inspired by the the code:
2
+ * Inspired by the code:
3
3
  * {@link https://github.com/sveltejs/kit/blob/main/packages/kit/src/runtime/client/state.svelte.js}
4
4
  *
5
5
  * The differences:
@@ -10,6 +10,7 @@
10
10
  * @module
11
11
  */
12
12
 
13
+ import { noteConfiguration, noteMockSet } from '@storybook/sveltekit/internal/mocks/docs-isolation';
13
14
  import { fn } from 'storybook/test';
14
15
 
15
16
  /**
@@ -35,7 +36,9 @@ import { fn } from 'storybook/test';
35
36
  * @property {any} form
36
37
  */
37
38
 
38
- const defaultStatePageValues = {
39
+ // A function, so a story that mutates `page.data` doesn't change the defaults of the next story
40
+ /** @type {() => Page} */
41
+ const defaultStatePageValues = () => ({
39
42
  data: {},
40
43
  form: null,
41
44
  error: null,
@@ -44,24 +47,26 @@ const defaultStatePageValues = {
44
47
  state: {},
45
48
  status: -1,
46
49
  url: new URL(location.origin),
47
- };
50
+ });
51
+
52
+ const initialPage = defaultStatePageValues();
48
53
 
49
54
  /** @type {Page['data']} */
50
- let pageData = $state.raw(defaultStatePageValues.data);
55
+ let pageData = $state.raw(initialPage.data);
51
56
  /** @type {Page['form']} */
52
- let pageForm = $state.raw(defaultStatePageValues.form);
57
+ let pageForm = $state.raw(initialPage.form);
53
58
  /** @type {Page['error']} */
54
- let pageError = $state.raw(defaultStatePageValues.error);
59
+ let pageError = $state.raw(initialPage.error);
55
60
  /** @type {Page['params']} */
56
- let pageParams = $state.raw(defaultStatePageValues.params);
61
+ let pageParams = $state.raw(initialPage.params);
57
62
  /** @type {Page['route']} */
58
- let pageRoute = $state.raw(defaultStatePageValues.route);
63
+ let pageRoute = $state.raw(initialPage.route);
59
64
  /** @type {Page['state']} */
60
- let pageState = $state.raw(defaultStatePageValues.state);
65
+ let pageState = $state.raw(initialPage.state);
61
66
  /** @type {Page['status']} */
62
- let pageStatus = $state.raw(defaultStatePageValues.status);
67
+ let pageStatus = $state.raw(initialPage.status);
63
68
  /** @type {Page['url']} */
64
- let pageUrl = $state.raw(defaultStatePageValues.url);
69
+ let pageUrl = $state.raw(initialPage.url);
65
70
 
66
71
  /** @type {Page} */
67
72
  // oxlint-disable-next-line prefer-const -- mirrors upstream SvelteKit state.svelte.js, where this is a mutable `let` binding
@@ -70,63 +75,60 @@ export let page = {
70
75
  return pageData;
71
76
  },
72
77
  set data(newPageData) {
78
+ noteMockSet();
73
79
  pageData = newPageData;
74
80
  },
75
81
  get form() {
76
82
  return pageForm;
77
83
  },
78
84
  set form(newPageForm) {
85
+ noteMockSet();
79
86
  pageForm = newPageForm;
80
87
  },
81
88
  get error() {
82
89
  return pageError;
83
90
  },
84
91
  set error(newPageError) {
92
+ noteMockSet();
85
93
  pageError = newPageError;
86
94
  },
87
95
  get params() {
88
96
  return pageParams;
89
97
  },
90
98
  set params(newPageParams) {
99
+ noteMockSet();
91
100
  pageParams = newPageParams;
92
101
  },
93
102
  get route() {
94
103
  return pageRoute;
95
104
  },
96
105
  set route(newPageRoute) {
106
+ noteMockSet();
97
107
  pageRoute = newPageRoute;
98
108
  },
99
109
  get state() {
100
110
  return pageState;
101
111
  },
102
112
  set state(newPageState) {
113
+ noteMockSet();
103
114
  pageState = newPageState;
104
115
  },
105
116
  get status() {
106
117
  return pageStatus;
107
118
  },
108
119
  set status(newPageStatus) {
120
+ noteMockSet();
109
121
  pageStatus = newPageStatus;
110
122
  },
111
123
  get url() {
112
124
  return pageUrl;
113
125
  },
114
126
  set url(newPageUrl) {
127
+ noteMockSet();
115
128
  pageUrl = newPageUrl;
116
129
  },
117
130
  };
118
131
 
119
- export function setAppStatePage(params = {}) {
120
- page.data = params.data ?? defaultStatePageValues.data;
121
- page.form = params.form ?? defaultStatePageValues.form;
122
- page.error = params.error ?? defaultStatePageValues.error;
123
- page.params = params.params ?? defaultStatePageValues.params;
124
- page.route = params.route ?? defaultStatePageValues.route;
125
- page.state = params.state ?? defaultStatePageValues.state;
126
- page.status = params.status ?? defaultStatePageValues.status;
127
- page.url = params.url ?? defaultStatePageValues.url;
128
- }
129
-
130
132
  /**
131
133
  * @typedef {Object} NavigationTarget
132
134
  * @property {Record<string, string> | null} params
@@ -176,49 +178,46 @@ export let navigating = {
176
178
  return navigatingFrom;
177
179
  },
178
180
  set from(newNavigatingFrom) {
181
+ noteMockSet();
179
182
  navigatingFrom = newNavigatingFrom;
180
183
  },
181
184
  get to() {
182
185
  return navigatingTo;
183
186
  },
184
187
  set to(newNavigatingTo) {
188
+ noteMockSet();
185
189
  navigatingTo = newNavigatingTo;
186
190
  },
187
191
  get type() {
188
192
  return navigatingType;
189
193
  },
190
194
  set type(newNavigatingType) {
195
+ noteMockSet();
191
196
  navigatingType = newNavigatingType;
192
197
  },
193
198
  get willUnload() {
194
199
  return navigatingWillUnload;
195
200
  },
196
201
  set willUnload(newNavigatingWillUnload) {
202
+ noteMockSet();
197
203
  navigatingWillUnload = newNavigatingWillUnload;
198
204
  },
199
205
  get delta() {
200
206
  return navigatingDelta;
201
207
  },
202
208
  set delta(newNavigatingDelta) {
209
+ noteMockSet();
203
210
  navigatingDelta = newNavigatingDelta;
204
211
  },
205
212
  get complete() {
206
213
  return navigatingComplete;
207
214
  },
208
215
  set complete(newNavigatingComplete) {
216
+ noteMockSet();
209
217
  navigatingComplete = newNavigatingComplete;
210
218
  },
211
219
  };
212
220
 
213
- export function setAppStateNavigating(params = {}) {
214
- navigating.from = params.from ?? defaultStateNavigatingValues.from;
215
- navigating.to = params.to ?? defaultStateNavigatingValues.to;
216
- navigating.type = params.type ?? defaultStateNavigatingValues.type;
217
- navigating.willUnload = params.willUnload ?? defaultStateNavigatingValues.willUnload;
218
- navigating.delta = params.delta ?? defaultStateNavigatingValues.delta;
219
- navigating.complete = params.complete ?? defaultStateNavigatingValues.complete;
220
- }
221
-
222
221
  /** @type {boolean} */
223
222
  let updatedCurrent = $state.raw(false);
224
223
 
@@ -228,11 +227,42 @@ export let updated = {
228
227
  return updatedCurrent;
229
228
  },
230
229
  set current(newCurrent) {
230
+ noteMockSet();
231
231
  updatedCurrent = newCurrent;
232
232
  },
233
- check: fn(() => Promise.resolve(updatedCurrent)),
233
+ check: noteConfiguration(fn(() => Promise.resolve(updatedCurrent))),
234
234
  };
235
235
 
236
- export function setAppStateUpdated(params = {}) {
237
- updated.current = params.current ?? false;
236
+ /** Resets `page`, `navigating` and `updated` to their defaults. The framework calls it before every story. */
237
+ // The page values of the last reset, to find writes into them, such as `page.data.user = user`
238
+ let pageDefaults = initialPage;
239
+
240
+ export function resetAppState() {
241
+ pageDefaults = defaultStatePageValues();
242
+ Object.assign(page, pageDefaults);
243
+ Object.assign(navigating, defaultStateNavigatingValues);
244
+ updated.current = false;
245
+ }
246
+
247
+ /**
248
+ * Tells if a write went into a default value of `page`, which its setters don't see. The defaults
249
+ * are flat, so a shallow comparison finds every write.
250
+ *
251
+ * @returns {boolean}
252
+ */
253
+ export function pageDefaultsChanged() {
254
+ const fresh = defaultStatePageValues();
255
+ return Object.entries(pageDefaults).some(([key, value]) => {
256
+ if (page[key] !== value || value === null || typeof value !== 'object') {
257
+ return false;
258
+ }
259
+ if (value instanceof URL) {
260
+ return value.href !== fresh[key].href;
261
+ }
262
+ const expected = fresh[key];
263
+ return (
264
+ Object.keys(value).length !== Object.keys(expected).length ||
265
+ Object.entries(expected).some(([field, fieldValue]) => value[field] !== fieldValue)
266
+ );
267
+ });
238
268
  }
@@ -1,10 +1,10 @@
1
1
  <script module>
2
- import { defineMeta } from '@storybook/sveltekit';
2
+ import preview from '../../.storybook/preview';
3
3
  import Button from './Button.svelte';
4
4
  import { fn } from 'storybook/test';
5
5
 
6
6
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
7
- const { Story } = defineMeta({
7
+ const { Story } = preview.meta({
8
8
  title: 'Example/Button',
9
9
  component: Button,
10
10
  tags: ['autodocs'],
@@ -1,10 +1,10 @@
1
1
  <script module>
2
- import { defineMeta } from '@storybook/sveltekit';
2
+ import preview from '../../.storybook/preview';
3
3
  import Header from './Header.svelte';
4
4
  import { fn } from 'storybook/test';
5
5
 
6
6
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
7
- const { Story } = defineMeta({
7
+ const { Story } = preview.meta({
8
8
  title: 'Example/Header',
9
9
  component: Header,
10
10
  // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
@@ -1,11 +1,11 @@
1
1
  <script module>
2
- import { defineMeta } from '@storybook/sveltekit';
2
+ import preview from '../../.storybook/preview';
3
3
  import { expect, userEvent, waitFor, within } from 'storybook/test';
4
4
  import Page from './Page.svelte';
5
5
  import { fn } from 'storybook/test';
6
6
 
7
7
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
8
- const { Story } = defineMeta({
8
+ const { Story } = preview.meta({
9
9
  title: 'Example/Page',
10
10
  component: Page,
11
11
  parameters: {
@@ -1,10 +1,10 @@
1
1
  <script module>
2
- import { defineMeta } from '@storybook/sveltekit';
2
+ import preview from '../../.storybook/preview';
3
3
  import Button from './Button.svelte';
4
4
  import { fn } from 'storybook/test';
5
5
 
6
6
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
7
- const { Story } = defineMeta({
7
+ const { Story } = preview.meta({
8
8
  title: 'Example/Button',
9
9
  component: Button,
10
10
  tags: ['autodocs'],
@@ -1,10 +1,10 @@
1
1
  <script module>
2
- import { defineMeta } from '@storybook/sveltekit';
2
+ import preview from '../../.storybook/preview';
3
3
  import Header from './Header.svelte';
4
4
  import { fn } from 'storybook/test';
5
5
 
6
6
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
7
- const { Story } = defineMeta({
7
+ const { Story } = preview.meta({
8
8
  title: 'Example/Header',
9
9
  component: Header,
10
10
  // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
@@ -1,11 +1,11 @@
1
1
  <script module>
2
- import { defineMeta } from '@storybook/sveltekit';
2
+ import preview from '../../.storybook/preview';
3
3
  import { expect, userEvent, waitFor, within } from 'storybook/test';
4
4
  import Page from './Page.svelte';
5
5
  import { fn } from 'storybook/test';
6
6
 
7
7
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
8
- const { Story } = defineMeta({
8
+ const { Story } = preview.meta({
9
9
  title: 'Example/Page',
10
10
  component: Page,
11
11
  parameters: {
@@ -1,7 +1,22 @@
1
1
  <script>
2
2
  import { enhance } from '$app/forms';
3
+ import { page } from '$app/state';
4
+
5
+ const { submit } = $props();
3
6
  </script>
4
7
 
5
- <form use:enhance method="post">
6
- <button>enhance</button>
7
- </form>
8
+ <form method="post" action="?/subscribe" use:enhance={submit}>
9
+ <label>Email <input name="email" /></label>
10
+ <button>Subscribe</button>
11
+ </form>
12
+
13
+ {#if page.form?.error}
14
+ <p role="alert">{page.form.error}</p>
15
+ {/if}
16
+ {#if page.form?.email}
17
+ <p>Subscribed {page.form.email}</p>
18
+ {/if}
19
+ {#if page.error}
20
+ <p role="alert">Error: {page.error.message}</p>
21
+ {/if}
22
+ <p>Status: <span data-testid="status">{page.status}</span></p>
@@ -1,3 +1,7 @@
1
+ <script>
2
+ import { page } from '$app/state';
3
+ </script>
4
+
1
5
  <ul>
2
6
  <li><a href="/basic-href">Link to <code>/basic-href</code></a></li>
3
7
  <li>
@@ -5,4 +9,8 @@
5
9
  >Link to <code>/deep/nested/link?with=true&multiple-params=200#and-an-id</code></a
6
10
  >
7
11
  </li>
12
+ <li><a href="https://svelte.dev">Link to <code>https://svelte.dev</code></a></li>
13
+ <li><a href="/new-window" target="_blank">Opens in a new window</a></li>
8
14
  </ul>
15
+
16
+ <p>Current URL: <span data-testid="current-url">{page.url.href}</span></p>
@@ -7,10 +7,10 @@
7
7
  <h1>$app/state</h1>
8
8
 
9
9
  <h2>page</h2>
10
- <pre>{JSON.stringify(page, null, 2)}</pre>
10
+ <pre data-testid="page">{JSON.stringify(page, null, 2)}</pre>
11
11
 
12
12
  <h2>navigating</h2>
13
- <pre>{JSON.stringify(navigating, null, 2)}</pre>
13
+ <pre data-testid="navigating">{JSON.stringify(navigating, null, 2)}</pre>
14
14
 
15
15
  <h2>updated</h2>
16
- <pre>{JSON.stringify(updated, null, 2)}</pre>
16
+ <pre data-testid="updated">{JSON.stringify(updated, null, 2)}</pre>