Skip to content

Commit

Permalink
Revert 8.0 changes (#59)
Browse files Browse the repository at this point in the history
These were released as a 7.1 version when they should have been released as 8.0. We need to revert so we can release a fixed 7.1.1 version (like 7.0.2). After that, we'll do another attempt at 8.0.
  • Loading branch information
literalpie authored May 26, 2024
1 parent fd9eafc commit 97492b5
Show file tree
Hide file tree
Showing 17 changed files with 4,952 additions and 4,069 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v2

- name: Prepare repository
run: |
git fetch --unshallow --tags
git config user.name "GitHub Actions Bot"
git config user.email "[email protected]"
- name: Use Node.js 20.x
uses: actions/setup-node@v4
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: 20.x
node-version: 16.x

- name: Install dependencies
uses: bahmutov/npm-install@v1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
name: Core Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '20.x'
node-version: "16.x"
cache: yarn
- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
stories: ["../stories/**/*.stories.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)"],
addons: ["../preset", "@storybook/addon-webpack5-compiler-babel"],
addons: ["../preset"],
framework: {
name: "@storybook/react-webpack5",
options: {}
Expand Down
26 changes: 11 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
"build": "concurrently \"npm run buildBabel\" \"npm run buildTsc\"",
"test": "jest",
"storybook": "storybook dev -p 6006",
"start": "concurrently \"npm run storybook -- --quiet\" \"npm run build -- --watch\"",
"start": "concurrently \"npm run storybook -- --no-manager-cache --quiet\" \"npm run build -- --watch\"",
"build-storybook": "storybook build",
"release": "npm run build && auto shipit"
},
"resolutions": {
"jackspeak": "2.1.1"
},
"dependencies": {
"copy-to-clipboard": "^3.3.3",
"core-js": "^3.29.0",
Expand All @@ -51,36 +48,35 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.0",
"@emotion/jest": "^11.10.5",
"@storybook/addon-webpack5-compiler-babel": "^3.0.0",
"@storybook/components": "^8.0.0",
"@storybook/react": "^8.0.0",
"@storybook/react-webpack5": "^8.0.0",
"@storybook/react": "^7.0.0",
"@storybook/react-webpack5": "^7.0.0",
"@testing-library/dom": "^9.2.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/escape-html": "^1.0.2",
"@types/lodash": "^4.14.191",
"@types/node": "^20.12.12",
"@types/node": "^18.15.11",
"@types/react-lifecycles-compat": "^3.0.1",
"@types/react-select": "^3.1.2",
"@types/webpack-env": "^1.18.0",
"auto": "^11.1.6",
"auto": "^10.43.0",
"chalk": "^5.2.0",
"concurrently": "^7.6.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^4.4.0",
"storybook": "^8.0.0",
"storybook": "^7.0.0",
"typescript": "^4.9.5"
},
"peerDependencies": {
"@storybook/api": "^8.0.0",
"@storybook/components": "^8.0.0",
"@storybook/core-events": "^8.0.0",
"@storybook/theming": "^8.0.0",
"@storybook/addons": "^7.0.0",
"@storybook/api": "^7.0.0",
"@storybook/components": "^7.0.0",
"@storybook/core-events": "^7.0.0",
"@storybook/theming": "^7.0.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
Expand Down
24 changes: 23 additions & 1 deletion src/KnobManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
// navigator exists in Jest but not the browser. global exists in the browser but not Jest
import { navigator as gNavigator, global } from 'global';
import escape from 'escape-html';
import { getQueryParams } from '@storybook/preview-api';
import { Channel } from '@storybook/channels';

import KnobStore, { KnobStoreKnob } from './KnobStore';
import { Knob, KnobType, Mutable } from './type-defs';
import { SET } from './shared';

import { deserializers } from './converters';

const navigator: Navigator = gNavigator || global.navigator;

const knobValuesFromUrl: Record<string, string> = Object.entries(getQueryParams()).reduce(
(acc, [k, v]) => {
if (k.includes('knob-')) {
return { ...acc, [k.replace('knob-', '')]: v };
}
return acc;
},
{}
);

// This is used by _mayCallChannel to determine how long to wait to before triggering a panel update
const PANEL_UPDATE_INTERVAL = 400;

Expand Down Expand Up @@ -92,7 +105,16 @@ export default class KnobManager {
label: name,
};

knobInfo.defaultValue = options.value;
if (knobValuesFromUrl[knobName]) {
const value = deserializers[options.type](knobValuesFromUrl[knobName]);

knobInfo.defaultValue = value;
knobInfo.value = value;

delete knobValuesFromUrl[knobName];
} else {
knobInfo.defaultValue = options.value;
}

knobStore.set(knobName, knobInfo as KnobStoreKnob);
return this.getKnobValue(knobStore.get(knobName));
Expand Down
4 changes: 2 additions & 2 deletions src/components/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Link,
ScrollArea,
} from '@storybook/components';
import { API } from '@storybook/manager-api';
import { API } from '@storybook/api';
import { RESET, SET, CHANGE, SET_OPTIONS, CLICK } from '../shared';

import { getKnobControl } from './types';
Expand Down Expand Up @@ -283,7 +283,7 @@ export default class KnobPanel extends PureComponent<KnobPanelProps> {
<TabsState>
{entries.map(([k, v]) => (
<div id={k} key={k} title={v.title}>
{v.render as unknown as ReactNode}
{v.render}
</div>
))}
</TabsState>
Expand Down
7 changes: 6 additions & 1 deletion src/components/types/Boolean.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const deserialize = (value: string | null) => value === 'true';
const BooleanType: FunctionComponent<BooleanTypeProps> & {
serialize: typeof serialize;
deserialize: typeof deserialize;
} = ({ knob = {} as any, onChange = (value)=>value }) => (
} = ({ knob, onChange }) => (
<Input
id={knob.name}
name={knob.name}
Expand All @@ -39,6 +39,11 @@ const BooleanType: FunctionComponent<BooleanTypeProps> & {
/>
);

BooleanType.defaultProps = {
knob: {} as any,
onChange: (value) => value,
};

BooleanType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
Expand Down
7 changes: 6 additions & 1 deletion src/components/types/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ const deserialize = (): undefined => undefined;
const ButtonType: FunctionComponent<ButtonTypeProps> & {
serialize: typeof serialize;
deserialize: typeof deserialize;
} = ({ knob = {} as any, onClick = ()=>{} }) => (
} = ({ knob, onClick }) => (
<Form.Button type="button" name={knob.name} onClick={() => onClick(knob)}>
{knob.name}
</Form.Button>
);

ButtonType.defaultProps = {
knob: {} as any,
onClick: () => {},
};

ButtonType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
Expand Down
6 changes: 4 additions & 2 deletions src/components/types/Color.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { Component, Validator } from 'react';
import { RgbaStringColorPicker } from 'react-colorful';

import { styled } from '@storybook/theming';
import { Button } from '@storybook/components';
import { Form } from '@storybook/components';
import { KnobControlConfig, KnobControlProps } from './types';

type ColorTypeKnobValue = string;
Expand All @@ -23,6 +23,8 @@ interface ColorButtonProps {
onClick: () => any;
}

const { Button } = Form;

const Swatch = styled.div<{}>(({ theme }) => ({
position: 'absolute',
top: '50%',
Expand Down Expand Up @@ -121,7 +123,7 @@ export default class ColorType extends Component<ColorTypeProps, ColorTypeState>
type="button"
name={knob.name}
onClick={this.handleClick}
size="small"
size="flex"
>
{knob.value && knob.value.toUpperCase()}
<Swatch style={colorStyle} />
Expand Down
7 changes: 6 additions & 1 deletion src/components/types/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const deserialize = (): undefined => undefined;
const FilesType: FunctionComponent<FilesTypeProps> & {
serialize: typeof serialize;
deserialize: typeof deserialize;
} = ({ knob = {} as any, onChange = (value)=>value }) => (
} = ({ knob, onChange }) => (
<FileInput
type="file"
name={knob.name}
Expand All @@ -49,6 +49,11 @@ const FilesType: FunctionComponent<FilesTypeProps> & {
/>
);

FilesType.defaultProps = {
knob: {} as any,
onChange: (value) => value,
};

FilesType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
Expand Down
7 changes: 6 additions & 1 deletion src/components/types/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const OptionsType: FunctionComponent<OptionsTypeProps<any>> & {
serialize: typeof serialize;
deserialize: typeof deserialize;
} = (props) => {
const { knob = {} as any, onChange = (value)=>value } = props;
const { knob, onChange } = props;
const { display } = knob.optionsObj;

if (display === 'check' || display === 'inline-check') {
Expand Down Expand Up @@ -113,6 +113,11 @@ const OptionsType: FunctionComponent<OptionsTypeProps<any>> & {
return null;
};

OptionsType.defaultProps = {
knob: {} as any,
display: 'select',
onChange: (value) => value,
};

OptionsType.propTypes = {
knob: PropTypes.shape({
Expand Down
7 changes: 6 additions & 1 deletion src/components/types/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const deserialize = (value: SelectTypeKnobValue) => value;
const SelectType: FunctionComponent<SelectTypeProps> & {
serialize: typeof serialize;
deserialize: typeof deserialize;
} = ({ knob = {} as any, onChange = (value)=>value }) => {
} = ({ knob, onChange }) => {
const { options } = knob;

const callbackReduceArrayOptions = (acc: any, option: any, i: number) => {
Expand Down Expand Up @@ -67,6 +67,11 @@ const SelectType: FunctionComponent<SelectTypeProps> & {
);
};

SelectType.defaultProps = {
knob: {} as any,
onChange: (value) => value,
};

SelectType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeDecorator, addons } from '@storybook/preview-api';
import { makeDecorator, addons } from '@storybook/addons';

import { SET_OPTIONS } from './shared';
import { manager, registerKnobs } from './registerKnobs';
Expand Down
7 changes: 3 additions & 4 deletions src/register.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as React from 'react';
import { addons, types } from '@storybook/manager-api';
import { addons } from '@storybook/addons';
import Panel from './components/Panel';
import { ADDON_ID, PANEL_ID, PARAM_KEY } from './shared';
import { createTitleListener } from './title';

addons.register(ADDON_ID, (api) => {
addons.add(PANEL_ID, {
type: types.PANEL,
addons.addPanel(PANEL_ID, {
title: createTitleListener(api),
render: ({ active }) => <Panel api={api} active={active} />,
render: ({ active, key }) => <Panel api={api} key={key} active={active} />,
paramKey: PARAM_KEY,
});
});
3 changes: 2 additions & 1 deletion src/registerKnobs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, addons } from '@storybook/preview-api';
import { addons } from '@storybook/addons';
import { useEffect } from '@storybook/preview-api';
import { STORY_CHANGED, FORCE_RE_RENDER } from '@storybook/core-events';
import debounce from 'lodash/debounce';

Expand Down
2 changes: 1 addition & 1 deletion src/title.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API } from '@storybook/manager-api';
import { API } from '@storybook/api';
import { SET } from './shared';
import { KnobStoreKnob } from './KnobStore';

Expand Down
Loading

0 comments on commit 97492b5

Please sign in to comment.