Skip to content

Commit

Permalink
undo deprecations removal (will do this in a separate branch so it ca…
Browse files Browse the repository at this point in the history
…n be reviewed
  • Loading branch information
ndelangen committed Jun 10, 2022
1 parent aed959e commit 982a694
Show file tree
Hide file tree
Showing 97 changed files with 890 additions and 66 deletions.
1 change: 1 addition & 0 deletions addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"global": "^4.4.0",
"lodash": "^4.17.21",
"react-sizeme": "^3.0.1",
"regenerator-runtime": "^0.13.7",
"ts-dedent": "^2.0.0",
"util-deprecate": "^1.0.2"
},
Expand Down
19 changes: 19 additions & 0 deletions addons/a11y/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import type { AnyFramework, DecoratorFunction } from '@storybook/csf';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';

export { PARAM_KEY } from './constants';
export * from './highlight';
export * from './params';

if (module && module.hot && module.hot.decline) {
module.hot.decline();
}

export const withA11y: DecoratorFunction<AnyFramework> = deprecate(
(storyFn, storyContext) => {
return storyFn(storyContext);
},
dedent`
withA11y(options) is deprecated, please configure addon-a11y using the addParameter api:
addParameters({
a11y: options,
});
More at: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#removed-witha11y-decorator
`
);
1 change: 1 addition & 0 deletions addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"polished": "^4.2.2",
"prop-types": "^15.7.2",
"react-inspector": "^5.1.0",
"regenerator-runtime": "^0.13.7",
"telejson": "^6.0.8",
"ts-dedent": "^2.0.0",
"util-deprecate": "^1.0.2",
Expand Down
3 changes: 3 additions & 0 deletions addons/actions/src/preset/addDecorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { withActions } from '../index';

export const decorators = [withActions];
1 change: 1 addition & 0 deletions addons/actions/src/preset/preview.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './addDecorator';
export * from './addArgs';
37 changes: 37 additions & 0 deletions addons/actions/src/preview/decorateAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';

import { DecoratorFunction } from '../models';

export const decorateAction = (_decorators: DecoratorFunction[]) => {
return deprecate(
() => {},
dedent`
decorateAction is no longer supported as of Storybook 6.0.
`
);
};

const deprecatedCallback = deprecate(() => {},
'decorate.* is no longer supported as of Storybook 6.0.');

export const decorate = (_decorators: DecoratorFunction[]) => {
return deprecate(
() => {
return {
action: deprecatedCallback,
actions: deprecatedCallback,
withActions: deprecatedCallback,
};
},
dedent`
decorate is deprecated, please configure addon-actions using the addParameter api:
addParameters({
actions: {
handles: options
},
});
`
);
};
2 changes: 2 additions & 0 deletions addons/actions/src/preview/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './action';
export * from './actions';
export * from './configureActions';
export * from './decorateAction';
export * from './withActions';
88 changes: 88 additions & 0 deletions addons/actions/src/preview/withActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Based on http://backbonejs.org/docs/backbone.html#section-164
import global from 'global';
import { useEffect, makeDecorator } from '@storybook/addons';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';

import { actions } from './actions';

import { PARAM_KEY } from '../constants';

const { document, Element } = global;

const delegateEventSplitter = /^(\S+)\s*(.*)$/;

const isIE = Element != null && !Element.prototype.matches;
const matchesMethod = isIE ? 'msMatchesSelector' : 'matches';

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

const hasMatchInAncestry = (element: any, selector: any): boolean => {
if (element[matchesMethod](selector)) {
return true;
}
const parent = element.parentElement;
if (!parent) {
return false;
}
return hasMatchInAncestry(parent, selector);
};

const createHandlers = (actionsFn: (...arg: any[]) => object, ...handles: any[]) => {
const actionsObject = actionsFn(...handles);
return Object.entries(actionsObject).map(([key, action]) => {
const [_, eventName, selector] = key.match(delegateEventSplitter);
return {
eventName,
handler: (e: { target: any }) => {
if (!selector || hasMatchInAncestry(e.target, selector)) {
action(e);
}
},
};
});
};

const applyEventHandlers = deprecate(
(actionsFn: any, ...handles: any[]) => {
useEffect(() => {
if (root != null) {
const handlers = createHandlers(actionsFn, ...handles);
handlers.forEach(({ eventName, handler }) => root.addEventListener(eventName, handler));
return () =>
handlers.forEach(({ eventName, handler }) =>
root.removeEventListener(eventName, handler)
);
}
return undefined;
}, [root, actionsFn, handles]);
},
dedent`
withActions(options) is deprecated, please configure addon-actions using the addParameter api:
addParameters({
actions: {
handles: options
},
});
`
);

const applyDeprecatedOptions = (actionsFn: any, options: any[]) => {
if (options) {
applyEventHandlers(actionsFn, options);
}
};

export const withActions = makeDecorator({
name: 'withActions',
parameterName: PARAM_KEY,
skipIfNoParametersOrOptions: true,
wrapper: (getStory, context, { parameters, options }) => {
applyDeprecatedOptions(actions, options as any[]);

if (parameters && parameters.handles) applyEventHandlers(actions, ...parameters.handles);

return getStory(context);
},
});
1 change: 1 addition & 0 deletions addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"core-js": "^3.8.2",
"global": "^4.4.0",
"memoizerific": "^1.11.3",
"regenerator-runtime": "^0.13.7",
"ts-dedent": "^2.0.0",
"util-deprecate": "^1.0.2"
},
Expand Down
20 changes: 19 additions & 1 deletion addons/backgrounds/src/decorators/withGrid.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import dedent from 'ts-dedent';
import deprecate from 'util-deprecate';
import { useMemo, useEffect } from '@storybook/addons';
import type { AnyFramework, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/csf';

import { clearStyles, addGridStyle } from '../helpers';
import { PARAM_KEY as BACKGROUNDS_PARAM_KEY } from '../constants';

const deprecatedCellSizeWarning = deprecate(
() => {},
dedent`
Backgrounds Addon: The cell size parameter has been changed.
- parameters.grid.cellSize should now be parameters.backgrounds.grid.cellSize
See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-grid-parameter
`
);

export const withGrid = (
StoryFn: StoryFunction<AnyFramework>,
context: StoryContext<AnyFramework>
Expand All @@ -14,7 +26,13 @@ export const withGrid = (
const { cellAmount, cellSize, opacity } = gridParameters;
const isInDocs = context.viewMode === 'docs';

const gridSize: number = cellSize;
let gridSize: number;
if (parameters.grid?.cellSize) {
gridSize = parameters.grid.cellSize;
deprecatedCellSizeWarning();
} else {
gridSize = cellSize;
}

const isLayoutPadded = parameters.layout === undefined || parameters.layout === 'padded';
// 16px offset in the grid to account for padded layout
Expand Down
2 changes: 2 additions & 0 deletions addons/docs/blocks.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ColorPalette, ColorItem, IconGallery, IconItem, Typeset } from '@storybook/components';
export * from './dist/types/blocks/index.d';
14 changes: 14 additions & 0 deletions addons/docs/blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';

const warnBlocksImport = deprecate(
() => {},
dedent`
Importing from '@storybook/addon-docs/blocks' is deprecated, import directly from '@storybook/addon-docs' instead:
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-scoped-blocks-imports
`
);
warnBlocksImport();

export * from './dist/esm/blocks';
1 change: 1 addition & 0 deletions addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"fast-deep-equal": "^3.1.3",
"global": "^4.4.0",
"lodash": "^4.17.21",
"regenerator-runtime": "^0.13.7",
"remark-external-links": "^8.0.0",
"remark-slug": "^6.0.0",
"ts-dedent": "^2.0.0",
Expand Down
20 changes: 17 additions & 3 deletions addons/docs/src/blocks/DocsContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { FunctionComponent, useEffect } from 'react';
import global from 'global';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';
import { MDXProvider } from '@mdx-js/react';
import { ThemeProvider, ensure as ensureTheme } from '@storybook/theming';
import { DocsWrapper, DocsContent, components as htmlComponents } from '@storybook/components';
Expand All @@ -24,13 +26,25 @@ const defaultComponents = {
...HeadersMdx,
};

const warnOptionsTheme = deprecate(
() => {},
dedent`
Deprecated parameter: options.theme => docs.theme
https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/theming.md#storybook-theming
`
);

export const DocsContainer: FunctionComponent<DocsContainerProps> = ({ context, children }) => {
const { id: storyId, storyById } = context;
const {
parameters: { docs = {} },
parameters: { options = {}, docs = {} },
} = storyById(storyId);
const themeVars = docs.theme;

let themeVars = docs.theme;
if (!themeVars && options.theme) {
warnOptionsTheme();
themeVars = options.theme;
}
const theme = ensureTheme(themeVars);
const allComponents = { ...defaultComponents, ...docs.components };

Expand Down
15 changes: 15 additions & 0 deletions addons/docs/src/blocks/DocsStory.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import React, { FunctionComponent } from 'react';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';
import { Subheading } from './Subheading';
import { DocsStoryProps } from './types';
import { Anchor } from './Anchor';
import { Description } from './Description';
import { Story } from './Story';
import { Canvas } from './Canvas';

const warnStoryDescription = deprecate(
() => {},
dedent`
Deprecated parameter: docs.storyDescription => docs.description.story
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#docs-description-parameter
`
);

export const DocsStory: FunctionComponent<DocsStoryProps> = ({
id,
name,
Expand All @@ -17,6 +28,10 @@ export const DocsStory: FunctionComponent<DocsStoryProps> = ({
const { docs } = parameters;
if (expanded && docs) {
description = docs.description?.story;
if (!description) {
description = docs.storyDescription;
if (description) warnStoryDescription();
}
}

const subheading = expanded && name;
Expand Down
13 changes: 13 additions & 0 deletions addons/docs/src/blocks/Preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { ComponentProps } from 'react';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';
import { Canvas } from './Canvas';

export const Preview = deprecate(
(props: ComponentProps<typeof Canvas>) => <Canvas {...props} />,
dedent`
Preview doc block has been renamed to Canvas.
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#previewprops-renamed
`
);
19 changes: 19 additions & 0 deletions addons/docs/src/blocks/Props.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { ComponentProps } from 'react';
import deprecate from 'util-deprecate';
import dedent from 'ts-dedent';
import { ArgsTable } from './ArgsTable';
import { CURRENT_SELECTION } from './types';

export const Props = deprecate(
(props: ComponentProps<typeof ArgsTable>) => <ArgsTable {...props} />,
dedent`
Props doc block has been renamed to ArgsTable.
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#previewprops-renamed
`
);

// @ts-ignore
Props.defaultProps = {
of: CURRENT_SELECTION,
};
2 changes: 2 additions & 0 deletions addons/docs/src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export * from './DocsContainer';
export * from './DocsStory';
export * from './Heading';
export * from './Meta';
export * from './Preview';
export * from './Primary';
export * from './Props';
export * from './Source';
export * from './SourceContainer';
export * from './Stories';
Expand Down
1 change: 1 addition & 0 deletions addons/essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@storybook/core-common": "7.0.0-alpha.1",
"@storybook/node-logger": "7.0.0-alpha.1",
"core-js": "^3.8.2",
"regenerator-runtime": "^0.13.7",
"ts-dedent": "^2.0.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions addons/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"core-js": "^3.8.2",
"global": "^4.4.0",
"react-sizeme": "^3.0.1",
"regenerator-runtime": "^0.13.7",
"upath": "^1.2.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"core-js": "^3.8.2",
"global": "^4.4.0",
"prop-types": "^15.7.2",
"regenerator-runtime": "^0.13.7",
"ts-dedent": "^2.0.0"
},
"peerDependencies": {
Expand Down
Loading

0 comments on commit 982a694

Please sign in to comment.