storybook-addon-playground
Version:
A playground to enable consumers learn how to use the component library or to reproduce bugs
41 lines (39 loc) • 1.6 kB
JavaScript
import { addons } from '@storybook/manager-api';
import { Addon_TypesEnum } from '@storybook/types';
import Panel from './components/Addons/Panel.js';
import PanelTitle from './components/Addons/PanelTitle.js';
import Tool from './components/Addons/Tool.js';
import { ADDON_ID, TOOL_ID, PANEL_ID, ADDON_ID_FOR_PARAMETERS } from './consts/addon-consts.js';
import { PLAYGROUND_STORY_PREPARED } from './consts/events-consts.js';
import '@codemirror/commands';
import { STORY_PREPARED } from '@storybook/core-events';
import 'prettier';
import 'prettier/parser-html';
import 'prettier/parser-typescript';
import 'prettier/parser-postcss';
import { getStoryId } from './utils/storybook-utils.js';
import 'lz-string';
addons.register(ADDON_ID, ({ getCurrentParameter, on, emit, resolveStory }) => {
function getPlaygroundStoryId() {
const { storyId } = getCurrentParameter(ADDON_ID_FOR_PARAMETERS) || {};
return storyId;
}
on(STORY_PREPARED, ({ id: preparedStoryId }) => {
const resolvedStory = resolveStory(getPlaygroundStoryId());
if (preparedStoryId === getStoryId(resolvedStory)) {
emit(PLAYGROUND_STORY_PREPARED);
}
});
addons.add(TOOL_ID, {
type: Addon_TypesEnum.TOOLEXTRA,
title: "", // has no effect, but it is a must-have attr
match: (matchOptions) => !matchOptions?.storyId?.includes?.(getPlaygroundStoryId()),
render: Tool,
});
addons.add(PANEL_ID, {
type: Addon_TypesEnum.PANEL,
title: PanelTitle,
render: Panel,
});
});
//# sourceMappingURL=manager.js.map