diff --git a/package.json b/package.json index 27ea7bf..b7e903f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-devkit", - "version": "1.3.3", + "version": "1.3.4", "description": "Storybook Addon Development Kit", "author": { "name": "Oleg Proskurin", diff --git a/src/index.d.ts b/src/index.d.ts index 9feb69e..312143b 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,8 +1,13 @@ -type Store = { - [key: string]: any -}; +import { types as addonTypes } from '@storybook/addons' +import { API } from '@storybook/api' + +interface Dictionary { + [key: string]: T +} + +type AddonStore = Dictionary; -type Selector = (store: Store) => any; +type Selector = (store: AddonStore) => any; type ParamSelector = (parameters: { [key: string]: any }, selectors: { @@ -11,18 +16,19 @@ type ParamSelector = (parameters: { type ActionDispatcher = (...args: any[]) => void | Promise; type ActionGenerator = ( - action: (store: Store, ...args: any[]) => Store | Promise + action: (store: AddonStore, ...args: any[]) => AddonStore | Promise ) => ActionDispatcher; -type Actions = ({ local: ActionGenerator, global: ActionGenerator }) => { - [key: string]: ActionDispatcher -}; +type Actions = ({ local: ActionGenerator, global: ActionGenerator }) => Dictionary; + +type RegisterOptions = { + type?: addonTypes + initData?: Dictionary +} export declare function register( - storeSelectors: { - [key: string]: Selector - }, - createActions: Actions -): (Component: React.ComponentType) => void; + storeSelectors?: Dictionary, + createActions?: Actions +): (Component: React.ComponentType, options: RegisterOptions) => void; interface StoryContext { @@ -43,18 +49,40 @@ type DecoratorOptions = { isGlobal: boolean, } -export declare function createDecorator(storeSelectors: { - [key: string]: Selector -}, +export declare function createDecorator(storeSelectors?: Dictionary, createActions: Actions, - paramSelectors: { - [key: string]: ParamSelector - } + paramSelectors?: Dictionary< + (parameters: Dictionary, selectors: Dictionary<() => any>) => any + > ): (Component: React.ComponentType, options: DecoratorOptions) => DecoratorFunction; -type AddonParameters = { - [key: string]: any -} +type AddonParameters = Dictionary + export declare function setParameters(): (T) => ({ - addonKey: T + [ConfigValues.PARAM_Key]: T }) + +type ConfigOptions = { + addonId?: string + panelId?: string + panelTitle?: string + paramKey?: string + eventInit?: string + eventData?: string + eventBack?: string +} + +export declare function setConfig(config: ConfigOptions): void + +type ConfigValues = { + ADDON_ID: string + PANEL_ID: string + PANEL_Title: string + PARAM_Key: string + EVENT_ID_INIT: string + EVENT_ID_DATA: string + EVENT_ID_BACK: string +} + +export declare function getConfig(): ConfigValues +