@storybook/sveltekit 11.0.0-beta.1 → 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.
- package/dist/_browser-chunks/chunk-3HHKZM2E.js +55 -0
- package/dist/_browser-chunks/chunk-VAS652SN.js +88 -0
- package/dist/_node-chunks/{chunk-N7N5BJW4.js → chunk-GPJZQKOH.js} +8 -8
- package/dist/chunk-56nWP1O9.d.ts +43 -0
- package/dist/chunk-B5frDvvZ.d.ts +64 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/mocks/app/forms.d.ts +32 -0
- package/dist/mocks/app/forms.js +74 -14
- package/dist/mocks/app/navigation.d.ts +61 -0
- package/dist/mocks/app/navigation.js +63 -60
- package/dist/mocks/docs-isolation.d.ts +22 -0
- package/dist/mocks/docs-isolation.js +62 -0
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +6 -6
- package/dist/preset.js +11 -10
- package/dist/preview.js +2 -1
- package/dist/vite-plugin.js +7 -7
- package/package.json +20 -8
- package/static/app-state-mock.svelte.d.ts +39 -0
- package/static/app-state-mock.svelte.js +63 -33
- package/template/stories_svelte-kit-skeleton-ts/modules/Forms.svelte +18 -3
- package/template/stories_svelte-kit-skeleton-ts/modules/Hrefs.svelte +8 -0
- package/template/stories_svelte-kit-skeleton-ts/modules/State.svelte +3 -3
- package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-isolated-mocks.stories.js +26 -0
- package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-shared-mocks.stories.js +28 -0
- package/template/stories_svelte-kit-skeleton-ts/modules/docs-page-user.svelte +5 -0
- package/template/stories_svelte-kit-skeleton-ts/modules/forms.stories.js +88 -14
- package/template/stories_svelte-kit-skeleton-ts/modules/hrefs.stories.js +42 -33
- package/template/stories_svelte-kit-skeleton-ts/modules/navigation.stories.js +52 -111
- package/template/stories_svelte-kit-skeleton-ts/modules/state.stories.js +45 -63
- package/dist/_browser-chunks/chunk-EB5JBDJD.js +0 -34
- package/dist/chunk-Curl48fh.d.ts +0 -120
- package/static/MockProvider.svelte +0 -123
package/dist/chunk-Curl48fh.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { CompatibleString, StorybookConfig } from "storybook/internal/types";
|
|
2
|
-
import { BuilderOptions, StorybookConfigVite } from "@storybook/builder-vite";
|
|
3
|
-
|
|
4
|
-
//#region code/frameworks/sveltekit/.dts-emit/code/frameworks/sveltekit/src/mocks/app/navigation.d.ts
|
|
5
|
-
declare function goto(...args: any[]): Promise<void>;
|
|
6
|
-
declare function invalidate(...args: any[]): Promise<void>;
|
|
7
|
-
declare function invalidateAll(): Promise<void>;
|
|
8
|
-
declare function refreshAll(): Promise<void>;
|
|
9
|
-
declare function pushState(...args: any[]): Promise<void>;
|
|
10
|
-
declare function replaceState(...args: any[]): Promise<void>;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region code/frameworks/sveltekit/.dts-emit/code/frameworks/sveltekit/src/types.d.ts
|
|
13
|
-
type FrameworkName = CompatibleString<'@storybook/sveltekit'>;
|
|
14
|
-
type BuilderName = CompatibleString<'@storybook/builder-vite'>;
|
|
15
|
-
type FrameworkOptions = {
|
|
16
|
-
builder?: BuilderOptions;
|
|
17
|
-
/**
|
|
18
|
-
* Enable or disable automatic documentation generation for component properties, events, and
|
|
19
|
-
* slots. When disabled, Storybook will skip the docgen processing step during build, which can
|
|
20
|
-
* improve build performance.
|
|
21
|
-
*
|
|
22
|
-
* @deprecated Builder docgen is removed in Storybook 12. Use `features.docgenServer`.
|
|
23
|
-
* @default true
|
|
24
|
-
*/
|
|
25
|
-
docgen?: boolean;
|
|
26
|
-
};
|
|
27
|
-
type StorybookConfigFramework = {
|
|
28
|
-
framework: FrameworkName | {
|
|
29
|
-
name: FrameworkName;
|
|
30
|
-
options: FrameworkOptions;
|
|
31
|
-
};
|
|
32
|
-
core?: StorybookConfig['core'] & {
|
|
33
|
-
builder?: BuilderName | {
|
|
34
|
-
name: BuilderName;
|
|
35
|
-
options: BuilderOptions;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
type StorybookConfig$1 = Omit<StorybookConfig, keyof StorybookConfigVite | keyof StorybookConfigFramework> & StorybookConfigVite & StorybookConfigFramework;
|
|
40
|
-
type NormalizedHrefConfig = {
|
|
41
|
-
callback: (to: string, event: Event) => void;
|
|
42
|
-
asRegex?: boolean;
|
|
43
|
-
};
|
|
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: ({
|
|
57
|
-
message: string;
|
|
58
|
-
} & Record<string, any>) | null;
|
|
59
|
-
data: Record<string, any>;
|
|
60
|
-
state: Record<string, any>;
|
|
61
|
-
form: any;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Copied from:
|
|
65
|
-
* {@link https://github.com/sveltejs/kit/blob/7bb41aa4263b057a8912f4cdd35db03755d37342/packages/kit/types/index.d.ts#L988}
|
|
66
|
-
*/
|
|
67
|
-
interface NavigationTarget {
|
|
68
|
-
params: Record<string, string> | null;
|
|
69
|
-
route: {
|
|
70
|
-
id: string | null;
|
|
71
|
-
};
|
|
72
|
-
url: URL;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Copied from:
|
|
76
|
-
* {@link https://github.com/sveltejs/kit/blob/7bb41aa4263b057a8912f4cdd35db03755d37342/packages/kit/types/index.d.ts#L1017C9-L1017C89}
|
|
77
|
-
*/
|
|
78
|
-
type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
79
|
-
/**
|
|
80
|
-
* Copied from:
|
|
81
|
-
* {@link https://github.com/sveltejs/kit/blob/7bb41aa4263b057a8912f4cdd35db03755d37342/packages/kit/types/index.d.ts#L1017C9-L1017C89}
|
|
82
|
-
*/
|
|
83
|
-
interface Navigation {
|
|
84
|
-
from: NavigationTarget | null;
|
|
85
|
-
to: NavigationTarget | null;
|
|
86
|
-
type: Exclude<NavigationType, 'enter'>;
|
|
87
|
-
willUnload: boolean;
|
|
88
|
-
delta?: number;
|
|
89
|
-
complete: Promise<void>;
|
|
90
|
-
}
|
|
91
|
-
type MockOf<F extends (...args: any[]) => unknown> = (...args: Parameters<F>) => void;
|
|
92
|
-
type SvelteKitParameters = Partial<{
|
|
93
|
-
hrefs: Record<string, HrefConfig>;
|
|
94
|
-
state: Partial<{
|
|
95
|
-
page: Partial<Page>;
|
|
96
|
-
navigating: Partial<Navigation>;
|
|
97
|
-
updated: {
|
|
98
|
-
current: boolean;
|
|
99
|
-
};
|
|
100
|
-
}>;
|
|
101
|
-
navigation: Partial<{
|
|
102
|
-
goto: MockOf<typeof goto>;
|
|
103
|
-
invalidate: MockOf<typeof invalidate>;
|
|
104
|
-
invalidateAll: MockOf<typeof invalidateAll>;
|
|
105
|
-
refreshAll: MockOf<typeof refreshAll>;
|
|
106
|
-
pushState: MockOf<typeof pushState>;
|
|
107
|
-
replaceState: MockOf<typeof replaceState>;
|
|
108
|
-
afterNavigate: Record<string, any>;
|
|
109
|
-
}>;
|
|
110
|
-
forms: Partial<{
|
|
111
|
-
enhance: (event: SubmitEvent) => void;
|
|
112
|
-
}>;
|
|
113
|
-
}>;
|
|
114
|
-
interface SvelteKitTypes {
|
|
115
|
-
parameters: {
|
|
116
|
-
/** Mocks for the SvelteKit modules, such as `$app/state` and `$app/navigation`. */sveltekit_experimental?: SvelteKitParameters;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
//#endregion
|
|
120
|
-
export { SvelteKitParameters as a, StorybookConfig$1 as i, HrefConfig as n, SvelteKitTypes as o, NormalizedHrefConfig as r, FrameworkOptions as t };
|
|
@@ -1,123 +0,0 @@
|
|
|
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
|
-
|
|
7
|
-
const { svelteKitParameters = {}, children } = $props();
|
|
8
|
-
|
|
9
|
-
// Set context during component initialization - this happens before any child components
|
|
10
|
-
setAfterNavigateArgument(svelteKitParameters?.navigation?.afterNavigate);
|
|
11
|
-
|
|
12
|
-
const normalizeHrefConfig = (hrefConfig) => {
|
|
13
|
-
if (typeof hrefConfig === 'function') {
|
|
14
|
-
return { callback: hrefConfig, asRegex: false };
|
|
15
|
-
}
|
|
16
|
-
return hrefConfig;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
onMount(() => {
|
|
20
|
-
const globalClickListener = (e) => {
|
|
21
|
-
// we add a global click event listener and we check if there's a link in the composedPath
|
|
22
|
-
const path = e.composedPath();
|
|
23
|
-
const element = path.findLast((el) => el instanceof HTMLElement && el.tagName === 'A');
|
|
24
|
-
if (element && element instanceof HTMLAnchorElement) {
|
|
25
|
-
// if the element is an a-tag we get the href of the element
|
|
26
|
-
// and compare it to the hrefs-parameter set by the user
|
|
27
|
-
const to = element.getAttribute('href');
|
|
28
|
-
if (!to) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
e.preventDefault();
|
|
32
|
-
const defaultActionCallback = () => action('navigate')(to, e);
|
|
33
|
-
if (!svelteKitParameters.hrefs) {
|
|
34
|
-
defaultActionCallback();
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let callDefaultCallback = true;
|
|
39
|
-
// we loop over every href set by the user and check if the href matches
|
|
40
|
-
// if it does we call the callback provided by the user and disable the default callback
|
|
41
|
-
Object.entries(svelteKitParameters.hrefs).forEach(([href, hrefConfig]) => {
|
|
42
|
-
const { callback, asRegex } = normalizeHrefConfig(hrefConfig);
|
|
43
|
-
const isMatch = asRegex ? new RegExp(href).test(to) : to === href;
|
|
44
|
-
if (isMatch) {
|
|
45
|
-
callDefaultCallback = false;
|
|
46
|
-
callback?.(to, e);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
if (callDefaultCallback) {
|
|
50
|
-
defaultActionCallback();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Function that create and add listeners for the event that are emitted by the mocked
|
|
57
|
-
* functions. The event name is based on the function name
|
|
58
|
-
*
|
|
59
|
-
* Eg. storybook:goto, storybook:invalidateAll
|
|
60
|
-
*
|
|
61
|
-
* @param baseModule The base module where the function lives (navigation|forms)
|
|
62
|
-
* @param functions The list of functions in that module that emit events
|
|
63
|
-
* @param {boolean} [defaultToAction] The list of functions in that module that emit events
|
|
64
|
-
* @returns A function to remove all the listener added
|
|
65
|
-
*/
|
|
66
|
-
function createListeners(baseModule, functions, defaultToAction) {
|
|
67
|
-
// the array of every added listener, we can use this in the return function
|
|
68
|
-
// to clean them
|
|
69
|
-
const toRemove = [];
|
|
70
|
-
functions.forEach((func) => {
|
|
71
|
-
// we loop over every function and check if the user actually passed
|
|
72
|
-
// a function in sveltekit_experimental[baseModule][func] eg. sveltekit_experimental.navigation.goto
|
|
73
|
-
const hasFunction =
|
|
74
|
-
svelteKitParameters[baseModule]?.[func] &&
|
|
75
|
-
svelteKitParameters[baseModule][func] instanceof Function;
|
|
76
|
-
// if we default to an action we still add the listener (this will be the case for goto, invalidate, invalidateAll)
|
|
77
|
-
if (hasFunction || defaultToAction) {
|
|
78
|
-
// we create the listener that will just get the detail array from the custom element
|
|
79
|
-
// and call the user provided function spreading this args in...this will basically call
|
|
80
|
-
// the function that the user provide with the same arguments the function is invoked to
|
|
81
|
-
|
|
82
|
-
// eg. if it calls goto("/my-route") inside the component the function sveltekit_experimental.navigation.goto
|
|
83
|
-
// it provided to storybook will be called with "/my-route"
|
|
84
|
-
const listener = ({ detail = [] }) => {
|
|
85
|
-
const args = Array.isArray(detail) ? detail : [];
|
|
86
|
-
// if it has a function in the parameters we call that function
|
|
87
|
-
// otherwise we invoke the action
|
|
88
|
-
const fnToCall = hasFunction
|
|
89
|
-
? svelteKitParameters[baseModule][func]
|
|
90
|
-
: action(func);
|
|
91
|
-
fnToCall(...args);
|
|
92
|
-
};
|
|
93
|
-
const eventType = `storybook:${func}`;
|
|
94
|
-
toRemove.push({ eventType, listener });
|
|
95
|
-
// add the listener to window
|
|
96
|
-
window.addEventListener(eventType, listener);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return () => {
|
|
100
|
-
// loop over every listener added and remove them
|
|
101
|
-
toRemove.forEach(({ eventType, listener }) => {
|
|
102
|
-
window.removeEventListener(eventType, listener);
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const removeNavigationListeners = createListeners(
|
|
108
|
-
'navigation',
|
|
109
|
-
['goto', 'invalidate', 'invalidateAll', 'refreshAll', 'pushState', 'replaceState'],
|
|
110
|
-
true
|
|
111
|
-
);
|
|
112
|
-
const removeFormsListeners = createListeners('forms', ['enhance']);
|
|
113
|
-
window.addEventListener('click', globalClickListener);
|
|
114
|
-
|
|
115
|
-
return () => {
|
|
116
|
-
window.removeEventListener('click', globalClickListener);
|
|
117
|
-
removeNavigationListeners();
|
|
118
|
-
removeFormsListeners();
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
</script>
|
|
122
|
-
|
|
123
|
-
{@render children()}
|