From c656965f51dd63e5d153e025faa09db6badf8fdf Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 18:54:13 +0100 Subject: [PATCH 01/17] split the html renderer preview entrypoint into docs & non-docs parts --- code/renderers/html/package.json | 12 ++++++------ code/renderers/html/preset.js | 1 + code/renderers/html/preview.js | 1 - code/renderers/html/src/config.ts | 7 ------- code/renderers/html/src/preset.ts | 23 +++++++++++++++++++++++ code/renderers/html/src/preview-docs.ts | 2 ++ code/renderers/html/src/preview.ts | 5 +++++ 7 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 code/renderers/html/preset.js delete mode 100644 code/renderers/html/preview.js delete mode 100644 code/renderers/html/src/config.ts create mode 100644 code/renderers/html/src/preset.ts create mode 100644 code/renderers/html/src/preview-docs.ts create mode 100644 code/renderers/html/src/preview.ts diff --git a/code/renderers/html/package.json b/code/renderers/html/package.json index 3d042ea5f214..e9827cca4af5 100644 --- a/code/renderers/html/package.json +++ b/code/renderers/html/package.json @@ -26,11 +26,9 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -71,7 +69,9 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts" + "./src/preset.ts", + "./src/preview.ts", + "./src/preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/html/preset.js b/code/renderers/html/preset.js new file mode 100644 index 000000000000..a83f95279e7f --- /dev/null +++ b/code/renderers/html/preset.js @@ -0,0 +1 @@ +module.exports = require('./dist/preset'); diff --git a/code/renderers/html/preview.js b/code/renderers/html/preview.js deleted file mode 100644 index fe48d8883ba4..000000000000 --- a/code/renderers/html/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config'; diff --git a/code/renderers/html/src/config.ts b/code/renderers/html/src/config.ts deleted file mode 100644 index a318cb8498a2..000000000000 --- a/code/renderers/html/src/config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { parameters as docsParams } from './docs/config'; -import type { Parameters } from './types'; - -export const parameters: Parameters = { renderer: 'html', ...docsParams }; - -export { decorators, argTypesEnhancers } from './docs/config'; -export { renderToCanvas, render } from './render'; diff --git a/code/renderers/html/src/preset.ts b/code/renderers/html/src/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/html/src/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/html/src/preview-docs.ts b/code/renderers/html/src/preview-docs.ts new file mode 100644 index 000000000000..afee24665b33 --- /dev/null +++ b/code/renderers/html/src/preview-docs.ts @@ -0,0 +1,2 @@ +export { parameters } from './docs/config'; +export { decorators, argTypesEnhancers } from './docs/config'; diff --git a/code/renderers/html/src/preview.ts b/code/renderers/html/src/preview.ts new file mode 100644 index 000000000000..ab53ac0c984a --- /dev/null +++ b/code/renderers/html/src/preview.ts @@ -0,0 +1,5 @@ +import type { Parameters } from './types'; + +export const parameters: Parameters = { renderer: 'html' }; + +export { renderToCanvas, render } from './render'; From bbdcd6aa409eee70bf2a8d653daff7b863ae841b Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 18:58:02 +0100 Subject: [PATCH 02/17] split the preact renderer preview entrypoint into docs & non-docs parts --- code/renderers/preact/package.json | 12 ++++++------ code/renderers/preact/preset.js | 1 + code/renderers/preact/preview.js | 1 - code/renderers/preact/src/config.ts | 5 ----- code/renderers/preact/src/preset.ts | 23 +++++++++++++++++++++++ code/renderers/preact/src/preview-docs.ts | 1 + code/renderers/preact/src/preview.ts | 3 +++ 7 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 code/renderers/preact/preset.js delete mode 100644 code/renderers/preact/preview.js delete mode 100644 code/renderers/preact/src/config.ts create mode 100644 code/renderers/preact/src/preset.ts create mode 100644 code/renderers/preact/src/preview-docs.ts create mode 100644 code/renderers/preact/src/preview.ts diff --git a/code/renderers/preact/package.json b/code/renderers/preact/package.json index eed4e9bdf033..ea5cb88809d7 100644 --- a/code/renderers/preact/package.json +++ b/code/renderers/preact/package.json @@ -26,11 +26,9 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -71,7 +69,9 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts" + "./src/preset.ts", + "./src/preview.ts", + "./src/preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/preact/preset.js b/code/renderers/preact/preset.js new file mode 100644 index 000000000000..a83f95279e7f --- /dev/null +++ b/code/renderers/preact/preset.js @@ -0,0 +1 @@ +module.exports = require('./dist/preset'); diff --git a/code/renderers/preact/preview.js b/code/renderers/preact/preview.js deleted file mode 100644 index fe48d8883ba4..000000000000 --- a/code/renderers/preact/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config'; diff --git a/code/renderers/preact/src/config.ts b/code/renderers/preact/src/config.ts deleted file mode 100644 index 6c72da1bc702..000000000000 --- a/code/renderers/preact/src/config.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { parameters as docsParams } from './docs/config'; - -export { renderToCanvas, render } from './render'; - -export const parameters: {} = { renderer: 'preact' as const, ...docsParams }; diff --git a/code/renderers/preact/src/preset.ts b/code/renderers/preact/src/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/preact/src/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/preact/src/preview-docs.ts b/code/renderers/preact/src/preview-docs.ts new file mode 100644 index 000000000000..c5cd5bb0dbd4 --- /dev/null +++ b/code/renderers/preact/src/preview-docs.ts @@ -0,0 +1 @@ +export { parameters } from './docs/config'; diff --git a/code/renderers/preact/src/preview.ts b/code/renderers/preact/src/preview.ts new file mode 100644 index 000000000000..b09bdf943bcf --- /dev/null +++ b/code/renderers/preact/src/preview.ts @@ -0,0 +1,3 @@ +export { renderToCanvas, render } from './render'; + +export const parameters = { renderer: 'preact' }; From fc5c4a9924127e843acc895b501e2dcb868345ea Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 19:08:20 +0100 Subject: [PATCH 03/17] split the react renderer preview entrypoint into docs & non-docs parts --- code/renderers/react/package.json | 17 ++++++---------- code/renderers/react/preview.js | 1 - code/renderers/react/src/config.ts | 9 --------- code/renderers/react/src/preset.ts | 25 +++++++++++++++++++++++- code/renderers/react/src/preview-docs.ts | 2 ++ code/renderers/react/src/preview.ts | 3 +++ 6 files changed, 35 insertions(+), 22 deletions(-) delete mode 100644 code/renderers/react/preview.js delete mode 100644 code/renderers/react/src/config.ts create mode 100644 code/renderers/react/src/preview-docs.ts create mode 100644 code/renderers/react/src/preview.ts diff --git a/code/renderers/react/package.json b/code/renderers/react/package.json index 0a8dad42ae80..d48d90543bcd 100644 --- a/code/renderers/react/package.json +++ b/code/renderers/react/package.json @@ -26,15 +26,9 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, - "./dist/preset": { - "types": "./dist/preset.d.ts", - "require": "./dist/preset.js" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -102,8 +96,9 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts", - "./src/preset.ts" + "./src/preset.ts", + "./src/preview.ts", + "./src/preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/react/preview.js b/code/renderers/react/preview.js deleted file mode 100644 index f00f03b4e2e4..000000000000 --- a/code/renderers/react/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config.mjs'; diff --git a/code/renderers/react/src/config.ts b/code/renderers/react/src/config.ts deleted file mode 100644 index ee07fe8687a4..000000000000 --- a/code/renderers/react/src/config.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { parameters as docsParams } from './docs/config'; - -export const parameters: {} = { renderer: 'react', ...docsParams }; - -export { decorators, argTypesEnhancers } from './docs/config'; - -export { render, renderToCanvas } from './render'; - -export { applyDecorators } from './applyDecorators'; diff --git a/code/renderers/react/src/preset.ts b/code/renderers/react/src/preset.ts index 5194fd3a23f8..2f0defa7621f 100644 --- a/code/renderers/react/src/preset.ts +++ b/code/renderers/react/src/preset.ts @@ -1,5 +1,28 @@ -import type { StorybookConfig } from '@storybook/types'; +import type { StorybookConfig, LoadedPreset } from '@storybook/types'; + +import { join } from 'path'; export const addons: StorybookConfig['addons'] = [ require.resolve('@storybook/react-dom-shim/dist/preset'), ]; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/react/src/preview-docs.ts b/code/renderers/react/src/preview-docs.ts new file mode 100644 index 000000000000..afee24665b33 --- /dev/null +++ b/code/renderers/react/src/preview-docs.ts @@ -0,0 +1,2 @@ +export { parameters } from './docs/config'; +export { decorators, argTypesEnhancers } from './docs/config'; diff --git a/code/renderers/react/src/preview.ts b/code/renderers/react/src/preview.ts new file mode 100644 index 000000000000..ba970a0519f8 --- /dev/null +++ b/code/renderers/react/src/preview.ts @@ -0,0 +1,3 @@ +export const parameters: {} = { renderer: 'react' }; +export { render, renderToCanvas } from './render'; +export { applyDecorators } from './applyDecorators'; From d77983cd3598bad42771c887d55738bad390e732 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 19:18:55 +0100 Subject: [PATCH 04/17] split the server renderer preview entrypoint into docs & non-docs parts --- code/renderers/server/package.json | 16 ++++----------- code/renderers/server/preview.js | 1 - code/renderers/server/src/preset.ts | 20 ++++++++++++++++++- .../server/src/{config.ts => preview.ts} | 0 4 files changed, 23 insertions(+), 14 deletions(-) delete mode 100644 code/renderers/server/preview.js rename code/renderers/server/src/{config.ts => preview.ts} (100%) diff --git a/code/renderers/server/package.json b/code/renderers/server/package.json index 879e51a778e6..a06e7f6108fa 100644 --- a/code/renderers/server/package.json +++ b/code/renderers/server/package.json @@ -26,16 +26,8 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, - "./preset": { - "types": "./dist/preset.d.ts", - "require": "./dist/preset.js", - "import": "./dist/preset.mjs" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -77,8 +69,8 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts", - "./src/preset.ts" + "./src/preset.ts", + "./src/preview.ts" ], "platform": "browser" }, diff --git a/code/renderers/server/preview.js b/code/renderers/server/preview.js deleted file mode 100644 index fe48d8883ba4..000000000000 --- a/code/renderers/server/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config'; diff --git a/code/renderers/server/src/preset.ts b/code/renderers/server/src/preset.ts index 63cc1aca491a..7be99c64f00a 100644 --- a/code/renderers/server/src/preset.ts +++ b/code/renderers/server/src/preset.ts @@ -1,6 +1,14 @@ import fs from 'fs-extra'; import yaml from 'yaml'; -import type { StorybookConfig, Tag, StoryName, ComponentTitle } from '@storybook/types'; +import type { + StorybookConfig, + Tag, + StoryName, + ComponentTitle, + LoadedPreset, +} from '@storybook/types'; + +import { join } from 'path'; type FileContent = { title: ComponentTitle; @@ -34,3 +42,13 @@ export const experimental_indexers: StorybookConfig['experimental_indexers'] = ( }, ...(existingIndexers || []), ]; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const result: string[] = []; + + return result.concat(input).concat([join(__dirname, 'preview.mjs')]); +}; diff --git a/code/renderers/server/src/config.ts b/code/renderers/server/src/preview.ts similarity index 100% rename from code/renderers/server/src/config.ts rename to code/renderers/server/src/preview.ts From ac33fe95414c5474bff582576b354adcdc158ff2 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 20:08:14 +0100 Subject: [PATCH 05/17] split the svelte renderer preview entrypoint into docs & non-docs parts --- code/renderers/svelte/package.json | 12 ++++++------ code/renderers/svelte/preset.js | 1 + code/renderers/svelte/preview.js | 1 - code/renderers/svelte/src/config.ts | 7 ------- code/renderers/svelte/src/preset.ts | 23 +++++++++++++++++++++++ code/renderers/svelte/src/preview-docs.ts | 3 +++ code/renderers/svelte/src/preview.ts | 4 ++++ 7 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 code/renderers/svelte/preset.js delete mode 100644 code/renderers/svelte/preview.js delete mode 100644 code/renderers/svelte/src/config.ts create mode 100644 code/renderers/svelte/src/preset.ts create mode 100644 code/renderers/svelte/src/preview-docs.ts create mode 100644 code/renderers/svelte/src/preview.ts diff --git a/code/renderers/svelte/package.json b/code/renderers/svelte/package.json index 4ad9ad3801f5..58052db43324 100644 --- a/code/renderers/svelte/package.json +++ b/code/renderers/svelte/package.json @@ -26,11 +26,9 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", "./package.json": "./package.json", "./templates/HOC.svelte": "./templates/HOC.svelte", "./templates/PreviewRender.svelte": "./templates/PreviewRender.svelte", @@ -81,7 +79,9 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts" + "./src/preset.ts", + "./src/preview.ts", + "./src/preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/svelte/preset.js b/code/renderers/svelte/preset.js new file mode 100644 index 000000000000..a83f95279e7f --- /dev/null +++ b/code/renderers/svelte/preset.js @@ -0,0 +1 @@ +module.exports = require('./dist/preset'); diff --git a/code/renderers/svelte/preview.js b/code/renderers/svelte/preview.js deleted file mode 100644 index f00f03b4e2e4..000000000000 --- a/code/renderers/svelte/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config.mjs'; diff --git a/code/renderers/svelte/src/config.ts b/code/renderers/svelte/src/config.ts deleted file mode 100644 index 78323a1ce32c..000000000000 --- a/code/renderers/svelte/src/config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { parameters as docsParams } from './docs/config'; - -export const parameters: {} = { renderer: 'svelte' as const, ...docsParams }; -export { decorators, argTypesEnhancers } from './docs/config'; - -export { render, renderToCanvas } from './render'; -export { decorateStory as applyDecorators } from './decorators'; diff --git a/code/renderers/svelte/src/preset.ts b/code/renderers/svelte/src/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/svelte/src/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/svelte/src/preview-docs.ts b/code/renderers/svelte/src/preview-docs.ts new file mode 100644 index 000000000000..71c69e9b33c6 --- /dev/null +++ b/code/renderers/svelte/src/preview-docs.ts @@ -0,0 +1,3 @@ +export { parameters } from './docs/config'; + +export { decorators, argTypesEnhancers } from './docs/config'; diff --git a/code/renderers/svelte/src/preview.ts b/code/renderers/svelte/src/preview.ts new file mode 100644 index 000000000000..4d8b883dbffe --- /dev/null +++ b/code/renderers/svelte/src/preview.ts @@ -0,0 +1,4 @@ +export const parameters: {} = { renderer: 'svelte' }; + +export { render, renderToCanvas } from './render'; +export { decorateStory as applyDecorators } from './decorators'; From 5ef2534ffa0e433b657e1f8249f44e6f1f50618d Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 20:13:46 +0100 Subject: [PATCH 06/17] split the vue renderer preview entrypoint into docs & non-docs parts --- code/renderers/vue/package.json | 12 ++++++------ code/renderers/vue/preset.ts | 23 +++++++++++++++++++++++ code/renderers/vue/preview.js | 1 - code/renderers/vue/src/config.ts | 7 ------- code/renderers/vue/src/preset.ts | 23 +++++++++++++++++++++++ code/renderers/vue/src/preview-docs.ts | 2 ++ code/renderers/vue/src/preview.ts | 3 +++ 7 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 code/renderers/vue/preset.ts delete mode 100644 code/renderers/vue/preview.js delete mode 100644 code/renderers/vue/src/config.ts create mode 100644 code/renderers/vue/src/preset.ts create mode 100644 code/renderers/vue/src/preview-docs.ts create mode 100644 code/renderers/vue/src/preview.ts diff --git a/code/renderers/vue/package.json b/code/renderers/vue/package.json index a6df7ed76983..e7c38c0a0e52 100644 --- a/code/renderers/vue/package.json +++ b/code/renderers/vue/package.json @@ -26,11 +26,9 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -83,7 +81,9 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts" + "./src/preset.ts", + "./src/preview.ts", + "./src/preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/vue/preset.ts b/code/renderers/vue/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/vue/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/vue/preview.js b/code/renderers/vue/preview.js deleted file mode 100644 index fe48d8883ba4..000000000000 --- a/code/renderers/vue/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config'; diff --git a/code/renderers/vue/src/config.ts b/code/renderers/vue/src/config.ts deleted file mode 100644 index bd9a2fb152cd..000000000000 --- a/code/renderers/vue/src/config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { parameters as docsParams } from './docs/config'; - -export const parameters: {} = { renderer: 'vue' as const, ...docsParams }; -export { decorators, argTypesEnhancers } from './docs/config'; - -export { render, renderToCanvas } from './render'; -export { decorateStory as applyDecorators } from './decorateStory'; diff --git a/code/renderers/vue/src/preset.ts b/code/renderers/vue/src/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/vue/src/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/vue/src/preview-docs.ts b/code/renderers/vue/src/preview-docs.ts new file mode 100644 index 000000000000..afee24665b33 --- /dev/null +++ b/code/renderers/vue/src/preview-docs.ts @@ -0,0 +1,2 @@ +export { parameters } from './docs/config'; +export { decorators, argTypesEnhancers } from './docs/config'; diff --git a/code/renderers/vue/src/preview.ts b/code/renderers/vue/src/preview.ts new file mode 100644 index 000000000000..2110e13bcf0c --- /dev/null +++ b/code/renderers/vue/src/preview.ts @@ -0,0 +1,3 @@ +export const parameters: {} = { renderer: 'vue' }; +export { render, renderToCanvas } from './render'; +export { decorateStory as applyDecorators } from './decorateStory'; From da42b5dce7fcea10c667e531ed4d6bd9c4e04654 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 20:41:48 +0100 Subject: [PATCH 07/17] split the vue3 renderer preview entrypoint into docs & non-docs parts --- code/renderers/vue3/package.json | 12 ++++++------ code/renderers/vue3/preset.ts | 23 +++++++++++++++++++++++ code/renderers/vue3/preview.js | 1 - code/renderers/vue3/src/config.ts | 7 ------- code/renderers/vue3/src/preset.ts | 23 +++++++++++++++++++++++ code/renderers/vue3/src/preview-docs.ts | 2 ++ code/renderers/vue3/src/preview.ts | 3 +++ 7 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 code/renderers/vue3/preset.ts delete mode 100644 code/renderers/vue3/preview.js delete mode 100644 code/renderers/vue3/src/config.ts create mode 100644 code/renderers/vue3/src/preset.ts create mode 100644 code/renderers/vue3/src/preview-docs.ts create mode 100644 code/renderers/vue3/src/preview.ts diff --git a/code/renderers/vue3/package.json b/code/renderers/vue3/package.json index f536aee0c1c1..9a5cceda4f4a 100644 --- a/code/renderers/vue3/package.json +++ b/code/renderers/vue3/package.json @@ -26,11 +26,9 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -82,7 +80,9 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts" + "./src/preset.ts", + "./src/preview.ts", + "./src/preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/vue3/preset.ts b/code/renderers/vue3/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/vue3/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/vue3/preview.js b/code/renderers/vue3/preview.js deleted file mode 100644 index f00f03b4e2e4..000000000000 --- a/code/renderers/vue3/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config.mjs'; diff --git a/code/renderers/vue3/src/config.ts b/code/renderers/vue3/src/config.ts deleted file mode 100644 index f132fb510296..000000000000 --- a/code/renderers/vue3/src/config.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { parameters as docsParams } from './docs/config'; - -export const parameters: {} = { renderer: 'vue3' as const, ...docsParams }; -export { decorators, argTypesEnhancers } from './docs/config'; - -export { render, renderToCanvas } from './render'; -export { decorateStory as applyDecorators } from './decorateStory'; diff --git a/code/renderers/vue3/src/preset.ts b/code/renderers/vue3/src/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/vue3/src/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/vue3/src/preview-docs.ts b/code/renderers/vue3/src/preview-docs.ts new file mode 100644 index 000000000000..afee24665b33 --- /dev/null +++ b/code/renderers/vue3/src/preview-docs.ts @@ -0,0 +1,2 @@ +export { parameters } from './docs/config'; +export { decorators, argTypesEnhancers } from './docs/config'; diff --git a/code/renderers/vue3/src/preview.ts b/code/renderers/vue3/src/preview.ts new file mode 100644 index 000000000000..a53fd937a5fa --- /dev/null +++ b/code/renderers/vue3/src/preview.ts @@ -0,0 +1,3 @@ +export const parameters: {} = { renderer: 'vue3' }; +export { render, renderToCanvas } from './render'; +export { decorateStory as applyDecorators } from './decorateStory'; From ea7c2429103c901fcce012285c87a2476576d0fd Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 20:43:32 +0100 Subject: [PATCH 08/17] split the web-components renderer preview entrypoint into docs & non-docs parts --- code/renderers/web-components/package.json | 12 +++++----- code/renderers/web-components/preset.js | 1 + code/renderers/web-components/preview.js | 1 - code/renderers/web-components/src/config.ts | 5 ---- code/renderers/web-components/src/preset.ts | 23 +++++++++++++++++++ .../web-components/src/preview-docs.ts | 2 ++ code/renderers/web-components/src/preview.ts | 2 ++ 7 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 code/renderers/web-components/preset.js delete mode 100644 code/renderers/web-components/preview.js delete mode 100644 code/renderers/web-components/src/config.ts create mode 100644 code/renderers/web-components/src/preset.ts create mode 100644 code/renderers/web-components/src/preview-docs.ts create mode 100644 code/renderers/web-components/src/preview.ts diff --git a/code/renderers/web-components/package.json b/code/renderers/web-components/package.json index 43a43b404127..018d8c0a78a3 100644 --- a/code/renderers/web-components/package.json +++ b/code/renderers/web-components/package.json @@ -29,11 +29,9 @@ "require": "./dist/index.js", "import": "./dist/index.mjs" }, - "./preview": { - "types": "./dist/config.d.ts", - "require": "./dist/config.js", - "import": "./dist/config.mjs" - }, + "./preset": "./preset.js", + "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -82,7 +80,9 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/config.ts" + "./src/preset.ts", + "./src/preview.ts", + "./src/preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/web-components/preset.js b/code/renderers/web-components/preset.js new file mode 100644 index 000000000000..a83f95279e7f --- /dev/null +++ b/code/renderers/web-components/preset.js @@ -0,0 +1 @@ +module.exports = require('./dist/preset'); diff --git a/code/renderers/web-components/preview.js b/code/renderers/web-components/preview.js deleted file mode 100644 index fe48d8883ba4..000000000000 --- a/code/renderers/web-components/preview.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/config'; diff --git a/code/renderers/web-components/src/config.ts b/code/renderers/web-components/src/config.ts deleted file mode 100644 index abf93dbc12f2..000000000000 --- a/code/renderers/web-components/src/config.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { parameters as docsParams } from './docs/config'; - -export const parameters: {} = { renderer: 'web-components' as const, ...docsParams }; -export { decorators, argTypesEnhancers } from './docs/config'; -export { render, renderToCanvas } from './render'; diff --git a/code/renderers/web-components/src/preset.ts b/code/renderers/web-components/src/preset.ts new file mode 100644 index 000000000000..f5fab9828623 --- /dev/null +++ b/code/renderers/web-components/src/preset.ts @@ -0,0 +1,23 @@ +import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import { join } from 'path'; + +const hasDocs = (presetsList: LoadedPreset[]) => { + return presetsList.some((preset: string | { name: string }) => { + const presetName = typeof preset === 'string' ? preset : preset.name; + return presetName.includes('@storybook/addon-docs'); + }); +}; + +export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { + const { presetsList } = options; + if (!presetsList) { + return input; + } + const docsInList = hasDocs(presetsList); + const result: string[] = []; + + return result + .concat(input) + .concat([join(__dirname, 'preview.mjs')]) + .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); +}; diff --git a/code/renderers/web-components/src/preview-docs.ts b/code/renderers/web-components/src/preview-docs.ts new file mode 100644 index 000000000000..afee24665b33 --- /dev/null +++ b/code/renderers/web-components/src/preview-docs.ts @@ -0,0 +1,2 @@ +export { parameters } from './docs/config'; +export { decorators, argTypesEnhancers } from './docs/config'; diff --git a/code/renderers/web-components/src/preview.ts b/code/renderers/web-components/src/preview.ts new file mode 100644 index 000000000000..c0a759dcab8a --- /dev/null +++ b/code/renderers/web-components/src/preview.ts @@ -0,0 +1,2 @@ +export const parameters: {} = { renderer: 'web-components' }; +export { render, renderToCanvas } from './render'; From 5aaf56e0dfe1fc3075e8981ba7b93f82cbd0c441 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 30 Oct 2023 21:27:45 +0100 Subject: [PATCH 09/17] cleanup --- code/renderers/server/src/preset.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/code/renderers/server/src/preset.ts b/code/renderers/server/src/preset.ts index 7be99c64f00a..64b414320f06 100644 --- a/code/renderers/server/src/preset.ts +++ b/code/renderers/server/src/preset.ts @@ -1,12 +1,6 @@ import fs from 'fs-extra'; import yaml from 'yaml'; -import type { - StorybookConfig, - Tag, - StoryName, - ComponentTitle, - LoadedPreset, -} from '@storybook/types'; +import type { StorybookConfig, Tag, StoryName, ComponentTitle } from '@storybook/types'; import { join } from 'path'; From 02f9b36cd79b1ac77fb4b37f3752ee094e5a6d00 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 31 Oct 2023 10:01:46 +0100 Subject: [PATCH 10/17] change mechanism for detecting addon docs being active --- code/renderers/html/src/preset.ts | 17 +++-------------- code/renderers/preact/src/preset.ts | 17 +++-------------- code/renderers/react/src/preset.ts | 17 +++-------------- code/renderers/svelte/src/preset.ts | 17 +++-------------- code/renderers/vue/preset.ts | 17 +++-------------- code/renderers/vue/src/preset.ts | 17 +++-------------- code/renderers/vue3/preset.ts | 17 +++-------------- code/renderers/vue3/src/preset.ts | 17 +++-------------- code/renderers/web-components/src/preset.ts | 17 +++-------------- 9 files changed, 27 insertions(+), 126 deletions(-) diff --git a/code/renderers/html/src/preset.ts b/code/renderers/html/src/preset.ts index f5fab9828623..7cb30b002039 100644 --- a/code/renderers/html/src/preset.ts +++ b/code/renderers/html/src/preset.ts @@ -1,23 +1,12 @@ -import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; diff --git a/code/renderers/preact/src/preset.ts b/code/renderers/preact/src/preset.ts index f5fab9828623..7cb30b002039 100644 --- a/code/renderers/preact/src/preset.ts +++ b/code/renderers/preact/src/preset.ts @@ -1,23 +1,12 @@ -import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; diff --git a/code/renderers/react/src/preset.ts b/code/renderers/react/src/preset.ts index 2f0defa7621f..815c170cf1c2 100644 --- a/code/renderers/react/src/preset.ts +++ b/code/renderers/react/src/preset.ts @@ -1,4 +1,4 @@ -import type { StorybookConfig, LoadedPreset } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; @@ -6,23 +6,12 @@ export const addons: StorybookConfig['addons'] = [ require.resolve('@storybook/react-dom-shim/dist/preset'), ]; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; diff --git a/code/renderers/svelte/src/preset.ts b/code/renderers/svelte/src/preset.ts index f5fab9828623..7cb30b002039 100644 --- a/code/renderers/svelte/src/preset.ts +++ b/code/renderers/svelte/src/preset.ts @@ -1,23 +1,12 @@ -import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; diff --git a/code/renderers/vue/preset.ts b/code/renderers/vue/preset.ts index f5fab9828623..7cb30b002039 100644 --- a/code/renderers/vue/preset.ts +++ b/code/renderers/vue/preset.ts @@ -1,23 +1,12 @@ -import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; diff --git a/code/renderers/vue/src/preset.ts b/code/renderers/vue/src/preset.ts index f5fab9828623..7cb30b002039 100644 --- a/code/renderers/vue/src/preset.ts +++ b/code/renderers/vue/src/preset.ts @@ -1,23 +1,12 @@ -import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; diff --git a/code/renderers/vue3/preset.ts b/code/renderers/vue3/preset.ts index f5fab9828623..7cb30b002039 100644 --- a/code/renderers/vue3/preset.ts +++ b/code/renderers/vue3/preset.ts @@ -1,23 +1,12 @@ -import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; diff --git a/code/renderers/vue3/src/preset.ts b/code/renderers/vue3/src/preset.ts index f5fab9828623..7cb30b002039 100644 --- a/code/renderers/vue3/src/preset.ts +++ b/code/renderers/vue3/src/preset.ts @@ -1,23 +1,12 @@ -import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; diff --git a/code/renderers/web-components/src/preset.ts b/code/renderers/web-components/src/preset.ts index f5fab9828623..7cb30b002039 100644 --- a/code/renderers/web-components/src/preset.ts +++ b/code/renderers/web-components/src/preset.ts @@ -1,23 +1,12 @@ -import type { LoadedPreset, StorybookConfig } from '@storybook/types'; +import type { StorybookConfig } from '@storybook/types'; import { join } from 'path'; -const hasDocs = (presetsList: LoadedPreset[]) => { - return presetsList.some((preset: string | { name: string }) => { - const presetName = typeof preset === 'string' ? preset : preset.name; - return presetName.includes('@storybook/addon-docs'); - }); -}; - export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const { presetsList } = options; - if (!presetsList) { - return input; - } - const docsInList = hasDocs(presetsList); + const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; const result: string[] = []; return result .concat(input) .concat([join(__dirname, 'preview.mjs')]) - .concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); }; From 518d6436812ea248cb6795ea1e73f923bd6e23e5 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 31 Oct 2023 11:13:32 +0100 Subject: [PATCH 11/17] corrections --- code/renderers/vue/preset.js | 1 + code/renderers/vue/preset.ts | 12 ------------ code/renderers/vue3/preset.js | 1 + code/renderers/vue3/preset.ts | 12 ------------ 4 files changed, 2 insertions(+), 24 deletions(-) create mode 100644 code/renderers/vue/preset.js delete mode 100644 code/renderers/vue/preset.ts create mode 100644 code/renderers/vue3/preset.js delete mode 100644 code/renderers/vue3/preset.ts diff --git a/code/renderers/vue/preset.js b/code/renderers/vue/preset.js new file mode 100644 index 000000000000..a83f95279e7f --- /dev/null +++ b/code/renderers/vue/preset.js @@ -0,0 +1 @@ +module.exports = require('./dist/preset'); diff --git a/code/renderers/vue/preset.ts b/code/renderers/vue/preset.ts deleted file mode 100644 index 7cb30b002039..000000000000 --- a/code/renderers/vue/preset.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { StorybookConfig } from '@storybook/types'; -import { join } from 'path'; - -export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; - const result: string[] = []; - - return result - .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); -}; diff --git a/code/renderers/vue3/preset.js b/code/renderers/vue3/preset.js new file mode 100644 index 000000000000..a83f95279e7f --- /dev/null +++ b/code/renderers/vue3/preset.js @@ -0,0 +1 @@ +module.exports = require('./dist/preset'); diff --git a/code/renderers/vue3/preset.ts b/code/renderers/vue3/preset.ts deleted file mode 100644 index 7cb30b002039..000000000000 --- a/code/renderers/vue3/preset.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { StorybookConfig } from '@storybook/types'; -import { join } from 'path'; - -export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; - const result: string[] = []; - - return result - .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); -}; From 0d9b58a31021e699e9d36ebe3a9704388a7ef475 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 31 Oct 2023 16:48:38 +0100 Subject: [PATCH 12/17] do not edit docs config is --docs isn't set --- code/lib/core-server/src/presets/common-preset.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/lib/core-server/src/presets/common-preset.ts b/code/lib/core-server/src/presets/common-preset.ts index 39511aef6be4..8d2ac3b7e2d4 100644 --- a/code/lib/core-server/src/presets/common-preset.ts +++ b/code/lib/core-server/src/presets/common-preset.ts @@ -225,10 +225,13 @@ export const frameworkOptions = async ( export const docs = ( docsOptions: StorybookConfig['docs'], { docs: docsMode }: CLIOptions -): StorybookConfig['docs'] => ({ - ...docsOptions, - docsMode, -}); +): StorybookConfig['docs'] => + docsOptions && docsMode !== undefined + ? { + ...docsOptions, + docsMode, + } + : docsOptions; export const managerHead = async (_: any, options: Options) => { const location = join(options.configDir, 'manager-head.html'); From 09778c8b9a779f6078f80c81584860a191a79139 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 31 Oct 2023 16:49:02 +0100 Subject: [PATCH 13/17] optimize a story do it does not pull in the entire lodash universe --- code/lib/preview-api/template/stories/args.stories.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/lib/preview-api/template/stories/args.stories.ts b/code/lib/preview-api/template/stories/args.stories.ts index aa9719c4bf2c..6d397e108c5c 100644 --- a/code/lib/preview-api/template/stories/args.stories.ts +++ b/code/lib/preview-api/template/stories/args.stories.ts @@ -2,7 +2,7 @@ import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types'; import { within } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; -import { pick } from 'lodash'; +import pick from 'lodash/pick'; import { STORY_ARGS_UPDATED, UPDATE_STORY_ARGS, RESET_STORY_ARGS } from '@storybook/core-events'; export default { From 54cb15a27e32ac425bf5eed5b656f77e54618be0 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 31 Oct 2023 16:49:34 +0100 Subject: [PATCH 14/17] rename preview (previously config) to entry-preview, for easier identification --- code/renderers/html/package.json | 8 ++++---- .../renderers/html/src/{preview-docs.ts => entry-docs.ts} | 0 code/renderers/html/src/{preview.ts => entry-preview.ts} | 0 code/renderers/html/src/preset.ts | 4 ++-- code/renderers/preact/package.json | 8 ++++---- .../preact/src/{preview-docs.ts => entry-docs.ts} | 0 .../renderers/preact/src/{preview.ts => entry-preview.ts} | 0 code/renderers/preact/src/preset.ts | 4 ++-- code/renderers/react/package.json | 8 ++++---- .../src/preview-docs.ts => react/src/entry-docs.ts} | 1 + code/renderers/react/src/{preview.ts => entry-preview.ts} | 1 - code/renderers/react/src/preset.ts | 7 ++++--- code/renderers/server/package.json | 4 ++-- .../renderers/server/src/{preview.ts => entry-preview.ts} | 0 code/renderers/server/src/preset.ts | 2 +- code/renderers/svelte/package.json | 8 ++++---- .../svelte/src/{preview-docs.ts => entry-docs.ts} | 0 .../renderers/svelte/src/{preview.ts => entry-preview.ts} | 0 code/renderers/svelte/src/preset.ts | 4 ++-- code/renderers/vue/package.json | 8 ++++---- .../{react/src/preview-docs.ts => vue/src/entry-docs.ts} | 0 code/renderers/vue/src/{preview.ts => entry-preview.ts} | 0 code/renderers/vue/src/preset.ts | 4 ++-- code/renderers/vue3/package.json | 8 ++++---- .../{vue/src/preview-docs.ts => vue3/src/entry-docs.ts} | 0 code/renderers/vue3/src/{preview.ts => entry-preview.ts} | 0 code/renderers/vue3/src/preset.ts | 4 ++-- code/renderers/web-components/package.json | 8 ++++---- .../preview-docs.ts => web-components/src/entry-docs.ts} | 0 .../web-components/src/{preview.ts => entry-preview.ts} | 0 code/renderers/web-components/src/preset.ts | 4 ++-- 31 files changed, 48 insertions(+), 47 deletions(-) rename code/renderers/html/src/{preview-docs.ts => entry-docs.ts} (100%) rename code/renderers/html/src/{preview.ts => entry-preview.ts} (100%) rename code/renderers/preact/src/{preview-docs.ts => entry-docs.ts} (100%) rename code/renderers/preact/src/{preview.ts => entry-preview.ts} (100%) rename code/renderers/{web-components/src/preview-docs.ts => react/src/entry-docs.ts} (66%) rename code/renderers/react/src/{preview.ts => entry-preview.ts} (66%) rename code/renderers/server/src/{preview.ts => entry-preview.ts} (100%) rename code/renderers/svelte/src/{preview-docs.ts => entry-docs.ts} (100%) rename code/renderers/svelte/src/{preview.ts => entry-preview.ts} (100%) rename code/renderers/{react/src/preview-docs.ts => vue/src/entry-docs.ts} (100%) rename code/renderers/vue/src/{preview.ts => entry-preview.ts} (100%) rename code/renderers/{vue/src/preview-docs.ts => vue3/src/entry-docs.ts} (100%) rename code/renderers/vue3/src/{preview.ts => entry-preview.ts} (100%) rename code/renderers/{vue3/src/preview-docs.ts => web-components/src/entry-docs.ts} (100%) rename code/renderers/web-components/src/{preview.ts => entry-preview.ts} (100%) diff --git a/code/renderers/html/package.json b/code/renderers/html/package.json index e9827cca4af5..bf3f6a550daa 100644 --- a/code/renderers/html/package.json +++ b/code/renderers/html/package.json @@ -27,8 +27,8 @@ "import": "./dist/index.mjs" }, "./preset": "./preset.js", - "./dist/preview.mjs": "./dist/preview.mjs", - "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", + "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", + "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -70,8 +70,8 @@ "entries": [ "./src/index.ts", "./src/preset.ts", - "./src/preview.ts", - "./src/preview-docs.ts" + "./src/entry-preview.ts", + "./src/entry-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/html/src/preview-docs.ts b/code/renderers/html/src/entry-docs.ts similarity index 100% rename from code/renderers/html/src/preview-docs.ts rename to code/renderers/html/src/entry-docs.ts diff --git a/code/renderers/html/src/preview.ts b/code/renderers/html/src/entry-preview.ts similarity index 100% rename from code/renderers/html/src/preview.ts rename to code/renderers/html/src/entry-preview.ts diff --git a/code/renderers/html/src/preset.ts b/code/renderers/html/src/preset.ts index 7cb30b002039..2812abde9a23 100644 --- a/code/renderers/html/src/preset.ts +++ b/code/renderers/html/src/preset.ts @@ -7,6 +7,6 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat([join(__dirname, 'entry-preview.mjs')]) + .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); }; diff --git a/code/renderers/preact/package.json b/code/renderers/preact/package.json index ea5cb88809d7..edd0c5eaedf5 100644 --- a/code/renderers/preact/package.json +++ b/code/renderers/preact/package.json @@ -27,8 +27,8 @@ "import": "./dist/index.mjs" }, "./preset": "./preset.js", - "./dist/preview.mjs": "./dist/preview.mjs", - "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", + "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", + "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -70,8 +70,8 @@ "entries": [ "./src/index.ts", "./src/preset.ts", - "./src/preview.ts", - "./src/preview-docs.ts" + "./src/entry-preview.ts", + "./src/entry-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/preact/src/preview-docs.ts b/code/renderers/preact/src/entry-docs.ts similarity index 100% rename from code/renderers/preact/src/preview-docs.ts rename to code/renderers/preact/src/entry-docs.ts diff --git a/code/renderers/preact/src/preview.ts b/code/renderers/preact/src/entry-preview.ts similarity index 100% rename from code/renderers/preact/src/preview.ts rename to code/renderers/preact/src/entry-preview.ts diff --git a/code/renderers/preact/src/preset.ts b/code/renderers/preact/src/preset.ts index 7cb30b002039..2812abde9a23 100644 --- a/code/renderers/preact/src/preset.ts +++ b/code/renderers/preact/src/preset.ts @@ -7,6 +7,6 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat([join(__dirname, 'entry-preview.mjs')]) + .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); }; diff --git a/code/renderers/react/package.json b/code/renderers/react/package.json index d48d90543bcd..51bf2b42c3a1 100644 --- a/code/renderers/react/package.json +++ b/code/renderers/react/package.json @@ -27,8 +27,8 @@ "import": "./dist/index.mjs" }, "./preset": "./preset.js", - "./dist/preview.mjs": "./dist/preview.mjs", - "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", + "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", + "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -97,8 +97,8 @@ "entries": [ "./src/index.ts", "./src/preset.ts", - "./src/preview.ts", - "./src/preview-docs.ts" + "./src/entry-preview.ts", + "./src/entry-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/web-components/src/preview-docs.ts b/code/renderers/react/src/entry-docs.ts similarity index 66% rename from code/renderers/web-components/src/preview-docs.ts rename to code/renderers/react/src/entry-docs.ts index afee24665b33..4bd3f83d3465 100644 --- a/code/renderers/web-components/src/preview-docs.ts +++ b/code/renderers/react/src/entry-docs.ts @@ -1,2 +1,3 @@ export { parameters } from './docs/config'; export { decorators, argTypesEnhancers } from './docs/config'; +export { applyDecorators } from './applyDecorators'; diff --git a/code/renderers/react/src/preview.ts b/code/renderers/react/src/entry-preview.ts similarity index 66% rename from code/renderers/react/src/preview.ts rename to code/renderers/react/src/entry-preview.ts index ba970a0519f8..fe96bc623da7 100644 --- a/code/renderers/react/src/preview.ts +++ b/code/renderers/react/src/entry-preview.ts @@ -1,3 +1,2 @@ export const parameters: {} = { renderer: 'react' }; export { render, renderToCanvas } from './render'; -export { applyDecorators } from './applyDecorators'; diff --git a/code/renderers/react/src/preset.ts b/code/renderers/react/src/preset.ts index 815c170cf1c2..78648a0be01e 100644 --- a/code/renderers/react/src/preset.ts +++ b/code/renderers/react/src/preset.ts @@ -7,11 +7,12 @@ export const addons: StorybookConfig['addons'] = [ ]; export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => { - const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0; + const docsConfig = await options.presets.apply('docs', {}, options); + const docsEnabled = Object.keys(docsConfig).length > 0; const result: string[] = []; return result .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat([join(__dirname, 'entry-preview.mjs')]) + .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); }; diff --git a/code/renderers/server/package.json b/code/renderers/server/package.json index a06e7f6108fa..47d9cced041e 100644 --- a/code/renderers/server/package.json +++ b/code/renderers/server/package.json @@ -27,7 +27,7 @@ "import": "./dist/index.mjs" }, "./preset": "./preset.js", - "./dist/preview.mjs": "./dist/preview.mjs", + "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -70,7 +70,7 @@ "entries": [ "./src/index.ts", "./src/preset.ts", - "./src/preview.ts" + "./src/entry-preview.ts" ], "platform": "browser" }, diff --git a/code/renderers/server/src/preview.ts b/code/renderers/server/src/entry-preview.ts similarity index 100% rename from code/renderers/server/src/preview.ts rename to code/renderers/server/src/entry-preview.ts diff --git a/code/renderers/server/src/preset.ts b/code/renderers/server/src/preset.ts index 64b414320f06..01039ebfb980 100644 --- a/code/renderers/server/src/preset.ts +++ b/code/renderers/server/src/preset.ts @@ -44,5 +44,5 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( } const result: string[] = []; - return result.concat(input).concat([join(__dirname, 'preview.mjs')]); + return result.concat(input).concat([join(__dirname, 'entry-preview.mjs')]); }; diff --git a/code/renderers/svelte/package.json b/code/renderers/svelte/package.json index 58052db43324..476410dba5cf 100644 --- a/code/renderers/svelte/package.json +++ b/code/renderers/svelte/package.json @@ -27,8 +27,8 @@ "import": "./dist/index.mjs" }, "./preset": "./preset.js", - "./dist/preview.mjs": "./dist/preview.mjs", - "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", + "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", + "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", "./package.json": "./package.json", "./templates/HOC.svelte": "./templates/HOC.svelte", "./templates/PreviewRender.svelte": "./templates/PreviewRender.svelte", @@ -80,8 +80,8 @@ "entries": [ "./src/index.ts", "./src/preset.ts", - "./src/preview.ts", - "./src/preview-docs.ts" + "./src/entry-preview.ts", + "./src/entry-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/svelte/src/preview-docs.ts b/code/renderers/svelte/src/entry-docs.ts similarity index 100% rename from code/renderers/svelte/src/preview-docs.ts rename to code/renderers/svelte/src/entry-docs.ts diff --git a/code/renderers/svelte/src/preview.ts b/code/renderers/svelte/src/entry-preview.ts similarity index 100% rename from code/renderers/svelte/src/preview.ts rename to code/renderers/svelte/src/entry-preview.ts diff --git a/code/renderers/svelte/src/preset.ts b/code/renderers/svelte/src/preset.ts index 7cb30b002039..2812abde9a23 100644 --- a/code/renderers/svelte/src/preset.ts +++ b/code/renderers/svelte/src/preset.ts @@ -7,6 +7,6 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat([join(__dirname, 'entry-preview.mjs')]) + .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); }; diff --git a/code/renderers/vue/package.json b/code/renderers/vue/package.json index e7c38c0a0e52..1e45ec9831c6 100644 --- a/code/renderers/vue/package.json +++ b/code/renderers/vue/package.json @@ -27,8 +27,8 @@ "import": "./dist/index.mjs" }, "./preset": "./preset.js", - "./dist/preview.mjs": "./dist/preview.mjs", - "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", + "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", + "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -82,8 +82,8 @@ "entries": [ "./src/index.ts", "./src/preset.ts", - "./src/preview.ts", - "./src/preview-docs.ts" + "./src/entry-preview.ts", + "./src/entry-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/react/src/preview-docs.ts b/code/renderers/vue/src/entry-docs.ts similarity index 100% rename from code/renderers/react/src/preview-docs.ts rename to code/renderers/vue/src/entry-docs.ts diff --git a/code/renderers/vue/src/preview.ts b/code/renderers/vue/src/entry-preview.ts similarity index 100% rename from code/renderers/vue/src/preview.ts rename to code/renderers/vue/src/entry-preview.ts diff --git a/code/renderers/vue/src/preset.ts b/code/renderers/vue/src/preset.ts index 7cb30b002039..2812abde9a23 100644 --- a/code/renderers/vue/src/preset.ts +++ b/code/renderers/vue/src/preset.ts @@ -7,6 +7,6 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat([join(__dirname, 'entry-preview.mjs')]) + .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); }; diff --git a/code/renderers/vue3/package.json b/code/renderers/vue3/package.json index 9a5cceda4f4a..2583c5dcb2f0 100644 --- a/code/renderers/vue3/package.json +++ b/code/renderers/vue3/package.json @@ -27,8 +27,8 @@ "import": "./dist/index.mjs" }, "./preset": "./preset.js", - "./dist/preview.mjs": "./dist/preview.mjs", - "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", + "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", + "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -81,8 +81,8 @@ "entries": [ "./src/index.ts", "./src/preset.ts", - "./src/preview.ts", - "./src/preview-docs.ts" + "./src/entry-preview.ts", + "./src/entry-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/vue/src/preview-docs.ts b/code/renderers/vue3/src/entry-docs.ts similarity index 100% rename from code/renderers/vue/src/preview-docs.ts rename to code/renderers/vue3/src/entry-docs.ts diff --git a/code/renderers/vue3/src/preview.ts b/code/renderers/vue3/src/entry-preview.ts similarity index 100% rename from code/renderers/vue3/src/preview.ts rename to code/renderers/vue3/src/entry-preview.ts diff --git a/code/renderers/vue3/src/preset.ts b/code/renderers/vue3/src/preset.ts index 7cb30b002039..2812abde9a23 100644 --- a/code/renderers/vue3/src/preset.ts +++ b/code/renderers/vue3/src/preset.ts @@ -7,6 +7,6 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat([join(__dirname, 'entry-preview.mjs')]) + .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); }; diff --git a/code/renderers/web-components/package.json b/code/renderers/web-components/package.json index 018d8c0a78a3..db4ab8fce660 100644 --- a/code/renderers/web-components/package.json +++ b/code/renderers/web-components/package.json @@ -30,8 +30,8 @@ "import": "./dist/index.mjs" }, "./preset": "./preset.js", - "./dist/preview.mjs": "./dist/preview.mjs", - "./dist/preview-docs.mjs": "./dist/preview-docs.mjs", + "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", + "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -81,8 +81,8 @@ "entries": [ "./src/index.ts", "./src/preset.ts", - "./src/preview.ts", - "./src/preview-docs.ts" + "./src/entry-preview.ts", + "./src/entry-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/vue3/src/preview-docs.ts b/code/renderers/web-components/src/entry-docs.ts similarity index 100% rename from code/renderers/vue3/src/preview-docs.ts rename to code/renderers/web-components/src/entry-docs.ts diff --git a/code/renderers/web-components/src/preview.ts b/code/renderers/web-components/src/entry-preview.ts similarity index 100% rename from code/renderers/web-components/src/preview.ts rename to code/renderers/web-components/src/entry-preview.ts diff --git a/code/renderers/web-components/src/preset.ts b/code/renderers/web-components/src/preset.ts index 7cb30b002039..2812abde9a23 100644 --- a/code/renderers/web-components/src/preset.ts +++ b/code/renderers/web-components/src/preset.ts @@ -7,6 +7,6 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) - .concat([join(__dirname, 'preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []); + .concat([join(__dirname, 'entry-preview.mjs')]) + .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); }; From 10b1e55537637e27890f7023579f14f5d2b75d0a Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 1 Nov 2023 09:05:20 +0100 Subject: [PATCH 15/17] rename preview docs entrypoint --- code/renderers/html/package.json | 4 ++-- .../html/src/{entry-docs.ts => entry-preview-docs.ts} | 0 code/renderers/html/src/preset.ts | 2 +- code/renderers/preact/package.json | 4 ++-- .../preact/src/{entry-docs.ts => entry-preview-docs.ts} | 0 code/renderers/preact/src/preset.ts | 2 +- code/renderers/react/package.json | 4 ++-- .../react/src/{entry-docs.ts => entry-preview-docs.ts} | 0 code/renderers/react/src/preset.ts | 2 +- code/renderers/svelte/package.json | 4 ++-- .../svelte/src/{entry-docs.ts => entry-preview-docs.ts} | 0 code/renderers/svelte/src/preset.ts | 2 +- code/renderers/vue/package.json | 4 ++-- .../vue/src/{entry-docs.ts => entry-preview-docs.ts} | 0 code/renderers/vue/src/preset.ts | 2 +- code/renderers/vue3/package.json | 4 ++-- .../vue3/src/{entry-docs.ts => entry-preview-docs.ts} | 0 code/renderers/vue3/src/preset.ts | 2 +- code/renderers/web-components/package.json | 4 ++-- .../src/{entry-docs.ts => entry-preview-docs.ts} | 0 code/renderers/web-components/src/preset.ts | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) rename code/renderers/html/src/{entry-docs.ts => entry-preview-docs.ts} (100%) rename code/renderers/preact/src/{entry-docs.ts => entry-preview-docs.ts} (100%) rename code/renderers/react/src/{entry-docs.ts => entry-preview-docs.ts} (100%) rename code/renderers/svelte/src/{entry-docs.ts => entry-preview-docs.ts} (100%) rename code/renderers/vue/src/{entry-docs.ts => entry-preview-docs.ts} (100%) rename code/renderers/vue3/src/{entry-docs.ts => entry-preview-docs.ts} (100%) rename code/renderers/web-components/src/{entry-docs.ts => entry-preview-docs.ts} (100%) diff --git a/code/renderers/html/package.json b/code/renderers/html/package.json index bf3f6a550daa..9dec7bb0745e 100644 --- a/code/renderers/html/package.json +++ b/code/renderers/html/package.json @@ -28,7 +28,7 @@ }, "./preset": "./preset.js", "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", - "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", + "./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -71,7 +71,7 @@ "./src/index.ts", "./src/preset.ts", "./src/entry-preview.ts", - "./src/entry-docs.ts" + "./src/entry-preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/html/src/entry-docs.ts b/code/renderers/html/src/entry-preview-docs.ts similarity index 100% rename from code/renderers/html/src/entry-docs.ts rename to code/renderers/html/src/entry-preview-docs.ts diff --git a/code/renderers/html/src/preset.ts b/code/renderers/html/src/preset.ts index 2812abde9a23..b60ba9208510 100644 --- a/code/renderers/html/src/preset.ts +++ b/code/renderers/html/src/preset.ts @@ -8,5 +8,5 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) .concat([join(__dirname, 'entry-preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []); }; diff --git a/code/renderers/preact/package.json b/code/renderers/preact/package.json index edd0c5eaedf5..9d5330d468eb 100644 --- a/code/renderers/preact/package.json +++ b/code/renderers/preact/package.json @@ -28,7 +28,7 @@ }, "./preset": "./preset.js", "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", - "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", + "./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -71,7 +71,7 @@ "./src/index.ts", "./src/preset.ts", "./src/entry-preview.ts", - "./src/entry-docs.ts" + "./src/entry-preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/preact/src/entry-docs.ts b/code/renderers/preact/src/entry-preview-docs.ts similarity index 100% rename from code/renderers/preact/src/entry-docs.ts rename to code/renderers/preact/src/entry-preview-docs.ts diff --git a/code/renderers/preact/src/preset.ts b/code/renderers/preact/src/preset.ts index 2812abde9a23..b60ba9208510 100644 --- a/code/renderers/preact/src/preset.ts +++ b/code/renderers/preact/src/preset.ts @@ -8,5 +8,5 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) .concat([join(__dirname, 'entry-preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []); }; diff --git a/code/renderers/react/package.json b/code/renderers/react/package.json index 51bf2b42c3a1..08c29dd01229 100644 --- a/code/renderers/react/package.json +++ b/code/renderers/react/package.json @@ -28,7 +28,7 @@ }, "./preset": "./preset.js", "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", - "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", + "./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -98,7 +98,7 @@ "./src/index.ts", "./src/preset.ts", "./src/entry-preview.ts", - "./src/entry-docs.ts" + "./src/entry-preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/react/src/entry-docs.ts b/code/renderers/react/src/entry-preview-docs.ts similarity index 100% rename from code/renderers/react/src/entry-docs.ts rename to code/renderers/react/src/entry-preview-docs.ts diff --git a/code/renderers/react/src/preset.ts b/code/renderers/react/src/preset.ts index 78648a0be01e..6da62d30bbf2 100644 --- a/code/renderers/react/src/preset.ts +++ b/code/renderers/react/src/preset.ts @@ -14,5 +14,5 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) .concat([join(__dirname, 'entry-preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []); }; diff --git a/code/renderers/svelte/package.json b/code/renderers/svelte/package.json index 476410dba5cf..99a84af9c552 100644 --- a/code/renderers/svelte/package.json +++ b/code/renderers/svelte/package.json @@ -28,7 +28,7 @@ }, "./preset": "./preset.js", "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", - "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", + "./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs", "./package.json": "./package.json", "./templates/HOC.svelte": "./templates/HOC.svelte", "./templates/PreviewRender.svelte": "./templates/PreviewRender.svelte", @@ -81,7 +81,7 @@ "./src/index.ts", "./src/preset.ts", "./src/entry-preview.ts", - "./src/entry-docs.ts" + "./src/entry-preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/svelte/src/entry-docs.ts b/code/renderers/svelte/src/entry-preview-docs.ts similarity index 100% rename from code/renderers/svelte/src/entry-docs.ts rename to code/renderers/svelte/src/entry-preview-docs.ts diff --git a/code/renderers/svelte/src/preset.ts b/code/renderers/svelte/src/preset.ts index 2812abde9a23..b60ba9208510 100644 --- a/code/renderers/svelte/src/preset.ts +++ b/code/renderers/svelte/src/preset.ts @@ -8,5 +8,5 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) .concat([join(__dirname, 'entry-preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []); }; diff --git a/code/renderers/vue/package.json b/code/renderers/vue/package.json index 1e45ec9831c6..e9b16f82f4ae 100644 --- a/code/renderers/vue/package.json +++ b/code/renderers/vue/package.json @@ -28,7 +28,7 @@ }, "./preset": "./preset.js", "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", - "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", + "./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -83,7 +83,7 @@ "./src/index.ts", "./src/preset.ts", "./src/entry-preview.ts", - "./src/entry-docs.ts" + "./src/entry-preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/vue/src/entry-docs.ts b/code/renderers/vue/src/entry-preview-docs.ts similarity index 100% rename from code/renderers/vue/src/entry-docs.ts rename to code/renderers/vue/src/entry-preview-docs.ts diff --git a/code/renderers/vue/src/preset.ts b/code/renderers/vue/src/preset.ts index 2812abde9a23..b60ba9208510 100644 --- a/code/renderers/vue/src/preset.ts +++ b/code/renderers/vue/src/preset.ts @@ -8,5 +8,5 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) .concat([join(__dirname, 'entry-preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []); }; diff --git a/code/renderers/vue3/package.json b/code/renderers/vue3/package.json index 2583c5dcb2f0..3ea92f413b5f 100644 --- a/code/renderers/vue3/package.json +++ b/code/renderers/vue3/package.json @@ -28,7 +28,7 @@ }, "./preset": "./preset.js", "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", - "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", + "./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -82,7 +82,7 @@ "./src/index.ts", "./src/preset.ts", "./src/entry-preview.ts", - "./src/entry-docs.ts" + "./src/entry-preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/vue3/src/entry-docs.ts b/code/renderers/vue3/src/entry-preview-docs.ts similarity index 100% rename from code/renderers/vue3/src/entry-docs.ts rename to code/renderers/vue3/src/entry-preview-docs.ts diff --git a/code/renderers/vue3/src/preset.ts b/code/renderers/vue3/src/preset.ts index 2812abde9a23..b60ba9208510 100644 --- a/code/renderers/vue3/src/preset.ts +++ b/code/renderers/vue3/src/preset.ts @@ -8,5 +8,5 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) .concat([join(__dirname, 'entry-preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []); }; diff --git a/code/renderers/web-components/package.json b/code/renderers/web-components/package.json index db4ab8fce660..6ac0d96131dd 100644 --- a/code/renderers/web-components/package.json +++ b/code/renderers/web-components/package.json @@ -31,7 +31,7 @@ }, "./preset": "./preset.js", "./dist/entry-preview.mjs": "./dist/entry-preview.mjs", - "./dist/entry-docs.mjs": "./dist/entry-docs.mjs", + "./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs", "./package.json": "./package.json" }, "main": "dist/index.js", @@ -82,7 +82,7 @@ "./src/index.ts", "./src/preset.ts", "./src/entry-preview.ts", - "./src/entry-docs.ts" + "./src/entry-preview-docs.ts" ], "platform": "browser" }, diff --git a/code/renderers/web-components/src/entry-docs.ts b/code/renderers/web-components/src/entry-preview-docs.ts similarity index 100% rename from code/renderers/web-components/src/entry-docs.ts rename to code/renderers/web-components/src/entry-preview-docs.ts diff --git a/code/renderers/web-components/src/preset.ts b/code/renderers/web-components/src/preset.ts index 2812abde9a23..b60ba9208510 100644 --- a/code/renderers/web-components/src/preset.ts +++ b/code/renderers/web-components/src/preset.ts @@ -8,5 +8,5 @@ export const previewAnnotations: StorybookConfig['previewAnnotations'] = async ( return result .concat(input) .concat([join(__dirname, 'entry-preview.mjs')]) - .concat(docsEnabled ? [join(__dirname, 'entry-docs.mjs')] : []); + .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []); }; From cb03069173260a6dbe1d7d59add5ddd35394d0ff Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 1 Nov 2023 09:05:33 +0100 Subject: [PATCH 16/17] cleanup --- code/renderers/html/src/docs/config.ts | 23 ------------------- .../html/src/docs/sourceDecorator.ts | 10 ++++---- code/renderers/html/src/entry-preview-docs.ts | 23 +++++++++++++++++-- code/renderers/preact/src/docs/config.ts | 5 ---- .../preact/src/entry-preview-docs.ts | 6 ++++- .../react/src/{ => docs}/applyDecorators.ts | 4 ++-- code/renderers/react/src/docs/config.ts | 18 --------------- .../renderers/react/src/entry-preview-docs.ts | 23 ++++++++++++++++--- code/renderers/svelte/src/docs/config.ts | 17 -------------- .../svelte/src/docs/sourceDecorator.ts | 9 ++++---- .../svelte/src/entry-preview-docs.ts | 19 +++++++++++++-- code/renderers/vue/src/docs/config.ts | 16 ------------- code/renderers/vue/src/entry-preview-docs.ts | 19 +++++++++++++-- code/renderers/vue3/src/docs/config.ts | 16 ------------- .../vue3/src/docs/sourceDecorator.ts | 9 ++++---- code/renderers/vue3/src/entry-preview-docs.ts | 19 +++++++++++++-- .../web-components/src/docs/config.ts | 21 ----------------- .../web-components/src/entry-preview-docs.ts | 23 +++++++++++++++++-- 18 files changed, 135 insertions(+), 145 deletions(-) delete mode 100644 code/renderers/html/src/docs/config.ts delete mode 100644 code/renderers/preact/src/docs/config.ts rename code/renderers/react/src/{ => docs}/applyDecorators.ts (88%) delete mode 100644 code/renderers/react/src/docs/config.ts delete mode 100644 code/renderers/svelte/src/docs/config.ts delete mode 100644 code/renderers/vue/src/docs/config.ts delete mode 100644 code/renderers/vue3/src/docs/config.ts delete mode 100644 code/renderers/web-components/src/docs/config.ts diff --git a/code/renderers/html/src/docs/config.ts b/code/renderers/html/src/docs/config.ts deleted file mode 100644 index 2043949f02e1..000000000000 --- a/code/renderers/html/src/docs/config.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { Addon_DecoratorFunction, ArgTypesEnhancer } from '@storybook/types'; -import { SourceType, enhanceArgTypes } from '@storybook/docs-tools'; - -import { sourceDecorator } from './sourceDecorator'; -import type { Parameters, StoryFnHtmlReturnType } from '../types'; - -export const decorators: Addon_DecoratorFunction[] = [ - sourceDecorator as Addon_DecoratorFunction, -]; - -export const parameters: Partial = { - docs: { - story: { inline: true }, - source: { - type: SourceType.DYNAMIC, - language: 'html', - code: undefined, - excludeDecorators: undefined, - }, - }, -}; - -export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/html/src/docs/sourceDecorator.ts b/code/renderers/html/src/docs/sourceDecorator.ts index da1160fdc4f7..6318c9203312 100644 --- a/code/renderers/html/src/docs/sourceDecorator.ts +++ b/code/renderers/html/src/docs/sourceDecorator.ts @@ -2,13 +2,13 @@ import { SNIPPET_RENDERED, SourceType } from '@storybook/docs-tools'; import { addons, useEffect } from '@storybook/preview-api'; -import type { PartialStoryFn } from '@storybook/types'; +import type { DecoratorFunction } from '@storybook/types'; -import type { HtmlRenderer, StoryContext } from '../types'; +import type { HtmlRenderer } from '../types'; import type { StoryFn } from '../public-types'; -function skipSourceRender(context: StoryContext) { +function skipSourceRender(context: Parameters>[1]) { const sourceParams = context?.parameters.docs?.source; const isArgsStory = context?.parameters.__isArgsStory; @@ -22,7 +22,7 @@ function skipSourceRender(context: StoryContext) { return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE; } -export function sourceDecorator(storyFn: PartialStoryFn, context: StoryContext) { +export const sourceDecorator: DecoratorFunction = (storyFn, context) => { const story = storyFn(); const renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? (context.originalStoryFn as StoryFn)(context.args, context) @@ -42,4 +42,4 @@ export function sourceDecorator(storyFn: PartialStoryFn, context: }); return story; -} +}; diff --git a/code/renderers/html/src/entry-preview-docs.ts b/code/renderers/html/src/entry-preview-docs.ts index afee24665b33..872b95e0e077 100644 --- a/code/renderers/html/src/entry-preview-docs.ts +++ b/code/renderers/html/src/entry-preview-docs.ts @@ -1,2 +1,21 @@ -export { parameters } from './docs/config'; -export { decorators, argTypesEnhancers } from './docs/config'; +import type { ArgTypesEnhancer, DecoratorFunction } from '@storybook/types'; +import { SourceType, enhanceArgTypes } from '@storybook/docs-tools'; + +import { sourceDecorator } from './docs/sourceDecorator'; +import type { HtmlRenderer } from './types'; + +export const decorators: DecoratorFunction[] = [sourceDecorator]; + +export const parameters = { + docs: { + story: { inline: true }, + source: { + type: SourceType.DYNAMIC, + language: 'html', + code: undefined, + excludeDecorators: undefined, + }, + }, +}; + +export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/preact/src/docs/config.ts b/code/renderers/preact/src/docs/config.ts deleted file mode 100644 index e3ef6b8bd97b..000000000000 --- a/code/renderers/preact/src/docs/config.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const parameters = { - docs: { - story: { inline: true }, - }, -}; diff --git a/code/renderers/preact/src/entry-preview-docs.ts b/code/renderers/preact/src/entry-preview-docs.ts index c5cd5bb0dbd4..e3ef6b8bd97b 100644 --- a/code/renderers/preact/src/entry-preview-docs.ts +++ b/code/renderers/preact/src/entry-preview-docs.ts @@ -1 +1,5 @@ -export { parameters } from './docs/config'; +export const parameters = { + docs: { + story: { inline: true }, + }, +}; diff --git a/code/renderers/react/src/applyDecorators.ts b/code/renderers/react/src/docs/applyDecorators.ts similarity index 88% rename from code/renderers/react/src/applyDecorators.ts rename to code/renderers/react/src/docs/applyDecorators.ts index cf5c44fa5f80..109b5057f0c4 100644 --- a/code/renderers/react/src/applyDecorators.ts +++ b/code/renderers/react/src/docs/applyDecorators.ts @@ -1,8 +1,8 @@ import { defaultDecorateStory } from '@storybook/preview-api'; import type { LegacyStoryFn, DecoratorFunction } from '@storybook/types'; -import type { ReactRenderer } from './types'; -import { jsxDecorator } from './docs/jsxDecorator'; +import type { ReactRenderer } from '../types'; +import { jsxDecorator } from './jsxDecorator'; export const applyDecorators = ( storyFn: LegacyStoryFn, diff --git a/code/renderers/react/src/docs/config.ts b/code/renderers/react/src/docs/config.ts deleted file mode 100644 index adc3af6d2318..000000000000 --- a/code/renderers/react/src/docs/config.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Addon_DecoratorFunction, ArgTypesEnhancer } from '@storybook/types'; -import { extractComponentDescription, enhanceArgTypes } from '@storybook/docs-tools'; - -import { extractArgTypes } from './extractArgTypes'; -import { jsxDecorator } from './jsxDecorator'; -import type { StoryFnReactReturnType } from '../types'; - -export const parameters: {} = { - docs: { - story: { inline: true }, - extractArgTypes, - extractComponentDescription, - }, -}; - -export const decorators: Addon_DecoratorFunction[] = [jsxDecorator]; - -export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/react/src/entry-preview-docs.ts b/code/renderers/react/src/entry-preview-docs.ts index 4bd3f83d3465..51e347b0f03d 100644 --- a/code/renderers/react/src/entry-preview-docs.ts +++ b/code/renderers/react/src/entry-preview-docs.ts @@ -1,3 +1,20 @@ -export { parameters } from './docs/config'; -export { decorators, argTypesEnhancers } from './docs/config'; -export { applyDecorators } from './applyDecorators'; +import type { ArgTypesEnhancer, DecoratorFunction } from '@storybook/types'; +import { extractComponentDescription, enhanceArgTypes } from '@storybook/docs-tools'; + +import { extractArgTypes } from './docs/extractArgTypes'; +import { jsxDecorator } from './docs/jsxDecorator'; +import type { ReactRenderer } from './types'; + +export const parameters = { + docs: { + story: { inline: true }, + extractArgTypes, + extractComponentDescription, + }, +}; + +export const decorators: DecoratorFunction[] = [jsxDecorator]; + +export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; + +export { applyDecorators } from './docs/applyDecorators'; diff --git a/code/renderers/svelte/src/docs/config.ts b/code/renderers/svelte/src/docs/config.ts deleted file mode 100644 index 563235ec7f2d..000000000000 --- a/code/renderers/svelte/src/docs/config.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Addon_DecoratorFunction, ArgTypesEnhancer } from '@storybook/types'; -import { enhanceArgTypes } from '@storybook/docs-tools'; -import { extractArgTypes } from './extractArgTypes'; -import { extractComponentDescription } from './extractComponentDescription'; -import { sourceDecorator } from './sourceDecorator'; - -export const parameters: {} = { - docs: { - story: { inline: true }, - extractArgTypes, - extractComponentDescription, - }, -}; - -export const decorators: Addon_DecoratorFunction[] = [sourceDecorator]; - -export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/svelte/src/docs/sourceDecorator.ts b/code/renderers/svelte/src/docs/sourceDecorator.ts index 7b61eea6a7e9..62b27773058a 100644 --- a/code/renderers/svelte/src/docs/sourceDecorator.ts +++ b/code/renderers/svelte/src/docs/sourceDecorator.ts @@ -1,16 +1,17 @@ /* eslint-disable no-underscore-dangle */ import { addons, useEffect } from '@storybook/preview-api'; import { deprecate } from '@storybook/client-logger'; -import type { ArgTypes, Args, StoryContext, Renderer } from '@storybook/types'; +import type { ArgTypes, Args, StoryContext } from '@storybook/types'; import { SourceType, SNIPPET_RENDERED } from '@storybook/docs-tools'; +import type { SvelteRenderer } from '../types'; /** - * Check if the sourcecode should be generated. + * Check if the source-code should be generated. * * @param context StoryContext */ -const skipSourceRender = (context: StoryContext) => { +const skipSourceRender = (context: StoryContext) => { const sourceParams = context?.parameters.docs?.source; const isArgsStory = context?.parameters.__isArgsStory; @@ -162,7 +163,7 @@ function getWrapperProperties(component: any) { * @param storyFn Fn * @param context StoryContext */ -export const sourceDecorator = (storyFn: any, context: StoryContext) => { +export const sourceDecorator = (storyFn: any, context: StoryContext) => { const channel = addons.getChannel(); const skip = skipSourceRender(context); const story = storyFn(); diff --git a/code/renderers/svelte/src/entry-preview-docs.ts b/code/renderers/svelte/src/entry-preview-docs.ts index 71c69e9b33c6..8cc14c3b191f 100644 --- a/code/renderers/svelte/src/entry-preview-docs.ts +++ b/code/renderers/svelte/src/entry-preview-docs.ts @@ -1,3 +1,18 @@ -export { parameters } from './docs/config'; +import type { ArgTypesEnhancer, DecoratorFunction } from '@storybook/types'; +import { enhanceArgTypes } from '@storybook/docs-tools'; +import { extractArgTypes } from './docs/extractArgTypes'; +import { extractComponentDescription } from './docs/extractComponentDescription'; +import { sourceDecorator } from './docs/sourceDecorator'; +import type { SvelteRenderer } from './types'; -export { decorators, argTypesEnhancers } from './docs/config'; +export const parameters = { + docs: { + story: { inline: true }, + extractArgTypes, + extractComponentDescription, + }, +}; + +export const decorators: DecoratorFunction[] = [sourceDecorator]; + +export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/vue/src/docs/config.ts b/code/renderers/vue/src/docs/config.ts deleted file mode 100644 index 2e4d23aa3ad7..000000000000 --- a/code/renderers/vue/src/docs/config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { Addon_DecoratorFunction, ArgTypesEnhancer } from '@storybook/types'; -import { extractComponentDescription, enhanceArgTypes } from '@storybook/docs-tools'; -import { extractArgTypes } from './extractArgTypes'; -import { sourceDecorator } from './sourceDecorator'; - -export const parameters: {} = { - docs: { - story: { inline: true, iframeHeight: '120px' }, - extractArgTypes, - extractComponentDescription, - }, -}; - -export const decorators: Addon_DecoratorFunction[] = [sourceDecorator]; - -export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/vue/src/entry-preview-docs.ts b/code/renderers/vue/src/entry-preview-docs.ts index afee24665b33..bd5af4e3f916 100644 --- a/code/renderers/vue/src/entry-preview-docs.ts +++ b/code/renderers/vue/src/entry-preview-docs.ts @@ -1,2 +1,17 @@ -export { parameters } from './docs/config'; -export { decorators, argTypesEnhancers } from './docs/config'; +import type { ArgTypesEnhancer, DecoratorFunction } from '@storybook/types'; +import { extractComponentDescription, enhanceArgTypes } from '@storybook/docs-tools'; +import { extractArgTypes } from './docs/extractArgTypes'; +import { sourceDecorator } from './docs/sourceDecorator'; +import type { VueRenderer } from './types'; + +export const parameters = { + docs: { + story: { inline: true, iframeHeight: '120px' }, + extractArgTypes, + extractComponentDescription, + }, +}; + +export const decorators: DecoratorFunction[] = [sourceDecorator]; + +export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/vue3/src/docs/config.ts b/code/renderers/vue3/src/docs/config.ts deleted file mode 100644 index ba0a4949b53f..000000000000 --- a/code/renderers/vue3/src/docs/config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { Addon_DecoratorFunction, ArgTypesEnhancer } from '@storybook/types'; -import { extractComponentDescription, enhanceArgTypes } from '@storybook/docs-tools'; -import { extractArgTypes } from './extractArgTypes'; -import { sourceDecorator } from './sourceDecorator'; - -export const parameters: {} = { - docs: { - story: { inline: true }, - extractArgTypes, - extractComponentDescription, - }, -}; - -export const decorators: Addon_DecoratorFunction[] = [sourceDecorator]; - -export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/vue3/src/docs/sourceDecorator.ts b/code/renderers/vue3/src/docs/sourceDecorator.ts index f0e254f082ae..2fc83b62b04b 100644 --- a/code/renderers/vue3/src/docs/sourceDecorator.ts +++ b/code/renderers/vue3/src/docs/sourceDecorator.ts @@ -25,13 +25,14 @@ import { replaceValueWithRef, generateExpression, } from './utils'; +import type { VueRenderer } from '../types'; /** * Check if the sourcecode should be generated. * * @param context StoryContext */ -const skipSourceRender = (context: StoryContext) => { +const skipSourceRender = (context: StoryContext) => { const sourceParams = context?.parameters.docs?.source; const isArgsStory = context?.parameters.__isArgsStory; const isDocsViewMode = context?.viewMode === 'docs'; @@ -153,7 +154,7 @@ function generateScriptSetup(args: Args, argTypes: ArgTypes, components: any[]): */ function getTemplateComponents( renderFn: any, - context?: StoryContext + context?: StoryContext ): (TemplateChildNode | VNode)[] { try { const originalStoryFn = renderFn; @@ -274,7 +275,7 @@ export function generateTemplateSource( * @param storyFn Fn * @param context StoryContext */ -export const sourceDecorator = (storyFn: any, context: StoryContext) => { +export const sourceDecorator = (storyFn: any, context: StoryContext) => { const skip = skipSourceRender(context); const story = storyFn(); @@ -290,7 +291,7 @@ export const sourceDecorator = (storyFn: any, context: StoryContext) = return story; }; -export function generateSource(context: StoryContext) { +export function generateSource(context: StoryContext) { const channel = addons.getChannel(); const { args = {}, argTypes = {}, id } = context || {}; const storyComponents = getTemplateComponents(context?.originalStoryFn, context); diff --git a/code/renderers/vue3/src/entry-preview-docs.ts b/code/renderers/vue3/src/entry-preview-docs.ts index afee24665b33..0c598ffdec49 100644 --- a/code/renderers/vue3/src/entry-preview-docs.ts +++ b/code/renderers/vue3/src/entry-preview-docs.ts @@ -1,2 +1,17 @@ -export { parameters } from './docs/config'; -export { decorators, argTypesEnhancers } from './docs/config'; +import type { ArgTypesEnhancer, DecoratorFunction } from '@storybook/types'; +import { extractComponentDescription, enhanceArgTypes } from '@storybook/docs-tools'; +import { extractArgTypes } from './docs/extractArgTypes'; +import { sourceDecorator } from './docs/sourceDecorator'; +import type { VueRenderer } from './types'; + +export const parameters = { + docs: { + story: { inline: true }, + extractArgTypes, + extractComponentDescription, + }, +}; + +export const decorators: DecoratorFunction[] = [sourceDecorator]; + +export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/web-components/src/docs/config.ts b/code/renderers/web-components/src/docs/config.ts deleted file mode 100644 index 3597f99cd4cc..000000000000 --- a/code/renderers/web-components/src/docs/config.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { Addon_DecoratorFunction, ArgTypesEnhancer } from '@storybook/types'; -import { SourceType, enhanceArgTypes } from '@storybook/docs-tools'; -import { extractArgTypes, extractComponentDescription } from './custom-elements'; -import { sourceDecorator } from './sourceDecorator'; -import type { StoryFnHtmlReturnType } from '../types'; - -export const decorators: Addon_DecoratorFunction[] = [sourceDecorator]; - -export const parameters: object = { - docs: { - extractArgTypes, - extractComponentDescription, - story: { inline: true }, - source: { - type: SourceType.DYNAMIC, - language: 'html', - }, - }, -}; - -export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; diff --git a/code/renderers/web-components/src/entry-preview-docs.ts b/code/renderers/web-components/src/entry-preview-docs.ts index afee24665b33..917c0c17eb84 100644 --- a/code/renderers/web-components/src/entry-preview-docs.ts +++ b/code/renderers/web-components/src/entry-preview-docs.ts @@ -1,2 +1,21 @@ -export { parameters } from './docs/config'; -export { decorators, argTypesEnhancers } from './docs/config'; +import type { ArgTypesEnhancer, DecoratorFunction } from '@storybook/types'; +import { SourceType, enhanceArgTypes } from '@storybook/docs-tools'; +import { extractArgTypes, extractComponentDescription } from './docs/custom-elements'; +import { sourceDecorator } from './docs/sourceDecorator'; +import type { WebComponentsRenderer } from './types'; + +export const decorators: DecoratorFunction[] = [sourceDecorator]; + +export const parameters = { + docs: { + extractArgTypes, + extractComponentDescription, + story: { inline: true }, + source: { + type: SourceType.DYNAMIC, + language: 'html', + }, + }, +}; + +export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes]; From 2f76b605f26fca3478a94240ee0c4487863c0145 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 1 Nov 2023 09:30:03 +0100 Subject: [PATCH 17/17] fix --- code/renderers/vue3/src/docs/sourceDecorator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/renderers/vue3/src/docs/sourceDecorator.ts b/code/renderers/vue3/src/docs/sourceDecorator.ts index 2fc83b62b04b..e0820db75cbd 100644 --- a/code/renderers/vue3/src/docs/sourceDecorator.ts +++ b/code/renderers/vue3/src/docs/sourceDecorator.ts @@ -1,7 +1,7 @@ /* eslint-disable no-eval */ /* eslint-disable no-underscore-dangle */ import { addons } from '@storybook/preview-api'; -import type { ArgTypes, Args, StoryContext, Renderer } from '@storybook/types'; +import type { ArgTypes, Args, StoryContext } from '@storybook/types'; import { SourceType, SNIPPET_RENDERED } from '@storybook/docs-tools';