@storybook/sveltekit 10.0.0-beta.5 → 10.0.0-beta.7

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.
@@ -0,0 +1,39 @@
1
+ import {
2
+ __export,
3
+ __name
4
+ } from "./chunk-JFJ5UJ7Q.js";
5
+
6
+ // src/preview.ts
7
+ var preview_exports = {};
8
+ __export(preview_exports, {
9
+ beforeEach: () => beforeEach,
10
+ decorators: () => decorators
11
+ });
12
+ import MockProvider from "@storybook/sveltekit/internal/MockProvider.svelte";
13
+ import {
14
+ setAppStateNavigating,
15
+ setAppStatePage,
16
+ setAppStateUpdated
17
+ } from "@storybook/sveltekit/internal/mocks/app/state.svelte.js";
18
+ var svelteKitMocksDecorator = /* @__PURE__ */ __name((Story, ctx) => {
19
+ const svelteKitParameters = ctx.parameters?.sveltekit_experimental ?? {};
20
+ return {
21
+ Component: MockProvider,
22
+ props: {
23
+ svelteKitParameters
24
+ }
25
+ };
26
+ }, "svelteKitMocksDecorator");
27
+ var decorators = [svelteKitMocksDecorator];
28
+ var beforeEach = /* @__PURE__ */ __name(async (ctx) => {
29
+ const svelteKitParameters = ctx.parameters?.sveltekit_experimental ?? {};
30
+ setAppStatePage(svelteKitParameters?.state?.page);
31
+ setAppStateNavigating(svelteKitParameters?.state?.navigating);
32
+ setAppStateUpdated(svelteKitParameters?.state?.updated);
33
+ }, "beforeEach");
34
+
35
+ export {
36
+ decorators,
37
+ beforeEach,
38
+ preview_exports
39
+ };
@@ -1,17 +1,17 @@
1
- import CJS_COMPAT_NODE_URL_lr745q6e35 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_lr745q6e35 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_lr745q6e35 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_f9wtsfi1ckc from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f9wtsfi1ckc from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_lr745q6e35.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_lr745q6e35.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_lr745q6e35.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_f9wtsfi1ckc.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f9wtsfi1ckc.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc.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
  __name
14
- } from "./chunk-74JCJPKD.js";
14
+ } from "./chunk-MU6AXIPM.js";
15
15
 
16
16
  // src/plugins/mock-sveltekit-stores.ts
17
17
  function mockSveltekitStores() {
@@ -22,6 +22,7 @@ function mockSveltekitStores() {
22
22
  alias: {
23
23
  "$app/forms": "@storybook/sveltekit/internal/mocks/app/forms",
24
24
  "$app/navigation": "@storybook/sveltekit/internal/mocks/app/navigation",
25
+ "$app/state": "@storybook/sveltekit/internal/mocks/app/state.svelte.js",
25
26
  "$app/stores": "@storybook/sveltekit/internal/mocks/app/stores"
26
27
  }
27
28
  }
@@ -0,0 +1,17 @@
1
+ import CJS_COMPAT_NODE_URL_f9wtsfi1ckc from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f9wtsfi1ckc from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_f9wtsfi1ckc.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f9wtsfi1ckc.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ var __defProp = Object.defineProperty;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+
15
+ export {
16
+ __name
17
+ };
package/dist/index.d.ts CHANGED
@@ -42,8 +42,63 @@ type NormalizedHrefConfig = {
42
42
  asRegex?: boolean;
43
43
  };
44
44
  type HrefConfig = NormalizedHrefConfig | NormalizedHrefConfig['callback'];
45
+ /**
46
+ * Copied from:
47
+ * {@link https://github.com/sveltejs/kit/blob/7bb41aa4263b057a8912f4cdd35db03755d37342/packages/kit/types/index.d.ts#L1102-L1143}
48
+ */
49
+ interface Page<Params extends Record<string, string> = Record<string, string>, RouteId extends string | null = string | null> {
50
+ url: URL;
51
+ params: Params;
52
+ route: {
53
+ id: RouteId;
54
+ };
55
+ status: number;
56
+ error: Error | null;
57
+ data: Record<string, any>;
58
+ state: Record<string, any>;
59
+ form: any;
60
+ }
61
+ /**
62
+ * Copied from:
63
+ * {@link https://github.com/sveltejs/kit/blob/7bb41aa4263b057a8912f4cdd35db03755d37342/packages/kit/types/index.d.ts#L988}
64
+ */
65
+ interface NavigationTarget {
66
+ params: Record<string, string> | null;
67
+ route: {
68
+ id: string | null;
69
+ };
70
+ url: URL;
71
+ }
72
+ /**
73
+ * Copied from:
74
+ * {@link https://github.com/sveltejs/kit/blob/7bb41aa4263b057a8912f4cdd35db03755d37342/packages/kit/types/index.d.ts#L1017C9-L1017C89}
75
+ */
76
+ type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
77
+ /**
78
+ * Copied from:
79
+ * {@link https://github.com/sveltejs/kit/blob/7bb41aa4263b057a8912f4cdd35db03755d37342/packages/kit/types/index.d.ts#L1017C9-L1017C89}
80
+ */
81
+ interface Navigation {
82
+ from: NavigationTarget | null;
83
+ to: NavigationTarget | null;
84
+ type: Exclude<NavigationType, 'enter'>;
85
+ willUnload: boolean;
86
+ delta?: number;
87
+ complete: Promise<void>;
88
+ }
45
89
  type SvelteKitParameters = Partial<{
46
90
  hrefs: Record<string, HrefConfig>;
91
+ state: {
92
+ page: Partial<Page>;
93
+ navigating: Partial<Navigation>;
94
+ updated: {
95
+ current: boolean;
96
+ };
97
+ };
98
+ /**
99
+ * @deprecated
100
+ * @see {@link https://svelte.dev/docs/kit/$app-stores}
101
+ */
47
102
  stores: {
48
103
  page: Record<string, any>;
49
104
  navigating: Record<string, any>;
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import {
2
2
  preview_exports
3
- } from "./_browser-chunks/chunk-Y4OPRTUT.js";
4
- import "./_browser-chunks/chunk-T276X65R.js";
5
- import "./_browser-chunks/chunk-MNND3IGN.js";
3
+ } from "./_browser-chunks/chunk-Q3EHWMWT.js";
6
4
  import {
7
5
  __name
8
6
  } from "./_browser-chunks/chunk-JFJ5UJ7Q.js";
@@ -1,18 +1,70 @@
1
1
  import {
2
- afterNavigate,
3
- beforeNavigate,
4
- disableScrollHandling,
5
- goto,
6
- invalidate,
7
- invalidateAll,
8
- onNavigate,
9
- preloadCode,
10
- preloadData,
11
- pushState,
12
- replaceState,
13
- setAfterNavigateArgument
14
- } from "../../_browser-chunks/chunk-T276X65R.js";
15
- import "../../_browser-chunks/chunk-JFJ5UJ7Q.js";
2
+ __name
3
+ } from "../../_browser-chunks/chunk-JFJ5UJ7Q.js";
4
+
5
+ // src/mocks/app/navigation.ts
6
+ import { getContext, onMount, setContext } from "svelte";
7
+ async function goto(...args) {
8
+ const event = new CustomEvent("storybook:goto", {
9
+ detail: args
10
+ });
11
+ window.dispatchEvent(event);
12
+ }
13
+ __name(goto, "goto");
14
+ function setAfterNavigateArgument(afterNavigateArgs) {
15
+ setContext("after-navigate-args", afterNavigateArgs);
16
+ }
17
+ __name(setAfterNavigateArgument, "setAfterNavigateArgument");
18
+ function afterNavigate(cb) {
19
+ const argument = getContext("after-navigate-args");
20
+ onMount(() => {
21
+ if (cb && cb instanceof Function) {
22
+ cb(argument);
23
+ }
24
+ });
25
+ }
26
+ __name(afterNavigate, "afterNavigate");
27
+ function onNavigate() {
28
+ }
29
+ __name(onNavigate, "onNavigate");
30
+ function beforeNavigate() {
31
+ }
32
+ __name(beforeNavigate, "beforeNavigate");
33
+ function disableScrollHandling() {
34
+ }
35
+ __name(disableScrollHandling, "disableScrollHandling");
36
+ async function invalidate(...args) {
37
+ const event = new CustomEvent("storybook:invalidate", {
38
+ detail: args
39
+ });
40
+ window.dispatchEvent(event);
41
+ }
42
+ __name(invalidate, "invalidate");
43
+ async function invalidateAll() {
44
+ const event = new CustomEvent("storybook:invalidateAll");
45
+ window.dispatchEvent(event);
46
+ }
47
+ __name(invalidateAll, "invalidateAll");
48
+ function preloadCode() {
49
+ }
50
+ __name(preloadCode, "preloadCode");
51
+ function preloadData() {
52
+ }
53
+ __name(preloadData, "preloadData");
54
+ async function pushState(...args) {
55
+ const event = new CustomEvent("storybook:pushState", {
56
+ detail: args
57
+ });
58
+ window.dispatchEvent(event);
59
+ }
60
+ __name(pushState, "pushState");
61
+ async function replaceState(...args) {
62
+ const event = new CustomEvent("storybook:replaceState", {
63
+ detail: args
64
+ });
65
+ window.dispatchEvent(event);
66
+ }
67
+ __name(replaceState, "replaceState");
16
68
  export {
17
69
  afterNavigate,
18
70
  beforeNavigate,
@@ -1,19 +1,44 @@
1
1
  import {
2
- getStores,
3
- navigating,
4
- page,
5
- setNavigating,
6
- setPage,
7
- setUpdated,
8
- updated
9
- } from "../../_browser-chunks/chunk-MNND3IGN.js";
10
- import "../../_browser-chunks/chunk-JFJ5UJ7Q.js";
2
+ __name
3
+ } from "../../_browser-chunks/chunk-JFJ5UJ7Q.js";
4
+
5
+ // src/mocks/app/stores.ts
6
+ import { getContext, setContext } from "svelte";
7
+ function createMockedStore(contextName) {
8
+ return [
9
+ {
10
+ subscribe(runner) {
11
+ const page2 = getContext(contextName);
12
+ runner(page2);
13
+ return () => {
14
+ };
15
+ }
16
+ },
17
+ (value) => {
18
+ setContext(contextName, value);
19
+ }
20
+ ];
21
+ }
22
+ __name(createMockedStore, "createMockedStore");
23
+ var [page, setAppStoresPage] = createMockedStore("page-ctx");
24
+ var [navigating, setAppStoresNavigating] = createMockedStore("navigating-ctx");
25
+ var [updated, setAppStoresUpdated] = createMockedStore("updated-ctx");
26
+ updated.check = () => {
27
+ };
28
+ function getStores() {
29
+ return {
30
+ page,
31
+ navigating,
32
+ updated
33
+ };
34
+ }
35
+ __name(getStores, "getStores");
11
36
  export {
12
37
  getStores,
13
38
  navigating,
14
39
  page,
15
- setNavigating,
16
- setPage,
17
- setUpdated,
40
+ setAppStoresNavigating,
41
+ setAppStoresPage,
42
+ setAppStoresUpdated,
18
43
  updated
19
44
  };
@@ -1,17 +1,17 @@
1
- import CJS_COMPAT_NODE_URL_lr745q6e35 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_lr745q6e35 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_lr745q6e35 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_f9wtsfi1ckc from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f9wtsfi1ckc from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_lr745q6e35.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_lr745q6e35.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_lr745q6e35.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_f9wtsfi1ckc.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f9wtsfi1ckc.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc.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
  __name
14
- } from "../_node-chunks/chunk-74JCJPKD.js";
14
+ } from "../_node-chunks/chunk-MU6AXIPM.js";
15
15
 
16
16
  // src/node/index.ts
17
17
  function defineMain(config) {
package/dist/preset.js CHANGED
@@ -1,20 +1,20 @@
1
- import CJS_COMPAT_NODE_URL_lr745q6e35 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_lr745q6e35 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_lr745q6e35 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_f9wtsfi1ckc from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f9wtsfi1ckc from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_lr745q6e35.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_lr745q6e35.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_lr745q6e35.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_f9wtsfi1ckc.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f9wtsfi1ckc.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc.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
  mockSveltekitStores
14
- } from "./_node-chunks/chunk-G4KKPBLJ.js";
14
+ } from "./_node-chunks/chunk-3WVLFY2S.js";
15
15
  import {
16
16
  __name
17
- } from "./_node-chunks/chunk-74JCJPKD.js";
17
+ } from "./_node-chunks/chunk-MU6AXIPM.js";
18
18
 
19
19
  // src/preset.ts
20
20
  import { fileURLToPath } from "node:url";
@@ -61,7 +61,8 @@ var viteFinal = /* @__PURE__ */ __name(async (config, options) => {
61
61
  var optimizeViteDeps = [
62
62
  "@storybook/sveltekit/internal/mocks/app/forms",
63
63
  "@storybook/sveltekit/internal/mocks/app/navigation",
64
- "@storybook/sveltekit/internal/mocks/app/stores"
64
+ "@storybook/sveltekit/internal/mocks/app/stores",
65
+ "@storybook/sveltekit/internal/mocks/app/state.svelte.js"
65
66
  ];
66
67
  export {
67
68
  core,
package/dist/preview.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
+ beforeEach,
2
3
  decorators
3
- } from "./_browser-chunks/chunk-Y4OPRTUT.js";
4
- import "./_browser-chunks/chunk-T276X65R.js";
5
- import "./_browser-chunks/chunk-MNND3IGN.js";
4
+ } from "./_browser-chunks/chunk-Q3EHWMWT.js";
6
5
  import "./_browser-chunks/chunk-JFJ5UJ7Q.js";
7
6
  export {
7
+ beforeEach,
8
8
  decorators
9
9
  };
@@ -1,20 +1,20 @@
1
- import CJS_COMPAT_NODE_URL_lr745q6e35 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_lr745q6e35 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_lr745q6e35 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_f9wtsfi1ckc from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f9wtsfi1ckc from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_lr745q6e35.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_lr745q6e35.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_lr745q6e35.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_f9wtsfi1ckc.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f9wtsfi1ckc.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f9wtsfi1ckc.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
  mockSveltekitStores
14
- } from "./_node-chunks/chunk-G4KKPBLJ.js";
14
+ } from "./_node-chunks/chunk-3WVLFY2S.js";
15
15
  import {
16
16
  __name
17
- } from "./_node-chunks/chunk-74JCJPKD.js";
17
+ } from "./_node-chunks/chunk-MU6AXIPM.js";
18
18
 
19
19
  // src/vite-plugin.ts
20
20
  var storybookSveltekitPlugin = /* @__PURE__ */ __name(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/sveltekit",
3
- "version": "10.0.0-beta.5",
3
+ "version": "10.0.0-beta.7",
4
4
  "description": "Storybook for SvelteKit: Develop, document, and test UI components in isolation",
5
5
  "keywords": [
6
6
  "storybook",
@@ -32,8 +32,10 @@
32
32
  "types": "./dist/index.d.ts",
33
33
  "default": "./dist/index.js"
34
34
  },
35
+ "./internal/MockProvider.svelte": "./static/MockProvider.svelte",
35
36
  "./internal/mocks/app/forms": "./dist/mocks/app/forms.js",
36
37
  "./internal/mocks/app/navigation": "./dist/mocks/app/navigation.js",
38
+ "./internal/mocks/app/state.svelte.js": "./static/app-state-mock.svelte.js",
37
39
  "./internal/mocks/app/stores": "./dist/mocks/app/stores.js",
38
40
  "./node": {
39
41
  "types": "./dist/node/index.d.ts",
@@ -46,20 +48,20 @@
46
48
  },
47
49
  "files": [
48
50
  "dist/**/*",
51
+ "static/**/*",
49
52
  "template/**/*",
50
53
  "README.md",
51
54
  "*.js",
52
- "*.d.ts",
53
- "src/mocks/**/*"
55
+ "*.d.ts"
54
56
  ],
55
57
  "scripts": {
56
58
  "check": "jiti ../../../scripts/check/check-package.ts",
57
59
  "prep": "jiti ../../../scripts/build/build-package.ts"
58
60
  },
59
61
  "dependencies": {
60
- "@storybook/builder-vite": "10.0.0-beta.5",
61
- "@storybook/svelte": "10.0.0-beta.5",
62
- "@storybook/svelte-vite": "10.0.0-beta.5"
62
+ "@storybook/builder-vite": "10.0.0-beta.7",
63
+ "@storybook/svelte": "10.0.0-beta.7",
64
+ "@storybook/svelte-vite": "10.0.0-beta.7"
63
65
  },
64
66
  "devDependencies": {
65
67
  "@types/node": "^22.0.0",
@@ -67,7 +69,7 @@
67
69
  "vite": "^7.0.4"
68
70
  },
69
71
  "peerDependencies": {
70
- "storybook": "^10.0.0-beta.5",
72
+ "storybook": "^10.0.0-beta.7",
71
73
  "svelte": "^5.0.0",
72
74
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
73
75
  },
@@ -0,0 +1,127 @@
1
+ <script>
2
+ import { onMount } from 'svelte';
3
+ import { action } from 'storybook/actions';
4
+
5
+ import { setAfterNavigateArgument } from '@storybook/sveltekit/internal/mocks/app/navigation';
6
+ import { setAppStoresNavigating, setAppStoresPage, setAppStoresUpdated } from '@storybook/sveltekit/internal/mocks/app/stores';
7
+
8
+ const { svelteKitParameters = {}, children } = $props();
9
+
10
+ // Set context during component initialization - this happens before any child components
11
+ setAppStoresPage(svelteKitParameters?.stores?.page);
12
+ setAppStoresNavigating(svelteKitParameters?.stores?.navigating);
13
+ setAppStoresUpdated(svelteKitParameters?.stores?.updated);
14
+ setAfterNavigateArgument(svelteKitParameters?.navigation?.afterNavigate);
15
+
16
+ const normalizeHrefConfig = (hrefConfig) => {
17
+ if (typeof hrefConfig === 'function') {
18
+ return { callback: hrefConfig, asRegex: false };
19
+ }
20
+ return hrefConfig;
21
+ };
22
+
23
+ onMount(() => {
24
+ const globalClickListener = (e) => {
25
+ // we add a global click event listener and we check if there's a link in the composedPath
26
+ const path = e.composedPath();
27
+ const element = path.findLast((el) => el instanceof HTMLElement && el.tagName === 'A');
28
+ if (element && element instanceof HTMLAnchorElement) {
29
+ // if the element is an a-tag we get the href of the element
30
+ // and compare it to the hrefs-parameter set by the user
31
+ const to = element.getAttribute('href');
32
+ if (!to) {
33
+ return;
34
+ }
35
+ e.preventDefault();
36
+ const defaultActionCallback = () => action('navigate')(to, e);
37
+ if (!svelteKitParameters.hrefs) {
38
+ defaultActionCallback();
39
+ return;
40
+ }
41
+
42
+ let callDefaultCallback = true;
43
+ // we loop over every href set by the user and check if the href matches
44
+ // if it does we call the callback provided by the user and disable the default callback
45
+ Object.entries(svelteKitParameters.hrefs).forEach(([href, hrefConfig]) => {
46
+ const { callback, asRegex } = normalizeHrefConfig(hrefConfig);
47
+ const isMatch = asRegex ? new RegExp(href).test(to) : to === href;
48
+ if (isMatch) {
49
+ callDefaultCallback = false;
50
+ callback?.(to, e);
51
+ }
52
+ });
53
+ if (callDefaultCallback) {
54
+ defaultActionCallback();
55
+ }
56
+ }
57
+ };
58
+
59
+ /**
60
+ * Function that create and add listeners for the event that are emitted by the mocked
61
+ * functions. The event name is based on the function name
62
+ *
63
+ * Eg. storybook:goto, storybook:invalidateAll
64
+ *
65
+ * @param baseModule The base module where the function lives (navigation|forms)
66
+ * @param functions The list of functions in that module that emit events
67
+ * @param {boolean} [defaultToAction] The list of functions in that module that emit events
68
+ * @returns A function to remove all the listener added
69
+ */
70
+ function createListeners(baseModule, functions, defaultToAction) {
71
+ // the array of every added listener, we can use this in the return function
72
+ // to clean them
73
+ const toRemove = [];
74
+ functions.forEach((func) => {
75
+ // we loop over every function and check if the user actually passed
76
+ // a function in sveltekit_experimental[baseModule][func] eg. sveltekit_experimental.navigation.goto
77
+ const hasFunction =
78
+ svelteKitParameters[baseModule]?.[func] &&
79
+ svelteKitParameters[baseModule][func] instanceof Function;
80
+ // if we default to an action we still add the listener (this will be the case for goto, invalidate, invalidateAll)
81
+ if (hasFunction || defaultToAction) {
82
+ // we create the listener that will just get the detail array from the custom element
83
+ // and call the user provided function spreading this args in...this will basically call
84
+ // the function that the user provide with the same arguments the function is invoked to
85
+
86
+ // eg. if it calls goto("/my-route") inside the component the function sveltekit_experimental.navigation.goto
87
+ // it provided to storybook will be called with "/my-route"
88
+ const listener = ({ detail = [] }) => {
89
+ const args = Array.isArray(detail) ? detail : [];
90
+ // if it has a function in the parameters we call that function
91
+ // otherwise we invoke the action
92
+ const fnToCall = hasFunction
93
+ ? svelteKitParameters[baseModule][func]
94
+ : action(func);
95
+ fnToCall(...args);
96
+ };
97
+ const eventType = `storybook:${func}`;
98
+ toRemove.push({ eventType, listener });
99
+ // add the listener to window
100
+ window.addEventListener(eventType, listener);
101
+ }
102
+ });
103
+ return () => {
104
+ // loop over every listener added and remove them
105
+ toRemove.forEach(({ eventType, listener }) => {
106
+ window.removeEventListener(eventType, listener);
107
+ });
108
+ };
109
+ }
110
+
111
+ const removeNavigationListeners = createListeners(
112
+ 'navigation',
113
+ ['goto', 'invalidate', 'invalidateAll', 'pushState', 'replaceState'],
114
+ true
115
+ );
116
+ const removeFormsListeners = createListeners('forms', ['enhance']);
117
+ window.addEventListener('click', globalClickListener);
118
+
119
+ return () => {
120
+ window.removeEventListener('click', globalClickListener);
121
+ removeNavigationListeners();
122
+ removeFormsListeners();
123
+ };
124
+ });
125
+ </script>
126
+
127
+ {@render children()}
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Inspired by the the code:
3
+ * {@link https://github.com/sveltejs/kit/blob/main/packages/kit/src/runtime/client/state.svelte.js}
4
+ *
5
+ * The differences:
6
+ *
7
+ * - Legacy Svelte support is not included
8
+ * - Not using classes (internal coding style preference)
9
+ *
10
+ * @module
11
+ */
12
+ import { fn } from 'storybook/test';
13
+
14
+ /**
15
+ * @typedef {Object} App
16
+ * @property {Object} Error
17
+ * @property {string} Error.message
18
+ * @property {Object} Locals
19
+ * @property {Object} PageData
20
+ * @property {Object} PageState
21
+ * @property {Object} Platform
22
+ */
23
+
24
+ /**
25
+ * @typedef {Object} Page
26
+ * @property {URL} url
27
+ * @property {Record<string, string>} params
28
+ * @property {Object} route
29
+ * @property {string | null} route.id
30
+ * @property {number} status
31
+ * @property {App.Error | null} error
32
+ * @property {App.PageData & Record<string, any>} data
33
+ * @property {App.PageState} state
34
+ * @property {any} form
35
+ */
36
+
37
+ const defaultStatePageValues = {
38
+ data: {},
39
+ form: null,
40
+ error: null,
41
+ params: {},
42
+ route: { id: null },
43
+ state: {},
44
+ status: -1,
45
+ url: new URL(location.origin),
46
+ };
47
+
48
+ /** @type {Page['data']} */
49
+ let pageData = $state.raw(defaultStatePageValues.data);
50
+ /** @type {Page['form']} */
51
+ let pageForm = $state.raw(defaultStatePageValues.form);
52
+ /** @type {Page['error']} */
53
+ let pageError = $state.raw(defaultStatePageValues.error);
54
+ /** @type {Page['params']} */
55
+ let pageParams = $state.raw(defaultStatePageValues.params);
56
+ /** @type {Page['route']} */
57
+ let pageRoute = $state.raw(defaultStatePageValues.route);
58
+ /** @type {Page['state']} */
59
+ let pageState = $state.raw(defaultStatePageValues.state);
60
+ /** @type {Page['status']} */
61
+ let pageStatus = $state.raw(defaultStatePageValues.status);
62
+ /** @type {Page['url']} */
63
+ let pageUrl = $state.raw(defaultStatePageValues.url);
64
+
65
+ /** @type {Page} */
66
+ export let page = {
67
+ get data() {
68
+ return pageData;
69
+ },
70
+ set data(newPageData) {
71
+ pageData = newPageData;
72
+ },
73
+ get form() {
74
+ return pageForm;
75
+ },
76
+ set form(newPageForm) {
77
+ pageForm = newPageForm;
78
+ },
79
+ get error() {
80
+ return pageError;
81
+ },
82
+ set error(newPageError) {
83
+ pageError = newPageError;
84
+ },
85
+ get params() {
86
+ return pageParams;
87
+ },
88
+ set params(newPageParams) {
89
+ pageParams = newPageParams;
90
+ },
91
+ get route() {
92
+ return pageRoute;
93
+ },
94
+ set route(newPageRoute) {
95
+ pageRoute = newPageRoute;
96
+ },
97
+ get state() {
98
+ return pageState;
99
+ },
100
+ set state(newPageState) {
101
+ pageState = newPageState;
102
+ },
103
+ get status() {
104
+ return pageStatus;
105
+ },
106
+ set status(newPageStatus) {
107
+ pageStatus = newPageStatus;
108
+ },
109
+ get url() {
110
+ return pageUrl;
111
+ },
112
+ set url(newPageUrl) {
113
+ pageUrl = newPageUrl;
114
+ },
115
+ };
116
+
117
+ export function setAppStatePage(params = {}) {
118
+ page.data = params.data ?? defaultStatePageValues.data;
119
+ page.form = params.form ?? defaultStatePageValues.form;
120
+ page.error = params.error ?? defaultStatePageValues.error;
121
+ page.params = params.params ?? defaultStatePageValues.params;
122
+ page.route = params.route ?? defaultStatePageValues.route;
123
+ page.state = params.state ?? defaultStatePageValues.state;
124
+ page.status = params.status ?? defaultStatePageValues.status;
125
+ page.url = params.url ?? defaultStatePageValues.url;
126
+ }
127
+
128
+ /**
129
+ * @typedef {Object} NavigationTarget
130
+ * @property {Record<string, string> | null} params
131
+ * @property {Object} route
132
+ * @property {string | null} route.id
133
+ * @property {URL} url
134
+ */
135
+
136
+ /** @typedef {'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate'} NavigationType */
137
+
138
+ /**
139
+ * @typedef {Object} Navigation
140
+ * @property {NavigationTarget | null} from
141
+ * @property {NavigationTarget | null} to
142
+ * @property {Exclude<NavigationType, 'enter'>} type
143
+ * @property {boolean} willUnload
144
+ * @property {number} [delta]
145
+ * @property {Promise<void>} complete
146
+ */
147
+
148
+ const defaultStateNavigatingValues = {
149
+ from: null,
150
+ to: null,
151
+ type: null,
152
+ willUnload: null,
153
+ delta: null,
154
+ complete: null,
155
+ };
156
+
157
+ /** @type {Navigation['from'] | null} */
158
+ let navigatingFrom = $state.raw(defaultStateNavigatingValues.from);
159
+ /** @type {Navigation['to'] | null} */
160
+ let navigatingTo = $state.raw(defaultStateNavigatingValues.to);
161
+ /** @type {Navigation['type'] | null} */
162
+ let navigatingType = $state.raw(defaultStateNavigatingValues.type);
163
+ /** @type {Navigation['willUnload'] | null} */
164
+ let navigatingWillUnload = $state.raw(defaultStateNavigatingValues.willUnload);
165
+ /** @type {Navigation['delta'] | null} */
166
+ let navigatingDelta = $state.raw(defaultStateNavigatingValues.delta);
167
+ /** @type {Navigation['complete'] | null} */
168
+ let navigatingComplete = $state.raw(defaultStateNavigatingValues.complete);
169
+
170
+ /** @type {Navigation} */
171
+ export let navigating = {
172
+ get from() {
173
+ return navigatingFrom;
174
+ },
175
+ set from(newNavigatingFrom) {
176
+ navigatingFrom = newNavigatingFrom;
177
+ },
178
+ get to() {
179
+ return navigatingTo;
180
+ },
181
+ set to(newNavigatingTo) {
182
+ navigatingTo = newNavigatingTo;
183
+ },
184
+ get type() {
185
+ return navigatingType;
186
+ },
187
+ set type(newNavigatingType) {
188
+ navigatingType = newNavigatingType;
189
+ },
190
+ get willUnload() {
191
+ return navigatingWillUnload;
192
+ },
193
+ set willUnload(newNavigatingWillUnload) {
194
+ navigatingWillUnload = newNavigatingWillUnload;
195
+ },
196
+ get delta() {
197
+ return navigatingDelta;
198
+ },
199
+ set delta(newNavigatingDelta) {
200
+ navigatingDelta = newNavigatingDelta;
201
+ },
202
+ get complete() {
203
+ return navigatingComplete;
204
+ },
205
+ set complete(newNavigatingComplete) {
206
+ navigatingComplete = newNavigatingComplete;
207
+ },
208
+ };
209
+
210
+ export function setAppStateNavigating(params = {}) {
211
+ navigating.from = params.from ?? defaultStateNavigatingValues.from;
212
+ navigating.to = params.to ?? defaultStateNavigatingValues.to;
213
+ navigating.type = params.type ?? defaultStateNavigatingValues.type;
214
+ navigating.willUnload = params.willUnload ?? defaultStateNavigatingValues.willUnload;
215
+ navigating.delta = params.delta ?? defaultStateNavigatingValues.delta;
216
+ navigating.complete = params.complete ?? defaultStateNavigatingValues.complete;
217
+ }
218
+
219
+ /** @type {boolean} */
220
+ let updatedCurrent = $state.raw(false);
221
+
222
+ export let updated = {
223
+ get current() {
224
+ return updatedCurrent;
225
+ },
226
+ set current(newCurrent) {
227
+ updatedCurrent = newCurrent;
228
+ },
229
+ check: fn(() => Promise.resolve(updatedCurrent)),
230
+ };
231
+
232
+ export function setAppStateUpdated(params = {}) {
233
+ updated.current = params.current ?? false;
234
+ }
@@ -0,0 +1,16 @@
1
+ <script>
2
+ import { page, navigating, updated } from '$app/state';
3
+
4
+ updated.check();
5
+ </script>
6
+
7
+ <h1>$app/state</h1>
8
+
9
+ <h2>page</h2>
10
+ <pre>{JSON.stringify(page, null, 2)}</pre>
11
+
12
+ <h2>navigating</h2>
13
+ <pre>{JSON.stringify(navigating, null, 2)}</pre>
14
+
15
+ <h2>updated</h2>
16
+ <pre>{JSON.stringify(updated, null, 2)}</pre>
@@ -0,0 +1,84 @@
1
+ import State from './State.svelte';
2
+
3
+ export default {
4
+ title: 'stories/frameworks/sveltekit/modules/state',
5
+ component: State,
6
+ parameters: {
7
+ sveltekit_experimental: {
8
+ state: {
9
+ page: {
10
+ url: new URL('https://storybook.js.org'), // necessary to make the rendered output deterministic in CH snapshots
11
+ },
12
+ },
13
+ },
14
+ },
15
+ };
16
+
17
+ export const Default = {};
18
+
19
+ export const Page = {
20
+ parameters: {
21
+ sveltekit_experimental: {
22
+ state: {
23
+ page: {
24
+ data: {
25
+ test: 'passed',
26
+ },
27
+ form: {
28
+ framework: 'SvelteKit',
29
+ rating: 5,
30
+ },
31
+ params: {
32
+ referrer: 'storybook',
33
+ },
34
+ route: {
35
+ id: '/framework/sveltekit',
36
+ },
37
+ status: 200,
38
+ url: new URL('https://svelte.dev/docs/kit/'),
39
+ },
40
+ },
41
+ },
42
+ },
43
+ };
44
+
45
+ export const Navigating = {
46
+ parameters: {
47
+ sveltekit_experimental: {
48
+ state: {
49
+ navigating: {
50
+ from: {
51
+ params: {
52
+ framework: 'SvelteKit',
53
+ },
54
+ route: {
55
+ id: '/framework/sveltekit',
56
+ },
57
+ url: new URL('https://svelte.dev'),
58
+ },
59
+ to: {
60
+ route: { id: '/storybook' },
61
+ params: {},
62
+ url: new URL('https://storybook.js.org'),
63
+ },
64
+ type: 'link',
65
+ willUnload: true,
66
+ delta: 3,
67
+ complete: Promise.resolve(),
68
+ },
69
+ },
70
+ },
71
+ },
72
+ };
73
+
74
+ export const Updated = {
75
+ parameters: {
76
+ sveltekit_experimental: {
77
+ state: {
78
+ updated: {
79
+ current: true,
80
+ },
81
+ },
82
+ },
83
+ },
84
+ };
@@ -1,45 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-JFJ5UJ7Q.js";
4
-
5
- // src/mocks/app/stores.ts
6
- import { getContext, setContext } from "svelte";
7
- function createMockedStore(contextName) {
8
- return [
9
- {
10
- subscribe(runner) {
11
- const page2 = getContext(contextName);
12
- runner(page2);
13
- return () => {
14
- };
15
- }
16
- },
17
- (value) => {
18
- setContext(contextName, value);
19
- }
20
- ];
21
- }
22
- __name(createMockedStore, "createMockedStore");
23
- var [page, setPage] = createMockedStore("page-ctx");
24
- var [navigating, setNavigating] = createMockedStore("navigating-ctx");
25
- var [updated, setUpdated] = createMockedStore("updated-ctx");
26
- updated.check = () => {
27
- };
28
- function getStores() {
29
- return {
30
- page,
31
- navigating,
32
- updated
33
- };
34
- }
35
- __name(getStores, "getStores");
36
-
37
- export {
38
- page,
39
- setPage,
40
- navigating,
41
- setNavigating,
42
- updated,
43
- setUpdated,
44
- getStores
45
- };
@@ -1,82 +0,0 @@
1
- import {
2
- __name
3
- } from "./chunk-JFJ5UJ7Q.js";
4
-
5
- // src/mocks/app/navigation.ts
6
- import { getContext, onMount, setContext } from "svelte";
7
- async function goto(...args) {
8
- const event = new CustomEvent("storybook:goto", {
9
- detail: args
10
- });
11
- window.dispatchEvent(event);
12
- }
13
- __name(goto, "goto");
14
- function setAfterNavigateArgument(afterNavigateArgs) {
15
- setContext("after-navigate-args", afterNavigateArgs);
16
- }
17
- __name(setAfterNavigateArgument, "setAfterNavigateArgument");
18
- function afterNavigate(cb) {
19
- const argument = getContext("after-navigate-args");
20
- onMount(() => {
21
- if (cb && cb instanceof Function) {
22
- cb(argument);
23
- }
24
- });
25
- }
26
- __name(afterNavigate, "afterNavigate");
27
- function onNavigate() {
28
- }
29
- __name(onNavigate, "onNavigate");
30
- function beforeNavigate() {
31
- }
32
- __name(beforeNavigate, "beforeNavigate");
33
- function disableScrollHandling() {
34
- }
35
- __name(disableScrollHandling, "disableScrollHandling");
36
- async function invalidate(...args) {
37
- const event = new CustomEvent("storybook:invalidate", {
38
- detail: args
39
- });
40
- window.dispatchEvent(event);
41
- }
42
- __name(invalidate, "invalidate");
43
- async function invalidateAll() {
44
- const event = new CustomEvent("storybook:invalidateAll");
45
- window.dispatchEvent(event);
46
- }
47
- __name(invalidateAll, "invalidateAll");
48
- function preloadCode() {
49
- }
50
- __name(preloadCode, "preloadCode");
51
- function preloadData() {
52
- }
53
- __name(preloadData, "preloadData");
54
- async function pushState(...args) {
55
- const event = new CustomEvent("storybook:pushState", {
56
- detail: args
57
- });
58
- window.dispatchEvent(event);
59
- }
60
- __name(pushState, "pushState");
61
- async function replaceState(...args) {
62
- const event = new CustomEvent("storybook:replaceState", {
63
- detail: args
64
- });
65
- window.dispatchEvent(event);
66
- }
67
- __name(replaceState, "replaceState");
68
-
69
- export {
70
- goto,
71
- setAfterNavigateArgument,
72
- afterNavigate,
73
- onNavigate,
74
- beforeNavigate,
75
- disableScrollHandling,
76
- invalidate,
77
- invalidateAll,
78
- preloadCode,
79
- preloadData,
80
- pushState,
81
- replaceState
82
- };
@@ -1,104 +0,0 @@
1
- import {
2
- setAfterNavigateArgument
3
- } from "./chunk-T276X65R.js";
4
- import {
5
- setNavigating,
6
- setPage,
7
- setUpdated
8
- } from "./chunk-MNND3IGN.js";
9
- import {
10
- __export,
11
- __name
12
- } from "./chunk-JFJ5UJ7Q.js";
13
-
14
- // src/preview.ts
15
- var preview_exports = {};
16
- __export(preview_exports, {
17
- decorators: () => decorators
18
- });
19
- import { action } from "storybook/actions";
20
- import { onMount } from "svelte";
21
- var normalizeHrefConfig = /* @__PURE__ */ __name((hrefConfig) => {
22
- if (typeof hrefConfig === "function") {
23
- return { callback: hrefConfig, asRegex: false };
24
- }
25
- return hrefConfig;
26
- }, "normalizeHrefConfig");
27
- var svelteKitMocksDecorator = /* @__PURE__ */ __name((Story, ctx) => {
28
- const svelteKitParameters = ctx.parameters?.sveltekit_experimental ?? {};
29
- setPage(svelteKitParameters?.stores?.page);
30
- setNavigating(svelteKitParameters?.stores?.navigating);
31
- setUpdated(svelteKitParameters?.stores?.updated);
32
- setAfterNavigateArgument(svelteKitParameters?.navigation?.afterNavigate);
33
- onMount(() => {
34
- const globalClickListener = /* @__PURE__ */ __name((e) => {
35
- const path = e.composedPath();
36
- const element = path.findLast((el) => el instanceof HTMLElement && el.tagName === "A");
37
- if (element && element instanceof HTMLAnchorElement) {
38
- const to = element.getAttribute("href");
39
- if (!to) {
40
- return;
41
- }
42
- e.preventDefault();
43
- const defaultActionCallback = /* @__PURE__ */ __name(() => action("navigate")(to, e), "defaultActionCallback");
44
- if (!svelteKitParameters.hrefs) {
45
- defaultActionCallback();
46
- return;
47
- }
48
- let callDefaultCallback = true;
49
- Object.entries(svelteKitParameters.hrefs).forEach(([href, hrefConfig]) => {
50
- const { callback, asRegex } = normalizeHrefConfig(hrefConfig);
51
- const isMatch = asRegex ? new RegExp(href).test(to) : to === href;
52
- if (isMatch) {
53
- callDefaultCallback = false;
54
- callback?.(to, e);
55
- }
56
- });
57
- if (callDefaultCallback) {
58
- defaultActionCallback();
59
- }
60
- }
61
- }, "globalClickListener");
62
- function createListeners(baseModule, functions, defaultToAction) {
63
- const toRemove = [];
64
- functions.forEach((func) => {
65
- const hasFunction = svelteKitParameters[baseModule]?.[func] && svelteKitParameters[baseModule][func] instanceof Function;
66
- if (hasFunction || defaultToAction) {
67
- const listener = /* @__PURE__ */ __name(({ detail = [] }) => {
68
- const args = Array.isArray(detail) ? detail : [];
69
- const fnToCall = hasFunction ? svelteKitParameters[baseModule][func] : action(func);
70
- fnToCall(...args);
71
- }, "listener");
72
- const eventType = `storybook:${func}`;
73
- toRemove.push({ eventType, listener });
74
- window.addEventListener(eventType, listener);
75
- }
76
- });
77
- return () => {
78
- toRemove.forEach(({ eventType, listener }) => {
79
- window.removeEventListener(eventType, listener);
80
- });
81
- };
82
- }
83
- __name(createListeners, "createListeners");
84
- const removeNavigationListeners = createListeners(
85
- "navigation",
86
- ["goto", "invalidate", "invalidateAll", "pushState", "replaceState"],
87
- true
88
- );
89
- const removeFormsListeners = createListeners("forms", ["enhance"]);
90
- window.addEventListener("click", globalClickListener);
91
- return () => {
92
- window.removeEventListener("click", globalClickListener);
93
- removeNavigationListeners();
94
- removeFormsListeners();
95
- };
96
- });
97
- return Story();
98
- }, "svelteKitMocksDecorator");
99
- var decorators = [svelteKitMocksDecorator];
100
-
101
- export {
102
- decorators,
103
- preview_exports
104
- };
@@ -1,17 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_lr745q6e35 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_lr745q6e35 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_lr745q6e35 from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_lr745q6e35.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_lr745q6e35.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_lr745q6e35.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
- var __defProp = Object.defineProperty;
13
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
-
15
- export {
16
- __name
17
- };
@@ -1,20 +0,0 @@
1
- export function enhance(form: HTMLFormElement) {
2
- const listener = (...args: any[]) => {
3
- const e = args[0];
4
- e.preventDefault();
5
- const event = new CustomEvent('storybook:enhance', {
6
- detail: args,
7
- });
8
- window.dispatchEvent(event);
9
- };
10
- form.addEventListener('submit', listener);
11
- return {
12
- destroy() {
13
- form.removeEventListener('submit', listener);
14
- },
15
- };
16
- }
17
-
18
- export function applyAction() {}
19
-
20
- export function deserialize() {}
@@ -1,57 +0,0 @@
1
- import { getContext, onMount, setContext } from 'svelte';
2
-
3
- export async function goto(...args: any[]) {
4
- const event = new CustomEvent('storybook:goto', {
5
- detail: args,
6
- });
7
- window.dispatchEvent(event);
8
- }
9
-
10
- export function setAfterNavigateArgument(afterNavigateArgs: any) {
11
- setContext('after-navigate-args', afterNavigateArgs);
12
- }
13
-
14
- export function afterNavigate(cb: any) {
15
- const argument = getContext('after-navigate-args');
16
- onMount(() => {
17
- if (cb && cb instanceof Function) {
18
- cb(argument);
19
- }
20
- });
21
- }
22
-
23
- export function onNavigate() {}
24
-
25
- export function beforeNavigate() {}
26
-
27
- export function disableScrollHandling() {}
28
-
29
- export async function invalidate(...args: any[]) {
30
- const event = new CustomEvent('storybook:invalidate', {
31
- detail: args,
32
- });
33
- window.dispatchEvent(event);
34
- }
35
-
36
- export async function invalidateAll() {
37
- const event = new CustomEvent('storybook:invalidateAll');
38
- window.dispatchEvent(event);
39
- }
40
-
41
- export function preloadCode() {}
42
-
43
- export function preloadData() {}
44
-
45
- export async function pushState(...args: any[]) {
46
- const event = new CustomEvent('storybook:pushState', {
47
- detail: args,
48
- });
49
- window.dispatchEvent(event);
50
- }
51
-
52
- export async function replaceState(...args: any[]) {
53
- const event = new CustomEvent('storybook:replaceState', {
54
- detail: args,
55
- });
56
- window.dispatchEvent(event);
57
- }
@@ -1,32 +0,0 @@
1
- import { getContext, setContext } from 'svelte';
2
-
3
- function createMockedStore(contextName: string) {
4
- return [
5
- {
6
- subscribe(runner: any) {
7
- const page = getContext(contextName);
8
- runner(page);
9
- return () => {};
10
- },
11
- },
12
- (value: unknown) => {
13
- setContext(contextName, value);
14
- },
15
- ] as const;
16
- }
17
-
18
- export const [page, setPage] = createMockedStore('page-ctx');
19
- export const [navigating, setNavigating] = createMockedStore('navigating-ctx');
20
- const [updated, setUpdated] = createMockedStore('updated-ctx');
21
-
22
- (updated as any).check = () => {};
23
-
24
- export { updated, setUpdated };
25
-
26
- export function getStores() {
27
- return {
28
- page,
29
- navigating,
30
- updated,
31
- };
32
- }