From 44b95f07ece7b62e0ae89d9fe1b98de9962bf4bb Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Wed, 12 Oct 2022 20:37:32 +0200 Subject: [PATCH] more typesafe CSF3 types for svelte --- code/addons/a11y/package.json | 2 +- code/addons/actions/package.json | 2 +- code/addons/backgrounds/package.json | 2 +- code/addons/controls/package.json | 2 +- code/addons/docs/package.json | 2 +- code/addons/interactions/package.json | 2 +- code/addons/links/package.json | 2 +- code/addons/measure/package.json | 2 +- code/addons/outline/package.json | 2 +- .../storyshots/storyshots-core/package.json | 2 +- .../storyshots-puppeteer/package.json | 2 +- code/examples/external-docs/package.json | 2 +- code/frameworks/angular/package.json | 2 +- code/lib/addons/package.json | 2 +- code/lib/api/package.json | 2 +- code/lib/blocks/package.json | 2 +- code/lib/client-api/package.json | 2 +- code/lib/codemod/package.json | 2 +- code/lib/components/package.json | 2 +- code/lib/core-client/package.json | 2 +- code/lib/core-common/package.json | 2 +- code/lib/core-common/src/index.ts | 1 + .../core-common/src/utils/satisfies.ts} | 0 code/lib/core-server/package.json | 2 +- code/lib/csf-tools/package.json | 2 +- code/lib/docs-tools/package.json | 2 +- code/lib/preview-web/package.json | 2 +- code/lib/source-loader/package.json | 2 +- code/lib/store/package.json | 2 +- code/package.json | 2 +- code/renderers/html/package.json | 2 +- code/renderers/preact/package.json | 2 +- code/renderers/react/package.json | 2 +- .../CSF3.test.tsx => public-types.test.tsx} | 17 +- code/renderers/react/src/public-types.ts | 34 ++- code/renderers/server/package.json | 2 +- code/renderers/svelte/package.json | 9 +- .../svelte/src/___test___/Button.svelte | 12 + .../svelte/src/___test___/Decorator.svelte | 8 + .../svelte/src/___test___/Decorator2.svelte | 8 + .../svelte/src/docs/extractArgTypes.test.ts | 1 + .../svelte/src/docs/extractArgTypes.ts | 2 +- .../docs/extractComponentDescription.test.ts | 1 + .../svelte/src/docs/sourceDecorator.test.ts | 7 +- .../svelte/src/docs/sourceDecorator.ts | 2 +- code/renderers/svelte/src/globals.ts | 1 - .../renderers/svelte/src/public-types.test.ts | 224 ++++++++++++++++++ code/renderers/svelte/src/public-types.ts | 45 +++- code/renderers/svelte/src/render.ts | 9 +- code/renderers/svelte/src/types.ts | 36 ++- code/renderers/svelte/src/typings.d.ts | 4 +- .../svelte/templates/PreviewRender.svelte | 4 +- code/renderers/svelte/tsconfig.json | 4 +- code/renderers/vue/package.json | 2 +- code/renderers/vue3/package.json | 2 +- code/renderers/web-components/package.json | 2 +- code/ui/manager/package.json | 2 +- code/yarn.lock | 126 ++++++---- package.json | 3 +- scripts/tasks/check.ts | 5 +- scripts/utils/options.test.ts | 8 +- 61 files changed, 488 insertions(+), 155 deletions(-) rename code/{renderers/react/src/__test__/utils.ts => lib/core-common/src/utils/satisfies.ts} (100%) rename code/renderers/react/src/{__test__/CSF3.test.tsx => public-types.test.tsx} (93%) create mode 100644 code/renderers/svelte/src/___test___/Button.svelte create mode 100644 code/renderers/svelte/src/___test___/Decorator.svelte create mode 100644 code/renderers/svelte/src/___test___/Decorator2.svelte create mode 100644 code/renderers/svelte/src/public-types.test.ts diff --git a/code/addons/a11y/package.json b/code/addons/a11y/package.json index c73adb6a8fe6..4be5dcb19397 100644 --- a/code/addons/a11y/package.json +++ b/code/addons/a11y/package.json @@ -69,7 +69,7 @@ "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/components": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/theming": "7.0.0-alpha.38", "axe-core": "^4.2.0", "global": "^4.4.0", diff --git a/code/addons/actions/package.json b/code/addons/actions/package.json index 5ed3599054b6..af21014cd6f7 100644 --- a/code/addons/actions/package.json +++ b/code/addons/actions/package.json @@ -63,7 +63,7 @@ "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/components": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/theming": "7.0.0-alpha.38", "dequal": "^2.0.2", "global": "^4.4.0", diff --git a/code/addons/backgrounds/package.json b/code/addons/backgrounds/package.json index d27de73a1be5..4b4bc1678c5d 100644 --- a/code/addons/backgrounds/package.json +++ b/code/addons/backgrounds/package.json @@ -67,7 +67,7 @@ "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/components": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/theming": "7.0.0-alpha.38", "global": "^4.4.0", "memoizerific": "^1.11.3", diff --git a/code/addons/controls/package.json b/code/addons/controls/package.json index 73766d9ea09d..83e7167b1dce 100644 --- a/code/addons/controls/package.json +++ b/code/addons/controls/package.json @@ -63,7 +63,7 @@ "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/components": "7.0.0-alpha.38", "@storybook/core-common": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/node-logger": "7.0.0-alpha.38", "@storybook/store": "7.0.0-alpha.38", "@storybook/theming": "7.0.0-alpha.38", diff --git a/code/addons/docs/package.json b/code/addons/docs/package.json index d61b6099e589..f4f2871a83c5 100644 --- a/code/addons/docs/package.json +++ b/code/addons/docs/package.json @@ -59,7 +59,7 @@ "@storybook/components": "7.0.0-alpha.38", "@storybook/core-common": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/csf-tools": "7.0.0-alpha.38", "@storybook/docs-tools": "7.0.0-alpha.38", "@storybook/mdx1-csf": "0.0.5-canary.13.9ce928a.0", diff --git a/code/addons/interactions/package.json b/code/addons/interactions/package.json index b52b1da54415..f8b4bd934d6b 100644 --- a/code/addons/interactions/package.json +++ b/code/addons/interactions/package.json @@ -65,7 +65,7 @@ "@storybook/components": "7.0.0-alpha.38", "@storybook/core-common": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/instrumenter": "7.0.0-alpha.38", "@storybook/theming": "7.0.0-alpha.38", "global": "^4.4.0", diff --git a/code/addons/links/package.json b/code/addons/links/package.json index 62b2c42aa66b..fe7d1d64ffd4 100644 --- a/code/addons/links/package.json +++ b/code/addons/links/package.json @@ -66,7 +66,7 @@ "@storybook/addons": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/router": "7.0.0-alpha.38", "global": "^4.4.0", "prop-types": "^15.7.2", diff --git a/code/addons/measure/package.json b/code/addons/measure/package.json index 1b9e97a786d9..f6b93eda10cf 100644 --- a/code/addons/measure/package.json +++ b/code/addons/measure/package.json @@ -66,7 +66,7 @@ "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/components": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "global": "^4.4.0" }, "devDependencies": { diff --git a/code/addons/outline/package.json b/code/addons/outline/package.json index 5ddd3f6f80c1..36017d98d7f6 100644 --- a/code/addons/outline/package.json +++ b/code/addons/outline/package.json @@ -69,7 +69,7 @@ "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/components": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "global": "^4.4.0", "ts-dedent": "^2.0.0" }, diff --git a/code/addons/storyshots/storyshots-core/package.json b/code/addons/storyshots/storyshots-core/package.json index d19385c0f2f0..cad2a9e2fba1 100644 --- a/code/addons/storyshots/storyshots-core/package.json +++ b/code/addons/storyshots/storyshots-core/package.json @@ -44,7 +44,7 @@ "@storybook/core-client": "7.0.0-alpha.38", "@storybook/core-common": "7.0.0-alpha.38", "@storybook/core-webpack": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@types/glob": "^7.1.3", "@types/jest": "^26.0.16", "@types/jest-specific-snapshot": "^0.5.3", diff --git a/code/addons/storyshots/storyshots-puppeteer/package.json b/code/addons/storyshots/storyshots-puppeteer/package.json index dbecfdf0d12e..74a780fa53dc 100644 --- a/code/addons/storyshots/storyshots-puppeteer/package.json +++ b/code/addons/storyshots/storyshots-puppeteer/package.json @@ -34,7 +34,7 @@ }, "dependencies": { "@axe-core/puppeteer": "^4.2.0", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/node-logger": "7.0.0-alpha.38", "@types/jest-image-snapshot": "^4.1.3", "jest-image-snapshot": "^4.3.0" diff --git a/code/examples/external-docs/package.json b/code/examples/external-docs/package.json index d1bf1e57dd12..3369d842c392 100644 --- a/code/examples/external-docs/package.json +++ b/code/examples/external-docs/package.json @@ -15,7 +15,7 @@ "@storybook/addon-essentials": "7.0.0-alpha.38", "@storybook/blocks": "7.0.0-alpha.38", "@storybook/components": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/preview-web": "7.0.0-alpha.38", "@storybook/react": "7.0.0-alpha.38", "@storybook/react-webpack5": "7.0.0-alpha.38", diff --git a/code/frameworks/angular/package.json b/code/frameworks/angular/package.json index d237136a690b..539f395b56c6 100644 --- a/code/frameworks/angular/package.json +++ b/code/frameworks/angular/package.json @@ -43,7 +43,7 @@ "@storybook/core-events": "7.0.0-alpha.38", "@storybook/core-server": "7.0.0-alpha.38", "@storybook/core-webpack": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/docs-tools": "7.0.0-alpha.38", "@storybook/node-logger": "7.0.0-alpha.38", "@storybook/store": "7.0.0-alpha.38", diff --git a/code/lib/addons/package.json b/code/lib/addons/package.json index 58dab4067366..20c2632ef36e 100644 --- a/code/lib/addons/package.json +++ b/code/lib/addons/package.json @@ -46,7 +46,7 @@ "@storybook/channels": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/router": "7.0.0-alpha.38", "@storybook/theming": "7.0.0-alpha.38", "global": "^4.4.0" diff --git a/code/lib/api/package.json b/code/lib/api/package.json index b768bf023880..447e13396482 100644 --- a/code/lib/api/package.json +++ b/code/lib/api/package.json @@ -48,7 +48,7 @@ "@storybook/channels": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/router": "7.0.0-alpha.38", "@storybook/theming": "7.0.0-alpha.38", "dequal": "^2.0.2", diff --git a/code/lib/blocks/package.json b/code/lib/blocks/package.json index 7f8d1528bf4b..fed9331466b1 100644 --- a/code/lib/blocks/package.json +++ b/code/lib/blocks/package.json @@ -46,7 +46,7 @@ "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/components": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/docs-tools": "7.0.0-alpha.38", "@storybook/preview-web": "7.0.0-alpha.38", "@storybook/store": "7.0.0-alpha.38", diff --git a/code/lib/client-api/package.json b/code/lib/client-api/package.json index c31e6c81df50..88e2de06c452 100644 --- a/code/lib/client-api/package.json +++ b/code/lib/client-api/package.json @@ -44,7 +44,7 @@ "dependencies": { "@storybook/addons": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/store": "7.0.0-alpha.38", "@types/qs": "^6.9.5", "@types/webpack-env": "^1.16.4", diff --git a/code/lib/codemod/package.json b/code/lib/codemod/package.json index 818967fdb4a6..336f533317da 100644 --- a/code/lib/codemod/package.json +++ b/code/lib/codemod/package.json @@ -39,7 +39,7 @@ "dependencies": { "@babel/types": "^7.12.11", "@mdx-js/mdx": "^1.6.22", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/csf-tools": "7.0.0-alpha.38", "@storybook/node-logger": "7.0.0-alpha.38", "cross-spawn": "^7.0.3", diff --git a/code/lib/components/package.json b/code/lib/components/package.json index ea5bd76233ed..b74306c0797e 100644 --- a/code/lib/components/package.json +++ b/code/lib/components/package.json @@ -52,7 +52,7 @@ }, "dependencies": { "@storybook/client-logger": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/theming": "7.0.0-alpha.38", "memoizerific": "^1.11.3", "util-deprecate": "^1.0.2" diff --git a/code/lib/core-client/package.json b/code/lib/core-client/package.json index 2918f5d075c1..c0a7f7db90f9 100644 --- a/code/lib/core-client/package.json +++ b/code/lib/core-client/package.json @@ -41,7 +41,7 @@ "@storybook/client-api": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/preview-web": "7.0.0-alpha.38", "@storybook/store": "7.0.0-alpha.38", "@storybook/ui": "7.0.0-alpha.38", diff --git a/code/lib/core-common/package.json b/code/lib/core-common/package.json index 09e291476c40..5996d5080883 100644 --- a/code/lib/core-common/package.json +++ b/code/lib/core-common/package.json @@ -47,7 +47,7 @@ }, "dependencies": { "@babel/core": "^7.12.10", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/node-logger": "7.0.0-alpha.38", "@types/babel__core": "^7.0.0", "@types/express": "^4.7.0", diff --git a/code/lib/core-common/src/index.ts b/code/lib/core-common/src/index.ts index 5b95a7716571..034c4a9301c6 100644 --- a/code/lib/core-common/src/index.ts +++ b/code/lib/core-common/src/index.ts @@ -28,6 +28,7 @@ export * from './utils/normalize-stories'; export * from './utils/readTemplate'; export * from './utils/findDistEsm'; export * from './utils/symlinks'; +export * from './utils/satisfies'; export * from './types'; diff --git a/code/renderers/react/src/__test__/utils.ts b/code/lib/core-common/src/utils/satisfies.ts similarity index 100% rename from code/renderers/react/src/__test__/utils.ts rename to code/lib/core-common/src/utils/satisfies.ts diff --git a/code/lib/core-server/package.json b/code/lib/core-server/package.json index dcdf9d62057e..91c44ecd006a 100644 --- a/code/lib/core-server/package.json +++ b/code/lib/core-server/package.json @@ -39,7 +39,7 @@ "@storybook/core-client": "7.0.0-alpha.38", "@storybook/core-common": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/csf-tools": "7.0.0-alpha.38", "@storybook/docs-mdx": "0.0.1-canary.12433cf.0", "@storybook/node-logger": "7.0.0-alpha.38", diff --git a/code/lib/csf-tools/package.json b/code/lib/csf-tools/package.json index 6e795fa3b613..c95194fe9c71 100644 --- a/code/lib/csf-tools/package.json +++ b/code/lib/csf-tools/package.json @@ -46,7 +46,7 @@ "@babel/parser": "^7.12.11", "@babel/traverse": "^7.12.11", "@babel/types": "^7.12.11", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "fs-extra": "^9.0.1", "ts-dedent": "^2.0.0" }, diff --git a/code/lib/docs-tools/package.json b/code/lib/docs-tools/package.json index 4cb875f14418..9427b0823e2a 100644 --- a/code/lib/docs-tools/package.json +++ b/code/lib/docs-tools/package.json @@ -44,7 +44,7 @@ "dependencies": { "@babel/core": "^7.12.10", "@storybook/core-common": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/store": "7.0.0-alpha.38", "doctrine": "^3.0.0", "lodash": "^4.17.21" diff --git a/code/lib/preview-web/package.json b/code/lib/preview-web/package.json index abe4e86bf78e..799b70ae3c2b 100644 --- a/code/lib/preview-web/package.json +++ b/code/lib/preview-web/package.json @@ -38,7 +38,7 @@ "@storybook/channels": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/store": "7.0.0-alpha.38", "ansi-to-html": "^0.6.11", "global": "^4.4.0", diff --git a/code/lib/source-loader/package.json b/code/lib/source-loader/package.json index 1085165920b9..df3c1edb4e31 100644 --- a/code/lib/source-loader/package.json +++ b/code/lib/source-loader/package.json @@ -43,7 +43,7 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "estraverse": "^5.2.0", "lodash": "^4.17.21", "prettier": ">=2.2.1 <=2.3.0" diff --git a/code/lib/store/package.json b/code/lib/store/package.json index 631cc4344db9..c07380083fb0 100644 --- a/code/lib/store/package.json +++ b/code/lib/store/package.json @@ -45,7 +45,7 @@ "@storybook/addons": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/core-events": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "dequal": "^2.0.2", "global": "^4.4.0", "lodash": "^4.17.21", diff --git a/code/package.json b/code/package.json index fc972e5f977e..de0d3d339f61 100644 --- a/code/package.json +++ b/code/package.json @@ -336,7 +336,7 @@ "ts-jest": "^26.4.4", "ts-node": "^10.4.0", "tsup": "^6.2.2", - "typescript": "4.7.4", + "typescript": "~4.6.3", "util": "^0.12.4", "vite": "^3.1.7", "wait-on": "^5.2.1", diff --git a/code/renderers/html/package.json b/code/renderers/html/package.json index 1187a3cc35db..efae979f1961 100644 --- a/code/renderers/html/package.json +++ b/code/renderers/html/package.json @@ -52,7 +52,7 @@ "dependencies": { "@storybook/addons": "7.0.0-alpha.38", "@storybook/core-client": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/docs-tools": "7.0.0-alpha.38", "@storybook/preview-web": "7.0.0-alpha.38", "@storybook/store": "7.0.0-alpha.38", diff --git a/code/renderers/preact/package.json b/code/renderers/preact/package.json index 8b4e25afd277..4ad1a18c13e1 100644 --- a/code/renderers/preact/package.json +++ b/code/renderers/preact/package.json @@ -52,7 +52,7 @@ "dependencies": { "@storybook/addons": "7.0.0-alpha.38", "@storybook/core-client": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/store": "7.0.0-alpha.38", "global": "^4.4.0", "react": "16.14.0", diff --git a/code/renderers/react/package.json b/code/renderers/react/package.json index ae3c052755f8..a529067cf868 100644 --- a/code/renderers/react/package.json +++ b/code/renderers/react/package.json @@ -54,7 +54,7 @@ "@storybook/addons": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/core-client": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/docs-tools": "7.0.0-alpha.38", "@storybook/store": "7.0.0-alpha.38", "@types/estree": "^0.0.51", diff --git a/code/renderers/react/src/__test__/CSF3.test.tsx b/code/renderers/react/src/public-types.test.tsx similarity index 93% rename from code/renderers/react/src/__test__/CSF3.test.tsx rename to code/renderers/react/src/public-types.test.tsx index 89bbb79aa3ea..7c407f77c324 100644 --- a/code/renderers/react/src/__test__/CSF3.test.tsx +++ b/code/renderers/react/src/public-types.test.tsx @@ -1,13 +1,13 @@ -import React, { KeyboardEventHandler, ReactNode } from 'react'; -import { expectTypeOf } from 'expect-type'; import { describe, test } from '@jest/globals'; +import { satisfies } from '@storybook/core-common'; import { StoryAnnotations } from '@storybook/csf'; +import { expectTypeOf } from 'expect-type'; +import React, { KeyboardEventHandler, ReactNode } from 'react'; import { SetOptional } from 'type-fest'; -import { Meta, StoryObj } from '../public-types'; -import { DecoratorFn } from '../public-api'; -import { satisfies } from './utils'; -import { ReactFramework } from '../types'; +import { DecoratorFn } from './public-api'; +import { Meta, StoryObj } from './public-types'; +import { ReactFramework } from './types'; type ReactStory = StoryAnnotations; @@ -75,6 +75,11 @@ describe('Args can be provided in multiple ways', () => { expectTypeOf(Basic).toEqualTypeOf(); } }); + + test('Component can be used as generic parameter for StoryObj', () => { + type Expected = ReactStory; + expectTypeOf>().toEqualTypeOf(); + }); }); test('✅ All void functions are optional', () => { diff --git a/code/renderers/react/src/public-types.ts b/code/renderers/react/src/public-types.ts index d724fc681c73..34452cf0c8a9 100644 --- a/code/renderers/react/src/public-types.ts +++ b/code/renderers/react/src/public-types.ts @@ -1,16 +1,15 @@ import type { AnnotatedStoryFn, Args, + ArgsFromMeta, ArgsStoryFn, ComponentAnnotations, - LoaderFunction, StoryAnnotations, } from '@storybook/csf'; -import { SetOptional, Simplify, UnionToIntersection } from 'type-fest'; import { ComponentProps, ComponentType, JSXElementConstructor } from 'react'; +import { SetOptional, Simplify } from 'type-fest'; import { ReactFramework } from './types'; -import { DecoratorFn } from './public-api'; type JSXElement = keyof JSX.IntrinsicElements | JSXElementConstructor; @@ -36,29 +35,28 @@ export type StoryFn = AnnotatedStoryFn; * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports) */ -export type StoryObj = MetaOrArgs extends { - render?: ArgsStoryFn; - component?: ComponentType; - loaders?: (infer Loaders)[]; +export type StoryObj = MetaOrCmpOrArgs extends { + render?: ArgsStoryFn; + component?: infer Component; args?: infer DefaultArgs; - decorators?: (infer Decorators)[]; } - ? Simplify & LoaderArgs> extends infer TArgs + ? Simplify< + (Component extends ComponentType ? ComponentProps : unknown) & + ArgsFromMeta + > extends infer TArgs ? StoryAnnotations< ReactFramework, TArgs, SetOptional)>> > : never - : StoryAnnotations; - -type DecoratorsArgs = UnionToIntersection< - Decorators extends DecoratorFn ? Args : unknown ->; - -type LoaderArgs = UnionToIntersection< - Loaders extends LoaderFunction ? Args : unknown ->; + : MetaOrCmpOrArgs extends ComponentType + ? StoryAnnotations< + ReactFramework, + ComponentProps, + ComponentProps + > + : StoryAnnotations; type ActionArgs = { [P in keyof Args as ((...args: any[]) => void) extends Args[P] ? P : never]: Args[P]; diff --git a/code/renderers/server/package.json b/code/renderers/server/package.json index 3e7413a52f43..87d4539f207b 100644 --- a/code/renderers/server/package.json +++ b/code/renderers/server/package.json @@ -52,7 +52,7 @@ "dependencies": { "@storybook/addons": "7.0.0-alpha.38", "@storybook/core-client": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/preview-web": "7.0.0-alpha.38", "@storybook/store": "7.0.0-alpha.38", "global": "^4.4.0", diff --git a/code/renderers/svelte/package.json b/code/renderers/svelte/package.json index ace782a2c08d..ee8eaa7e3378 100644 --- a/code/renderers/svelte/package.json +++ b/code/renderers/svelte/package.json @@ -50,23 +50,26 @@ "*.d.ts" ], "scripts": { - "check": "../../../scripts/node_modules/.bin/tsc --noEmit", + "check": "svelte-check --tsconfig ./tsconfig.json", "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { "@storybook/addons": "7.0.0-alpha.38", "@storybook/client-logger": "7.0.0-alpha.38", "@storybook/core-client": "7.0.0-alpha.38", - "@storybook/csf": "0.0.2--canary.49.258942b.0", + "@storybook/csf": "0.0.2--canary.51.768ca23.0", "@storybook/docs-tools": "7.0.0-alpha.38", "@storybook/store": "7.0.0-alpha.38", "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", - "sveltedoc-parser": "^4.2.1" + "sveltedoc-parser": "^4.2.1", + "type-fest": "2.19.0" }, "devDependencies": { + "expect-type": "^0.14.2", "svelte": "^3.31.2", + "svelte-check": "^2.9.2", "typescript": "~4.6.3" }, "peerDependencies": { diff --git a/code/renderers/svelte/src/___test___/Button.svelte b/code/renderers/svelte/src/___test___/Button.svelte new file mode 100644 index 000000000000..b7fd6e8e325c --- /dev/null +++ b/code/renderers/svelte/src/___test___/Button.svelte @@ -0,0 +1,12 @@ + + + diff --git a/code/renderers/svelte/src/___test___/Decorator.svelte b/code/renderers/svelte/src/___test___/Decorator.svelte new file mode 100644 index 000000000000..4fc5241ba9d4 --- /dev/null +++ b/code/renderers/svelte/src/___test___/Decorator.svelte @@ -0,0 +1,8 @@ + + +
+ Decorator: {decoratorArg} + +
diff --git a/code/renderers/svelte/src/___test___/Decorator2.svelte b/code/renderers/svelte/src/___test___/Decorator2.svelte new file mode 100644 index 000000000000..57d98a6e2676 --- /dev/null +++ b/code/renderers/svelte/src/___test___/Decorator2.svelte @@ -0,0 +1,8 @@ + + +
+ Decorator: {decoratorArg2} + +
diff --git a/code/renderers/svelte/src/docs/extractArgTypes.test.ts b/code/renderers/svelte/src/docs/extractArgTypes.test.ts index c1911ffa3d1d..dcde4dddcce6 100644 --- a/code/renderers/svelte/src/docs/extractArgTypes.test.ts +++ b/code/renderers/svelte/src/docs/extractArgTypes.test.ts @@ -1,3 +1,4 @@ +import { describe, expect } from '@jest/globals'; import svelteDoc from 'sveltedoc-parser'; import * as fs from 'fs'; import { createArgTypes } from './extractArgTypes'; diff --git a/code/renderers/svelte/src/docs/extractArgTypes.ts b/code/renderers/svelte/src/docs/extractArgTypes.ts index 900d55b336a2..080367309c23 100644 --- a/code/renderers/svelte/src/docs/extractArgTypes.ts +++ b/code/renderers/svelte/src/docs/extractArgTypes.ts @@ -89,7 +89,7 @@ export const createArgTypes = (docgen: SvelteComponentDoc) => { /** * Function to convert the type from sveltedoc-parser to a storybook type - * @param typeName + * @param type * @returns string */ const parseTypeToControl = (type: JSDocType | undefined): any => { diff --git a/code/renderers/svelte/src/docs/extractComponentDescription.test.ts b/code/renderers/svelte/src/docs/extractComponentDescription.test.ts index 3e6eb3e779c3..f2e7866f6394 100644 --- a/code/renderers/svelte/src/docs/extractComponentDescription.test.ts +++ b/code/renderers/svelte/src/docs/extractComponentDescription.test.ts @@ -1,3 +1,4 @@ +import { describe, expect, test } from '@jest/globals'; import { extractComponentDescription } from './extractComponentDescription'; describe('extractComponentDescription', () => { diff --git a/code/renderers/svelte/src/docs/sourceDecorator.test.ts b/code/renderers/svelte/src/docs/sourceDecorator.test.ts index 006a7bb4de05..eaa26616f792 100644 --- a/code/renderers/svelte/src/docs/sourceDecorator.test.ts +++ b/code/renderers/svelte/src/docs/sourceDecorator.test.ts @@ -1,12 +1,13 @@ +import { describe, expect, test } from '@jest/globals'; import type { Args } from '@storybook/api'; import { generateSvelteSource } from './sourceDecorator'; expect.addSnapshotSerializer({ print: (val: any) => val, - test: (val) => typeof val === 'string', + test: (val: unknown) => typeof val === 'string', }); -function generateForArgs(args: Args, slotProperty: string = null) { +function generateForArgs(args: Args, slotProperty: string | null = null) { return generateSvelteSource({ name: 'Component' }, args, {}, slotProperty); } @@ -42,6 +43,6 @@ describe('generateSvelteSource', () => { `); }); test('component is not set', () => { - expect(generateSvelteSource(null, null, null, null)).toBeNull(); + expect(generateSvelteSource(null, {}, {}, null)).toBeNull(); }); }); diff --git a/code/renderers/svelte/src/docs/sourceDecorator.ts b/code/renderers/svelte/src/docs/sourceDecorator.ts index d7b04f91c9df..05d90ffc5188 100644 --- a/code/renderers/svelte/src/docs/sourceDecorator.ts +++ b/code/renderers/svelte/src/docs/sourceDecorator.ts @@ -89,7 +89,7 @@ export function generateSvelteSource( component: any, args: Args, argTypes: ArgTypes, - slotProperty?: string + slotProperty?: string | null ): string | null { const name = getComponentName(component); diff --git a/code/renderers/svelte/src/globals.ts b/code/renderers/svelte/src/globals.ts index aabe0fd8fb42..a2fb5c9dad10 100644 --- a/code/renderers/svelte/src/globals.ts +++ b/code/renderers/svelte/src/globals.ts @@ -1,4 +1,3 @@ -// @ts-expect-error (Converted from ts-ignore) import global from 'global'; const { window: globalWindow } = global; diff --git a/code/renderers/svelte/src/public-types.test.ts b/code/renderers/svelte/src/public-types.test.ts new file mode 100644 index 000000000000..1f965457f1f0 --- /dev/null +++ b/code/renderers/svelte/src/public-types.test.ts @@ -0,0 +1,224 @@ +import { describe, test } from '@jest/globals'; +import { satisfies } from '@storybook/core-common'; +import { ComponentAnnotations, StoryAnnotations } from '@storybook/csf'; +import { expectTypeOf } from 'expect-type'; +import { ComponentProps, SvelteComponentTyped } from 'svelte'; +import Button from './___test___/Button.svelte'; +import Decorator from './___test___/Decorator.svelte'; +import Decorator2 from './___test___/Decorator2.svelte'; + +import { DecoratorFn, Meta, StoryObj } from './public-types'; +import { SvelteFramework } from './types'; + +type SvelteStory = StoryAnnotations< + SvelteFramework, + Args, + RequiredArgs +>; + +describe('Meta', () => { + test('Generic parameter of Meta can be a component', () => { + const meta: Meta