From 7bf028fe2f696d12b6ca77ed6c04b32311d817a4 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 17 Oct 2022 13:11:48 +0200 Subject: [PATCH] add the global api back because it's used internally Remove the global api from the public interface in renderers --- .../frameworks/angular/src/client/public-api.ts | 8 +------- code/lib/client-api/src/ClientApi.ts | 17 ++++++++++++++++- code/renderers/html/src/public-api.ts | 8 +------- code/renderers/preact/src/public-api.ts | 8 +------- code/renderers/react/src/public-api.tsx | 10 +--------- code/renderers/server/src/public-api.ts | 5 ++--- code/renderers/svelte/src/public-api.ts | 2 +- code/renderers/vue/src/public-api.ts | 8 +------- code/renderers/vue3/src/public-api.ts | 6 +----- code/renderers/web-components/src/public-api.ts | 8 +------- 10 files changed, 26 insertions(+), 54 deletions(-) diff --git a/code/frameworks/angular/src/client/public-api.ts b/code/frameworks/angular/src/client/public-api.ts index 0a2ca4a75a4..98b614df58a 100644 --- a/code/frameworks/angular/src/client/public-api.ts +++ b/code/frameworks/angular/src/client/public-api.ts @@ -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 { 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; diff --git a/code/lib/client-api/src/ClientApi.ts b/code/lib/client-api/src/ClientApi.ts index 7b7f61114c0..b7fa919e0d8 100644 --- a/code/lib/client-api/src/ClientApi.ts +++ b/code/lib/client-api/src/ClientApi.ts @@ -48,7 +48,7 @@ let singleton: ClientApi; 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) => { + checkMethod('addDecorator'); + singleton.addDecorator(decorator); +}; + +export const addParameters = (parameters: Parameters) => { + checkMethod('addParameters'); + singleton.addParameters(parameters); +}; + +export const addLoader = (loader: LoaderFunction) => { + checkMethod('addLoader'); + singleton.addLoader(loader); +}; + export const addArgs = (args: Args) => { checkMethod('addArgs'); singleton.addArgs(args); diff --git a/code/renderers/html/src/public-api.ts b/code/renderers/html/src/public-api.ts index 6a024cdce61..28d78a70bff 100644 --- a/code/renderers/html/src/public-api.ts +++ b/code/renderers/html/src/public-api.ts @@ -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 { 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; diff --git a/code/renderers/preact/src/public-api.ts b/code/renderers/preact/src/public-api.ts index c0121dd2b8b..ffa679e1d23 100644 --- a/code/renderers/preact/src/public-api.ts +++ b/code/renderers/preact/src/public-api.ts @@ -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 { 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; diff --git a/code/renderers/react/src/public-api.tsx b/code/renderers/react/src/public-api.tsx index 36366fd5515..aaa0727294c 100644 --- a/code/renderers/react/src/public-api.tsx +++ b/code/renderers/react/src/public-api.tsx @@ -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 { 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 = DecoratorFunction; -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; diff --git a/code/renderers/server/src/public-api.ts b/code/renderers/server/src/public-api.ts index 2ec72dd7698..71d4f110e07 100644 --- a/code/renderers/server/src/public-api.ts +++ b/code/renderers/server/src/public-api.ts @@ -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 { 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; diff --git a/code/renderers/svelte/src/public-api.ts b/code/renderers/svelte/src/public-api.ts index f1634180c09..e972744c573 100644 --- a/code/renderers/svelte/src/public-api.ts +++ b/code/renderers/svelte/src/public-api.ts @@ -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) => diff --git a/code/renderers/vue/src/public-api.ts b/code/renderers/vue/src/public-api.ts index 8908f6b8006..f5c287a5603 100644 --- a/code/renderers/vue/src/public-api.ts +++ b/code/renderers/vue/src/public-api.ts @@ -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 { 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; diff --git a/code/renderers/vue3/src/public-api.ts b/code/renderers/vue3/src/public-api.ts index a850ffabd74..d1502a78527 100644 --- a/code/renderers/vue3/src/public-api.ts +++ b/code/renderers/vue3/src/public-api.ts @@ -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 { 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'; diff --git a/code/renderers/web-components/src/public-api.ts b/code/renderers/web-components/src/public-api.ts index acd7d35c51c..775a90ea52f 100644 --- a/code/renderers/web-components/src/public-api.ts +++ b/code/renderers/web-components/src/public-api.ts @@ -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 { 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;