Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Split renderers preview entrypoints #24623

Merged
merged 19 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c656965
split the html renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
bbdcd6a
split the preact renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
fc5c4a9
split the react renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
d77983c
split the server renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
ac33fe9
split the svelte renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
5ef2534
split the vue renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
da42b5d
split the vue3 renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
ea7c242
split the web-components renderer preview entrypoint into docs & non-…
ndelangen Oct 30, 2023
5aaf56e
cleanup
ndelangen Oct 30, 2023
02f9b36
change mechanism for detecting addon docs being active
ndelangen Oct 31, 2023
518d643
corrections
ndelangen Oct 31, 2023
0d9b58a
do not edit docs config is --docs isn't set
ndelangen Oct 31, 2023
09778c8
optimize a story do it does not pull in the entire lodash universe
ndelangen Oct 31, 2023
54cb15a
rename preview (previously config) to entry-preview, for easier ident…
ndelangen Oct 31, 2023
7e49ce6
Merge branch 'next' into norbert/split-docs-entries
ndelangen Oct 31, 2023
10b1e55
rename preview docs entrypoint
ndelangen Nov 1, 2023
cb03069
cleanup
ndelangen Nov 1, 2023
0ef13ab
Merge branch 'next' into norbert/split-docs-entries
ndelangen Nov 1, 2023
2f76b60
fix
ndelangen Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions code/lib/core-server/src/presets/common-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/template/stories/args.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions code/renderers/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/entry-preview.mjs": "./dist/entry-preview.mjs",
"./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs",
"./package.json": "./package.json"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -71,7 +69,9 @@
"bundler": {
"entries": [
"./src/index.ts",
"./src/config.ts"
"./src/preset.ts",
"./src/entry-preview.ts",
"./src/entry-preview-docs.ts"
],
"platform": "browser"
},
Expand Down
1 change: 1 addition & 0 deletions code/renderers/html/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/preset');
1 change: 0 additions & 1 deletion code/renderers/html/preview.js

This file was deleted.

7 changes: 0 additions & 7 deletions code/renderers/html/src/config.ts

This file was deleted.

23 changes: 0 additions & 23 deletions code/renderers/html/src/docs/config.ts

This file was deleted.

10 changes: 5 additions & 5 deletions code/renderers/html/src/docs/sourceDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DecoratorFunction<HtmlRenderer>>[1]) {
const sourceParams = context?.parameters.docs?.source;
const isArgsStory = context?.parameters.__isArgsStory;

Expand All @@ -22,7 +22,7 @@ function skipSourceRender(context: StoryContext) {
return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
}

export function sourceDecorator(storyFn: PartialStoryFn<HtmlRenderer>, context: StoryContext) {
export const sourceDecorator: DecoratorFunction<HtmlRenderer> = (storyFn, context) => {
const story = storyFn();
const renderedForSource = context?.parameters.docs?.source?.excludeDecorators
? (context.originalStoryFn as StoryFn)(context.args, context)
Expand All @@ -42,4 +42,4 @@ export function sourceDecorator(storyFn: PartialStoryFn<HtmlRenderer>, context:
});

return story;
}
};
21 changes: 21 additions & 0 deletions code/renderers/html/src/entry-preview-docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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<HtmlRenderer>[] = [sourceDecorator];

export const parameters = {
docs: {
story: { inline: true },
source: {
type: SourceType.DYNAMIC,
language: 'html',
code: undefined,
excludeDecorators: undefined,
},
},
};

export const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes];
5 changes: 5 additions & 0 deletions code/renderers/html/src/entry-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Parameters } from './types';

export const parameters: Parameters = { renderer: 'html' };

export { renderToCanvas, render } from './render';
12 changes: 12 additions & 0 deletions code/renderers/html/src/preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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, 'entry-preview.mjs')])
.concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []);
};
12 changes: 6 additions & 6 deletions code/renderers/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/entry-preview.mjs": "./dist/entry-preview.mjs",
"./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs",
"./package.json": "./package.json"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -71,7 +69,9 @@
"bundler": {
"entries": [
"./src/index.ts",
"./src/config.ts"
"./src/preset.ts",
"./src/entry-preview.ts",
"./src/entry-preview-docs.ts"
],
"platform": "browser"
},
Expand Down
1 change: 1 addition & 0 deletions code/renderers/preact/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/preset');
1 change: 0 additions & 1 deletion code/renderers/preact/preview.js

This file was deleted.

5 changes: 0 additions & 5 deletions code/renderers/preact/src/config.ts

This file was deleted.

3 changes: 3 additions & 0 deletions code/renderers/preact/src/entry-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { renderToCanvas, render } from './render';

export const parameters = { renderer: 'preact' };
12 changes: 12 additions & 0 deletions code/renderers/preact/src/preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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, 'entry-preview.mjs')])
.concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []);
};
17 changes: 6 additions & 11 deletions code/renderers/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/entry-preview.mjs": "./dist/entry-preview.mjs",
"./dist/entry-preview-docs.mjs": "./dist/entry-preview-docs.mjs",
"./package.json": "./package.json"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -102,8 +96,9 @@
"bundler": {
"entries": [
"./src/index.ts",
"./src/config.ts",
"./src/preset.ts"
"./src/preset.ts",
"./src/entry-preview.ts",
"./src/entry-preview-docs.ts"
],
"platform": "browser"
},
Expand Down
1 change: 0 additions & 1 deletion code/renderers/react/preview.js

This file was deleted.

9 changes: 0 additions & 9 deletions code/renderers/react/src/config.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<ReactRenderer>,
Expand Down
18 changes: 0 additions & 18 deletions code/renderers/react/src/docs/config.ts

This file was deleted.

20 changes: 20 additions & 0 deletions code/renderers/react/src/entry-preview-docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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<ReactRenderer>[] = [jsxDecorator];

export const argTypesEnhancers: ArgTypesEnhancer<ReactRenderer>[] = [enhanceArgTypes];

export { applyDecorators } from './docs/applyDecorators';
2 changes: 2 additions & 0 deletions code/renderers/react/src/entry-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const parameters: {} = { renderer: 'react' };
export { render, renderToCanvas } from './render';
13 changes: 13 additions & 0 deletions code/renderers/react/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import type { StorybookConfig } from '@storybook/types';

import { join } from 'path';

export const addons: StorybookConfig['addons'] = [
require.resolve('@storybook/react-dom-shim/dist/preset'),
];

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
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, 'entry-preview.mjs')])
.concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : []);
};
16 changes: 4 additions & 12 deletions code/renderers/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/entry-preview.mjs": "./dist/entry-preview.mjs",
"./package.json": "./package.json"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -77,8 +69,8 @@
"bundler": {
"entries": [
"./src/index.ts",
"./src/config.ts",
"./src/preset.ts"
"./src/preset.ts",
"./src/entry-preview.ts"
],
"platform": "browser"
},
Expand Down
1 change: 0 additions & 1 deletion code/renderers/server/preview.js

This file was deleted.

12 changes: 12 additions & 0 deletions code/renderers/server/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import fs from 'fs-extra';
import yaml from 'yaml';
import type { StorybookConfig, Tag, StoryName, ComponentTitle } from '@storybook/types';

import { join } from 'path';

type FileContent = {
title: ComponentTitle;
tags?: Tag[];
Expand Down Expand Up @@ -34,3 +36,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, 'entry-preview.mjs')]);
};
Loading