Skip to content

Commit

Permalink
App-html: align types with addon, angular and react
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio-martinez committed Jul 11, 2019
1 parent 948f507 commit c70c1a9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 44 deletions.
1 change: 1 addition & 0 deletions app/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "5.2.0-alpha.41",
"@storybook/core": "5.2.0-alpha.41",
"common-tags": "^1.8.0",
"core-js": "^3.0.1",
Expand Down
55 changes: 29 additions & 26 deletions app/html/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
/* eslint-disable prefer-destructuring */
import { start } from '@storybook/core/client';
import { ClientStoryApi } from '@storybook/addons';

import './globals';
import render from './render';
import { StoryFnHtmlReturnType, IStorybookSection } from './types';

export type StoriesOfArgs = [string, typeof module];

export type LoadFnArgs = [RequireContext, typeof module, string];
const framework = 'html';

export interface RequireContext {
keys(): string[];
(id: string): any;
<T>(id: string): T;
resolve(id: string): string;
interface ClientApi extends ClientStoryApi<StoryFnHtmlReturnType> {
setAddon(addon: any): void;
configure(loaders: () => void, module: NodeModule): void;
getStorybook(): IStorybookSection[];
clearDecorators(): void;
forceReRender(): void;
raw: () => any; // todo add type
load: (req: any, m: NodeModule, framework: string) => void;
}

const { load: coreLoad, clientApi, configApi, forceReRender } = start(render);

export const {
setAddon,
addDecorator,
addParameters,
clearDecorators,
getStorybook,
raw,
} = clientApi;

const framework = 'html';
export const storiesOf = (...args: StoriesOfArgs) =>
clientApi.storiesOf(...args).addParameters({ framework });
export const load = (...args: LoadFnArgs) => coreLoad(...args, framework);

export const { configure } = configApi;
export { forceReRender };
const api = start(render);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
framework,
});
};

export const load: ClientApi['load'] = (...args) => api.load(...args, framework);
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator;
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters;
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators;
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon;
export const configure: ClientApi['configure'] = api.configApi.configure;
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender;
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook;
export const raw: ClientApi['raw'] = api.clientApi.raw;
15 changes: 1 addition & 14 deletions app/html/src/client/preview/render.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import { document, Node } from 'global';
import { stripIndents } from 'common-tags';

export interface ShowErrorArgs {
title: string;
description: string;
}

export interface RenderMainArgs {
storyFn: () => string | Node | undefined;
selectedKind: string;
selectedStory: string;
showMain: () => void;
showError: (args: ShowErrorArgs) => void;
forceRender: boolean;
}
import { RenderMainArgs } from './types';

const rootElement = document.getElementById('root');

Expand Down
27 changes: 27 additions & 0 deletions app/html/src/client/preview/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { StoryFn } from '@storybook/addons';

export type StoryFnHtmlReturnType = string | Node;

export interface IStorybookStory {
name: string;
render: () => any;
}

export interface IStorybookSection {
kind: string;
stories: IStorybookStory[];
}

export interface ShowErrorArgs {
title: string;
description: string;
}

export interface RenderMainArgs {
storyFn: () => StoryFn<StoryFnHtmlReturnType>;
selectedKind: string;
selectedStory: string;
showMain: () => void;
showError: (args: ShowErrorArgs) => void;
forceRender: boolean;
}
3 changes: 2 additions & 1 deletion app/html/src/server/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import packageJson from '../../package.json';
// tslint:disable-next-line: no-var-requires
const packageJson = require('../../package.json');

export default {
packageJson,
Expand Down
7 changes: 4 additions & 3 deletions app/html/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare module '@storybook/core/*';
declare module 'global';
declare module '*.json';
declare module '@storybook/core/client';
declare module '@storybook/core/server';

// will be provided by the webpack define plugin
declare var NODE_ENV: string | undefined;

0 comments on commit c70c1a9

Please sign in to comment.