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

Add app layer presets #16012

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/angular/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { render, renderToDOM } from './render';

export const parameters = { framework: 'react' };
export const parameters = { framework: 'angular' };
6 changes: 4 additions & 2 deletions app/angular/src/client/preview/render.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { RenderContext } from '@storybook/store';
import { ArgsStoryFn } from '@storybook/csf';

import { renderNgApp } from './angular/helpers';
import { AngularFramework, Story } from './types-6-0';
import { AngularFramework } from './types-6-0';

import { RendererFactory } from './angular-beta/RendererFactory';

export const rendererFactory = new RendererFactory();

export const render: Story = (props) => ({ props });
export const render: ArgsStoryFn<AngularFramework> = (props) => ({ props });

export async function renderToDOM(
{
storyFn,
Expand Down
7 changes: 7 additions & 0 deletions app/ember/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/ember/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { renderToDOM } from './render';

export const parameters = { framework: 'ember' };
4 changes: 2 additions & 2 deletions app/ember/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { start } from '@storybook/core/client';

import './globals';
import render from './render';
import { renderToDOM } from './render';

const { configure: coreConfigure, clientApi, forceReRender } = start(render);
const { configure: coreConfigure, clientApi, forceReRender } = start(renderToDOM);

export const {
setAddon,
Expand Down
2 changes: 1 addition & 1 deletion app/ember/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function render(options: OptionsArgs, el: HTMLElement) {
});
}

export default function renderMain(
export function renderToDOM(
{ storyFn, kind, name, showMain, showError }: RenderContext<EmberFramework>,
domElement: HTMLElement
) {
Expand Down
7 changes: 7 additions & 0 deletions app/html/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/html/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { renderToDOM } from './render';

export const parameters = { framework: 'html' };
4 changes: 2 additions & 2 deletions app/html/src/client/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ClientStoryApi, Loadable } from '@storybook/addons';
import { HtmlFramework } from './types-6-0';

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

const framework = 'html';
Expand All @@ -18,7 +18,7 @@ interface ClientApi extends ClientStoryApi<HtmlFramework['storyResult']> {
raw: () => any; // todo add type
}

const api = start(render);
const api = start(renderToDOM);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand Down
2 changes: 1 addition & 1 deletion app/html/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { HtmlFramework } from './types-6-0';

const { Node } = global;

export default function renderMain(
export function renderToDOM(
{ storyFn, kind, name, showMain, showError, forceRemount }: RenderContext<HtmlFramework>,
domElement: HTMLElement
) {
Expand Down
7 changes: 7 additions & 0 deletions app/preact/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/preact/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { renderToDOM } from './render';

export const parameters = { framework: 'preact' };
4 changes: 2 additions & 2 deletions app/preact/src/client/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { start } from '@storybook/core/client';
import { ClientStoryApi, Loadable } from '@storybook/addons';

import './globals';
import render from './render';
import { renderToDOM } from './render';
import { IStorybookSection } from './types';
import { PreactFramework } from './types-6-0';

Expand All @@ -18,7 +18,7 @@ export interface ClientApi extends ClientStoryApi<PreactFramework['storyResult']
}

const framework = 'preact';
const api = start(render);
const api = start(renderToDOM);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand Down
2 changes: 1 addition & 1 deletion app/preact/src/client/preview/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const StoryHarness: preact.FunctionalComponent<{
return content;
};

export default function renderMain(
export function renderToDOM(
{ storyFn, title, name, showMain, showError, forceRemount }: RenderContext<PreactFramework>,
domElement: HTMLElement
) {
Expand Down
7 changes: 7 additions & 0 deletions app/react/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/react/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { render, renderToDOM } from './render';

export const parameters = { framework: 'react' };
7 changes: 7 additions & 0 deletions app/server/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/server/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { render, renderToDOM } from './render';

export const parameters = { framework: 'server' };
6 changes: 2 additions & 4 deletions app/server/src/client/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { start } from '@storybook/core/client';
import { ClientStoryApi, Loadable, StoryFn, Args } from '@storybook/addons';
import { ClientStoryApi, Loadable } from '@storybook/addons';

import './globals';
import { renderMain as renderToDOM } from './render';
import { renderToDOM, render } from './render';
import { IStorybookSection, ServerFramework } from './types';

const framework = 'server';
Expand All @@ -16,8 +16,6 @@ interface ClientApi extends ClientStoryApi<ServerFramework['storyResult']> {
raw: () => any; // todo add type
}

const render: StoryFn = (args: Args) => {};

const api = start(renderToDOM, { render });

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
Expand Down
6 changes: 4 additions & 2 deletions app/server/src/client/preview/render.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-param-reassign */
import global from 'global';
import dedent from 'ts-dedent';
import { Args, ArgTypes } from '@storybook/api';
import { RenderContext } from '@storybook/store';
import { simulatePageLoad, simulateDOMContentLoaded } from '@storybook/preview-web';
import { StoryFn, Args, ArgTypes } from '@storybook/csf';
import { FetchStoryHtmlType, ServerFramework } from './types';

const { fetch, Node } = global;
Expand Down Expand Up @@ -40,7 +40,9 @@ const buildStoryArgs = (args: Args, argTypes: ArgTypes) => {
return storyArgs;
};

export async function renderMain(
export const render: StoryFn<ServerFramework> = (args: Args) => {};

export async function renderToDOM(
{
id,
title,
Expand Down
7 changes: 7 additions & 0 deletions app/svelte/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/svelte/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { renderToDOM } from './render';

export const parameters = { framework: 'svelte' };
6 changes: 4 additions & 2 deletions app/svelte/src/client/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { start } from '@storybook/core/client';
import { decorateStory } from './decorators';

import './globals';
import render from './render';
import { renderToDOM } from './render';

const { configure: coreConfigure, clientApi, forceReRender } = start(render, { decorateStory });
const { configure: coreConfigure, clientApi, forceReRender } = start(renderToDOM, {
decorateStory,
});

export const {
setAddon,
Expand Down
2 changes: 1 addition & 1 deletion app/svelte/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function cleanUpPreviousStory() {
previousComponent = null;
}

export default function render(
export function renderToDOM(
{ storyFn, kind, name, showMain, showError }: RenderContext<SvelteFramework>,
domElement: HTMLElement
) {
Expand Down
7 changes: 7 additions & 0 deletions app/vue/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/vue/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { renderToDOM } from './render';

export const parameters = { framework: 'vue' };
4 changes: 2 additions & 2 deletions app/vue/src/client/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './globals';
import { IStorybookSection, StoryFnVueReturnType } from './types';
import { VueFramework } from './types-6-0';

import render, { VALUES } from './render';
import { renderToDOM, VALUES } from './render';
import { extractProps } from './util';

export const WRAPS = 'STORYBOOK_WRAPS';
Expand Down Expand Up @@ -100,7 +100,7 @@ interface ClientApi extends ClientStoryApi<VueFramework['storyResult']> {
load: (...args: any[]) => void;
}

const api = start(render, { decorateStory });
const api = start(renderToDOM, { decorateStory });

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand Down
2 changes: 1 addition & 1 deletion app/vue/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const root = new Vue({
},
});

export default function render(
export function renderToDOM(
{
title,
name,
Expand Down
7 changes: 7 additions & 0 deletions app/vue3/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/vue3/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { renderToDOM } from './render';

export const parameters = { framework: 'vue3' };
4 changes: 2 additions & 2 deletions app/vue3/src/client/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './globals';
import { IStorybookSection } from './types';
import { VueFramework } from './types-6-0';

import render, { storybookApp } from './render';
import { renderToDOM, storybookApp } from './render';

/*
This normalizes a functional component into a render method in ComponentOptions.
Expand Down Expand Up @@ -87,7 +87,7 @@ interface ClientApi extends ClientStoryApi<VueFramework['storyResult']> {
app: App;
}

const api = start(render, { decorateStory });
const api = start(renderToDOM, { decorateStory });

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand Down
2 changes: 1 addition & 1 deletion app/vue3/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const storybookApp = createApp({
},
});

export default function render(
export function renderToDOM(
{ title, name, storyFn, showMain, showError, showException }: RenderContext<VueFramework>,
domElement: HTMLElement
) {
Expand Down
7 changes: 7 additions & 0 deletions app/web-components/preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function config(entry = []) {
return [...entry, require.resolve('./dist/esm/client/preview/config')];
}

module.exports = {
config,
};
3 changes: 3 additions & 0 deletions app/web-components/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { renderToDOM } from './render';

export const parameters = { framework: 'web-components' };
4 changes: 2 additions & 2 deletions app/web-components/src/client/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { start } from '@storybook/core/client';
import { ClientStoryApi, Loadable } from '@storybook/addons';

import './globals';
import render from './render';
import { renderToDOM } from './render';
import { IStorybookSection } from './types';
import { WebComponentsFramework } from './types-6-0';

Expand All @@ -18,7 +18,7 @@ interface ClientApi extends ClientStoryApi<WebComponentsFramework['storyResult']
raw: () => any; // todo add type
}

const api = start(render);
const api = start(renderToDOM);

export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
Expand Down
2 changes: 1 addition & 1 deletion app/web-components/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { WebComponentsFramework } from './types-6-0';

const { Node } = global;

export default function renderMain(
export function renderToDOM(
{ storyFn, kind, name, showMain, showError, forceRemount }: RenderContext<WebComponentsFramework>,
domElement: HTMLElement
) {
Expand Down