@storybook/addon-svelte-csf 3.0.1 → 3.0.3
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/cjs/components/RenderContext.svelte +6 -2
- package/dist/cjs/components/Story.svelte +6 -4
- package/dist/cjs/components/Template.svelte +6 -3
- package/dist/cjs/components/context.js +18 -2
- package/dist/esm/components/RenderContext.svelte +6 -2
- package/dist/esm/components/Story.svelte +6 -4
- package/dist/esm/components/Template.svelte +6 -3
- package/dist/esm/components/context.js +18 -2
- package/index.d.ts +5 -5
- package/package.json +2 -1
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
* @component
|
|
4
4
|
* @wrapper
|
|
5
5
|
*/
|
|
6
|
-
import { createRenderContext } from './context';
|
|
6
|
+
import { createRenderContext, setStoryRenderContext } from './context';
|
|
7
7
|
|
|
8
8
|
export let Stories;
|
|
9
|
+
export let args = {};
|
|
10
|
+
export let storyContext = {};
|
|
9
11
|
|
|
10
12
|
createRenderContext($$props);
|
|
13
|
+
|
|
14
|
+
$: setStoryRenderContext(args, storyContext);
|
|
11
15
|
</script>
|
|
12
16
|
|
|
13
|
-
<svelte:component this={Stories}/>
|
|
17
|
+
<svelte:component this={Stories} />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { useContext } from './context';
|
|
2
|
+
import { getStoryRenderContext, useContext } from './context';
|
|
3
3
|
|
|
4
4
|
const context = useContext();
|
|
5
5
|
|
|
@@ -12,14 +12,16 @@
|
|
|
12
12
|
|
|
13
13
|
context.register({
|
|
14
14
|
name,
|
|
15
|
-
...$$restProps,
|
|
15
|
+
...$$restProps,
|
|
16
16
|
template: template != null ? template : !$$slots.default ? 'default' : null,
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
$: render = context.render && !context.templateName && context.storyName == name;
|
|
20
|
-
|
|
20
|
+
const ctx = getStoryRenderContext();
|
|
21
|
+
const args = ctx.argsStore;
|
|
22
|
+
const storyContext = ctx.storyContextStore;
|
|
21
23
|
</script>
|
|
22
24
|
|
|
23
25
|
{#if render}
|
|
24
|
-
<slot {
|
|
26
|
+
<slot {...$args} context={$storyContext} args={$args} />
|
|
25
27
|
{/if}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { useContext } from './context';
|
|
2
|
+
import { useContext, getStoryRenderContext } from './context';
|
|
3
3
|
|
|
4
4
|
const context = useContext();
|
|
5
5
|
|
|
6
6
|
export let id = 'default';
|
|
7
7
|
|
|
8
|
-
context.register({id, isTemplate: true});
|
|
8
|
+
context.register({ id, isTemplate: true });
|
|
9
9
|
|
|
10
10
|
$: render = context.render && context.templateId === id;
|
|
11
|
+
const ctx = getStoryRenderContext();
|
|
12
|
+
const args = ctx.argsStore;
|
|
13
|
+
const storyContext = ctx.storyContextStore;
|
|
11
14
|
</script>
|
|
12
15
|
|
|
13
16
|
{#if render}
|
|
14
|
-
<slot {
|
|
17
|
+
<slot {...$args} context={$storyContext} args={$args} />
|
|
15
18
|
{/if}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { getContext, hasContext, setContext } from
|
|
2
|
-
|
|
1
|
+
import { getContext, hasContext, setContext } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
const CONTEXT_KEY = 'storybook-registration-context';
|
|
4
|
+
const CONTEXT_KEY_COMPONENT = 'storybook-registration-context-component';
|
|
3
5
|
export function createRenderContext(props = {}) {
|
|
4
6
|
setContext(CONTEXT_KEY, {
|
|
5
7
|
render: true,
|
|
@@ -27,4 +29,18 @@ export function useContext() {
|
|
|
27
29
|
createRenderContext();
|
|
28
30
|
}
|
|
29
31
|
return getContext(CONTEXT_KEY);
|
|
32
|
+
}
|
|
33
|
+
export function getStoryRenderContext() {
|
|
34
|
+
if (!hasContext(CONTEXT_KEY_COMPONENT)) {
|
|
35
|
+
setContext(CONTEXT_KEY_COMPONENT, {
|
|
36
|
+
argsStore: writable({}),
|
|
37
|
+
storyContextStore: writable({})
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return getContext(CONTEXT_KEY_COMPONENT);
|
|
41
|
+
}
|
|
42
|
+
export function setStoryRenderContext(args, storyContext) {
|
|
43
|
+
const ctx = getStoryRenderContext();
|
|
44
|
+
ctx.argsStore.set(args);
|
|
45
|
+
ctx.storyContextStore.set(storyContext);
|
|
30
46
|
}
|
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
* @component
|
|
4
4
|
* @wrapper
|
|
5
5
|
*/
|
|
6
|
-
import { createRenderContext } from './context';
|
|
6
|
+
import { createRenderContext, setStoryRenderContext } from './context';
|
|
7
7
|
|
|
8
8
|
export let Stories;
|
|
9
|
+
export let args = {};
|
|
10
|
+
export let storyContext = {};
|
|
9
11
|
|
|
10
12
|
createRenderContext($$props);
|
|
13
|
+
|
|
14
|
+
$: setStoryRenderContext(args, storyContext);
|
|
11
15
|
</script>
|
|
12
16
|
|
|
13
|
-
<svelte:component this={Stories}/>
|
|
17
|
+
<svelte:component this={Stories} />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { useContext } from './context';
|
|
2
|
+
import { getStoryRenderContext, useContext } from './context';
|
|
3
3
|
|
|
4
4
|
const context = useContext();
|
|
5
5
|
|
|
@@ -12,14 +12,16 @@
|
|
|
12
12
|
|
|
13
13
|
context.register({
|
|
14
14
|
name,
|
|
15
|
-
...$$restProps,
|
|
15
|
+
...$$restProps,
|
|
16
16
|
template: template != null ? template : !$$slots.default ? 'default' : null,
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
$: render = context.render && !context.templateName && context.storyName == name;
|
|
20
|
-
|
|
20
|
+
const ctx = getStoryRenderContext();
|
|
21
|
+
const args = ctx.argsStore;
|
|
22
|
+
const storyContext = ctx.storyContextStore;
|
|
21
23
|
</script>
|
|
22
24
|
|
|
23
25
|
{#if render}
|
|
24
|
-
<slot {
|
|
26
|
+
<slot {...$args} context={$storyContext} args={$args} />
|
|
25
27
|
{/if}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { useContext } from './context';
|
|
2
|
+
import { useContext, getStoryRenderContext } from './context';
|
|
3
3
|
|
|
4
4
|
const context = useContext();
|
|
5
5
|
|
|
6
6
|
export let id = 'default';
|
|
7
7
|
|
|
8
|
-
context.register({id, isTemplate: true});
|
|
8
|
+
context.register({ id, isTemplate: true });
|
|
9
9
|
|
|
10
10
|
$: render = context.render && context.templateId === id;
|
|
11
|
+
const ctx = getStoryRenderContext();
|
|
12
|
+
const args = ctx.argsStore;
|
|
13
|
+
const storyContext = ctx.storyContextStore;
|
|
11
14
|
</script>
|
|
12
15
|
|
|
13
16
|
{#if render}
|
|
14
|
-
<slot {
|
|
17
|
+
<slot {...$args} context={$storyContext} args={$args} />
|
|
15
18
|
{/if}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { getContext, hasContext, setContext } from
|
|
2
|
-
|
|
1
|
+
import { getContext, hasContext, setContext } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
const CONTEXT_KEY = 'storybook-registration-context';
|
|
4
|
+
const CONTEXT_KEY_COMPONENT = 'storybook-registration-context-component';
|
|
3
5
|
export function createRenderContext(props = {}) {
|
|
4
6
|
setContext(CONTEXT_KEY, {
|
|
5
7
|
render: true,
|
|
@@ -27,4 +29,18 @@ export function useContext() {
|
|
|
27
29
|
createRenderContext();
|
|
28
30
|
}
|
|
29
31
|
return getContext(CONTEXT_KEY);
|
|
32
|
+
}
|
|
33
|
+
export function getStoryRenderContext() {
|
|
34
|
+
if (!hasContext(CONTEXT_KEY_COMPONENT)) {
|
|
35
|
+
setContext(CONTEXT_KEY_COMPONENT, {
|
|
36
|
+
argsStore: writable({}),
|
|
37
|
+
storyContextStore: writable({})
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return getContext(CONTEXT_KEY_COMPONENT);
|
|
41
|
+
}
|
|
42
|
+
export function setStoryRenderContext(args, storyContext) {
|
|
43
|
+
const ctx = getStoryRenderContext();
|
|
44
|
+
ctx.argsStore.set(args);
|
|
45
|
+
ctx.storyContextStore.set(storyContext);
|
|
30
46
|
}
|
package/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { SvelteComponentTyped, SvelteComponent } from 'svelte';
|
|
2
|
-
import type { Addon_BaseMeta as BaseMeta, Addon_BaseAnnotations as BaseAnnotations, StoryContext } from '@storybook/types';
|
|
2
|
+
import type { Addon_BaseMeta as BaseMeta, Addon_BaseAnnotations as BaseAnnotations, StoryContext, WebRenderer } from '@storybook/types';
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
type DecoratorReturnType = void|SvelteComponent|{
|
|
5
|
+
type DecoratorReturnType = void | SvelteComponent | {
|
|
6
6
|
Component: any,
|
|
7
7
|
props?: any
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
interface StoryProps extends BaseAnnotations<any, DecoratorReturnType> {
|
|
10
|
+
interface StoryProps extends BaseAnnotations<any, DecoratorReturnType, WebRenderer> {
|
|
11
11
|
/**
|
|
12
12
|
* Id of the story.
|
|
13
13
|
*
|
|
@@ -32,7 +32,7 @@ interface StoryProps extends BaseAnnotations<any, DecoratorReturnType> {
|
|
|
32
32
|
* If source is true, then the source of the story will be used instead.
|
|
33
33
|
* If source is a string, it replaces the source of the story.
|
|
34
34
|
*/
|
|
35
|
-
source?: boolean|string
|
|
35
|
+
source?: boolean | string
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
interface TemplateProps extends BaseAnnotations<any, DecoratorReturnType> {
|
|
@@ -54,7 +54,7 @@ interface Slots {
|
|
|
54
54
|
/**
|
|
55
55
|
* Meta.
|
|
56
56
|
*/
|
|
57
|
-
export class Meta extends SvelteComponentTyped<BaseMeta<any> & BaseAnnotations<any, DecoratorReturnType>> {}
|
|
57
|
+
export class Meta extends SvelteComponentTyped<BaseMeta<any> & BaseAnnotations<any, DecoratorReturnType>> { }
|
|
58
58
|
/**
|
|
59
59
|
* Story.
|
|
60
60
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-svelte-csf",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Allows to write stories in Svelte syntax",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook-addons",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"@storybook/svelte": "^7.0.0-beta.0 || ^7.0.0-rc.0 || ^7.0.0",
|
|
58
58
|
"@storybook/svelte-webpack5": "^7.0.0-beta.0 || ^7.0.0-rc.0 || ^7.0.0",
|
|
59
59
|
"@storybook/testing-library": "^0.0.13",
|
|
60
|
+
"@storybook/types": "^7.0.0-beta.0 || ^7.0.0-rc.0 || ^7.0.0",
|
|
60
61
|
"auto": "^10.43.0",
|
|
61
62
|
"babel-jest": "^29.5.0",
|
|
62
63
|
"babel-loader": "^8.1.0",
|