add the global api back because it's used internally

Remove the global api from the public interface in renderers
This commit is contained in:
Norbert de Langen 2022-10-17 13:11:48 +02:00
parent 414020c0ea
commit 7bf028fe2f
No known key found for this signature in database
GPG Key ID: FD0E78AF9A837762
10 changed files with 26 additions and 54 deletions

View File

@ -3,7 +3,7 @@ import type { ClientStoryApi, Loadable } from '@storybook/addons';
import { start } from '@storybook/core-client';
import { renderToDOM, render } from './render';
import decorateStory from './decorateStory';
import type { IStorybookSection, AngularFramework } from './types';
import type { AngularFramework } from './types';
export * from './public-types';
@ -11,7 +11,6 @@ const FRAMEWORK = 'angular';
interface ClientApi extends ClientStoryApi<AngularFramework['storyResult']> {
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
forceReRender(): void;
raw: () => any; // todo add type
load: (...args: any[]) => void;
@ -26,10 +25,5 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook;
export const raw: ClientApi['raw'] = api.clientApi.raw;

View File

@ -48,7 +48,7 @@ let singleton: ClientApi<AnyFramework>;
const warningAlternatives = {
addDecorator: `Instead, use \`export const decorators = [];\` in your \`preview.js\`.`,
addParameters: `Instead, use \`export const parameters = {};\` in your \`preview.js\`.`,
addLoaders: `Instead, use \`export const loaders = [];\` in your \`preview.js\`.`,
addLoader: `Instead, use \`export const loaders = [];\` in your \`preview.js\`.`,
addArgs: '',
addArgTypes: '',
addArgsEnhancer: '',
@ -72,6 +72,21 @@ const checkMethod = (method: keyof typeof warningAlternatives) => {
}
};
export const addDecorator = (decorator: DecoratorFunction<AnyFramework>) => {
checkMethod('addDecorator');
singleton.addDecorator(decorator);
};
export const addParameters = (parameters: Parameters) => {
checkMethod('addParameters');
singleton.addParameters(parameters);
};
export const addLoader = (loader: LoaderFunction<AnyFramework>) => {
checkMethod('addLoader');
singleton.addLoader(loader);
};
export const addArgs = (args: Args) => {
checkMethod('addArgs');
singleton.addArgs(args);

View File

@ -1,7 +1,7 @@
/* eslint-disable prefer-destructuring */
import { start } from '@storybook/core-client';
import type { ClientStoryApi, Loadable } from '@storybook/addons';
import type { HtmlFramework, IStorybookSection } from './types';
import type { HtmlFramework } from './types';
import { renderToDOM, render } from './render';
@ -9,7 +9,6 @@ const FRAMEWORK = 'html';
interface ClientApi extends ClientStoryApi<HtmlFramework['storyResult']> {
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
forceReRender(): void;
raw: () => any; // todo add type
}
@ -23,10 +22,5 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook;
export const raw: ClientApi['raw'] = api.clientApi.raw;

View File

@ -3,11 +3,10 @@ import { start } from '@storybook/core-client';
import type { ClientStoryApi, Loadable } from '@storybook/addons';
import { renderToDOM } from './render';
import type { IStorybookSection, PreactFramework } from './types';
import type { PreactFramework } from './types';
export interface ClientApi extends ClientStoryApi<PreactFramework['storyResult']> {
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
forceReRender(): void;
raw: () => any; // todo add type
load: (...args: any[]) => void;
@ -23,10 +22,5 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook;
export const raw: ClientApi['raw'] = api.clientApi.raw;

View File

@ -1,14 +1,12 @@
/* eslint-disable prefer-destructuring */
import { start } from '@storybook/core-client';
import type { ClientStoryApi, Loadable } from '@storybook/addons';
import type { Args, DecoratorFunction } from '@storybook/csf';
import { renderToDOM, render } from './render';
import type { IStorybookSection, ReactFramework } from './types';
import type { ReactFramework } from './types';
interface ClientApi extends ClientStoryApi<ReactFramework['storyResult']> {
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
forceReRender(): void;
raw: () => any; // todo add type
}
@ -23,11 +21,5 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export type DecoratorFn<TArgs = Args> = DecoratorFunction<ReactFramework, TArgs>;
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook;
export const raw: ClientApi['raw'] = api.clientApi.raw;

View File

@ -2,13 +2,12 @@ import { start } from '@storybook/core-client';
import type { ClientStoryApi, Loadable } from '@storybook/addons';
import { renderToDOM, render } from './render';
import type { IStorybookSection, ServerFramework } from './types';
import type { ServerFramework } from './types';
const FRAMEWORK = 'server';
interface ClientApi extends ClientStoryApi<ServerFramework['storyResult']> {
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
forceReRender(): void;
raw: () => any; // todo add type
}
@ -22,6 +21,6 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const { addDecorator, addParameters, getStorybook, raw } = api.clientApi;
export const { raw } = api.clientApi;
export const { forceReRender } = api;

View File

@ -12,7 +12,7 @@ const {
render,
});
export const { addDecorator, addParameters, getStorybook, raw } = clientApi;
export const { raw } = clientApi;
const FRAMEWORK = 'svelte';
export const storiesOf = (kind: string, m: any) =>

View File

@ -2,7 +2,7 @@
import { start } from '@storybook/core-client';
import type { ClientStoryApi, Loadable } from '@storybook/addons';
import type { IStorybookSection, VueFramework } from './types';
import type { VueFramework } from './types';
import { renderToDOM, render } from './render';
import { decorateStory } from './decorateStory';
@ -10,7 +10,6 @@ const FRAMEWORK = 'vue';
interface ClientApi extends ClientStoryApi<VueFramework['storyResult']> {
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
forceReRender(): void;
raw: () => any; // todo add type
load: (...args: any[]) => void;
@ -25,10 +24,5 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook;
export const raw: ClientApi['raw'] = api.clientApi.raw;

View File

@ -2,7 +2,7 @@ import type { App } from 'vue';
import { start } from '@storybook/core-client';
import type { ClientStoryApi, Loadable } from '@storybook/addons';
import type { IStorybookSection, VueFramework } from './types';
import type { VueFramework } from './types';
import { decorateStory } from './decorateStory';
import { render, renderToDOM } from './render';
@ -11,7 +11,6 @@ const FRAMEWORK = 'vue3';
interface ClientApi extends ClientStoryApi<VueFramework['storyResult']> {
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
forceReRender(): void;
raw: () => any; // todo add type
load: (...args: any[]) => void;
@ -27,9 +26,6 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const { addDecorator } = api.clientApi;
export const { addParameters } = api.clientApi;
export const { forceReRender } = api;
export const { getStorybook } = api.clientApi;
export const { raw } = api.clientApi;
export { setup } from './render';

View File

@ -3,13 +3,12 @@ import { start } from '@storybook/core-client';
import type { ClientStoryApi, Loadable } from '@storybook/addons';
import { renderToDOM } from './render';
import type { IStorybookSection, WebComponentsFramework } from './types';
import type { WebComponentsFramework } from './types';
const FRAMEWORK = 'web-components';
interface ClientApi extends ClientStoryApi<WebComponentsFramework['storyResult']> {
configure(loader: Loadable, module: NodeModule): void;
getStorybook(): IStorybookSection[];
forceReRender(): void;
raw: () => any; // todo add type
}
@ -23,10 +22,5 @@ export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
};
export const configure: ClientApi['configure'] = (...args) => api.configure(FRAMEWORK, ...args);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi
.addDecorator as ClientApi['addDecorator'];
export const addParameters: ClientApi['addParameters'] = api.clientApi
.addParameters as ClientApi['addParameters'];
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook;
export const raw: ClientApi['raw'] = api.clientApi.raw;