From aaf78daae92b35ff4f9b2a7535a0a6139342490b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Fri, 9 Nov 2018 14:38:25 +0100 Subject: [PATCH 01/29] First poc approach with addon-notes --- addons/notes/package.json | 4 ++ .../src/__tests__/{index.js => index.ts} | 0 addons/notes/src/{index.js => index.ts} | 8 ++- addons/notes/src/react.js | 23 -------- addons/notes/src/react.ts | 22 +++++++ .../notes/src/{register.js => register.tsx} | 59 +++++++++++-------- addons/notes/tsconfig.json | 26 ++++++++ tsconfig.json | 10 +++- yarn.lock | 18 ++++++ 9 files changed, 121 insertions(+), 49 deletions(-) rename addons/notes/src/__tests__/{index.js => index.ts} (100%) rename addons/notes/src/{index.js => index.ts} (83%) delete mode 100644 addons/notes/src/react.js create mode 100644 addons/notes/src/react.ts rename addons/notes/src/{register.js => register.tsx} (58%) create mode 100644 addons/notes/tsconfig.json diff --git a/addons/notes/package.json b/addons/notes/package.json index e96f72fddc45..648cc88e039e 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -30,6 +30,10 @@ "marked": "^0.5.1", "prop-types": "^15.6.2" }, + "devDependencies": { + "@types/jest": "^23.3.9", + "@types/react": "^16.7.1" + }, "peerDependencies": { "react": "*" } diff --git a/addons/notes/src/__tests__/index.js b/addons/notes/src/__tests__/index.ts similarity index 100% rename from addons/notes/src/__tests__/index.js rename to addons/notes/src/__tests__/index.ts diff --git a/addons/notes/src/index.js b/addons/notes/src/index.ts similarity index 83% rename from addons/notes/src/index.js rename to addons/notes/src/index.ts index b05b21263f6a..34775c4e41d4 100644 --- a/addons/notes/src/index.js +++ b/addons/notes/src/index.ts @@ -16,7 +16,13 @@ export const withNotes = makeDecorator({ const storyOptions = parameters || options; const { text, markdown, markdownOptions } = - typeof storyOptions === 'string' ? { text: storyOptions } : storyOptions; + typeof storyOptions === 'string' + ? { + text: storyOptions, + markdown: undefined, + markdownOptions: undefined, + } + : storyOptions; if (!text && !markdown) { throw new Error('You must set of one of `text` or `markdown` on the `notes` parameter'); diff --git a/addons/notes/src/react.js b/addons/notes/src/react.js deleted file mode 100644 index 4d01226d81dd..000000000000 --- a/addons/notes/src/react.js +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import addons from '@storybook/addons'; - -export class WithNotes extends React.Component { - render() { - const { children, notes } = this.props; - const channel = addons.getChannel(); - - channel.emit('storybook/notes/add_notes', notes); - - return children; - } -} - -WithNotes.propTypes = { - children: PropTypes.node, - notes: PropTypes.string, -}; -WithNotes.defaultProps = { - children: null, - notes: '', -}; diff --git a/addons/notes/src/react.ts b/addons/notes/src/react.ts new file mode 100644 index 000000000000..28c9b2c18e43 --- /dev/null +++ b/addons/notes/src/react.ts @@ -0,0 +1,22 @@ +import * as React from 'react'; +import addons from '@storybook/addons'; + +interface WithNotesProps { + notes: string; +} + +export class WithNotes extends React.Component { + static defaultProps: WithNotesProps = { + notes: '', + // todo might need to add children: null and type that + }; + + render() { + const { children, notes } = this.props; + const channel = addons.getChannel(); + + channel.emit('storybook/notes/add_notes', notes); + + return children; + } +} diff --git a/addons/notes/src/register.js b/addons/notes/src/register.tsx similarity index 58% rename from addons/notes/src/register.js rename to addons/notes/src/register.tsx index 844323817448..1798eb54fa5d 100644 --- a/addons/notes/src/register.js +++ b/addons/notes/src/register.tsx @@ -1,18 +1,44 @@ -import React from 'react'; -import PropTypes from 'prop-types'; +import * as React from 'react'; import addons from '@storybook/addons'; import styled from '@emotion/styled'; +interface NotesChannel { + on: (listener: string, callback: (text: string) => void) => any; // todo check correct return value definition + emit: any; // todo check correct definition + removeListener: (listener: string, callback: (text: string) => void) => void; +} + +interface NotesApi { + onStory: (callback: () => void) => void; + getQueryParam: any; // todo check correct definition + setQueryParams: any; // todo check correct definition +} + +interface NotesProps { + active: boolean; + channel: NotesChannel; + api: NotesApi; +} + +interface NotesState { + text: string; +} + const Panel = styled.div({ padding: 10, boxSizing: 'border-box', - width: '100%', + width: '100%' }); -export class Notes extends React.Component { - constructor(...args) { - super(...args); +export class Notes extends React.Component { + + // todo check how react typescript does this, especially unmounted + stopListeningOnStory: any; // todo check correct definition + unmounted: any; // todo check correct definition + + constructor(...args: any) { + super(args /* todo: This was ...args before, check if this was a bug */); this.state = { text: '' }; this.onAddNotes = this.onAddNotes.bind(this); } @@ -48,9 +74,9 @@ export class Notes extends React.Component { const { text } = this.state; const textAfterFormatted = text ? text - .trim() - .replace(/(<\S+.*>)\n/g, '$1') - .replace(/\n/g, '
') + .trim() + .replace(/(<\S+.*>)\n/g, '$1') + .replace(/\n/g, '
') : ''; return active ? ( @@ -62,25 +88,12 @@ export class Notes extends React.Component { } } -Notes.propTypes = { - active: PropTypes.bool.isRequired, - channel: PropTypes.shape({ - on: PropTypes.func, - emit: PropTypes.func, - removeListener: PropTypes.func, - }).isRequired, - api: PropTypes.shape({ - onStory: PropTypes.func, - getQueryParam: PropTypes.func, - setQueryParams: PropTypes.func, - }).isRequired, -}; addons.register('storybook/notes', api => { const channel = addons.getChannel(); addons.addPanel('storybook/notes/panel', { title: 'Notes', // eslint-disable-next-line react/prop-types - render: ({ active }) => , + render: ({ active }) => }); }); diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json new file mode 100644 index 000000000000..45c333812ab4 --- /dev/null +++ b/addons/notes/tsconfig.json @@ -0,0 +1,26 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "target": "es2015", + "module": "es2015", + "moduleResolution": "node", + "declaration": true, + "sourceMap": false, + "jsx": "react", + "inlineSources": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "importHelpers": true, + "types": [ + "jest" + ], + "lib": [ + "dom", + "es2015" + ] + }, + "exclude": [ + "__tests__/**/*" + ] +} diff --git a/tsconfig.json b/tsconfig.json index c10e37b0ffc6..77cec09cfa14 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,20 @@ { "compileOnSave": false, "compilerOptions": { + "baseUrl": ".", "emitDecoratorMetadata": true, "experimentalDecorators": true, "skipLibCheck": true, - "noImplicitAny": true, + "noImplicitAny": false, "target": "es5", "lib": [ "es2016", "dom" - ] + ], + "paths": { + "@storybook/addons": [ + "lib/addons/dist/index.js" + ] + } } } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 6aeb50da7050..7c9480fdcca4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2034,11 +2034,24 @@ dependencies: "@types/node" "*" +"@types/prop-types@*": + version "15.5.6" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.6.tgz#9c03d3fed70a8d517c191b7734da2879b50ca26c" + integrity sha512-ZBFR7TROLVzCkswA3Fmqq+IIJt62/T7aY/Dmz+QkU7CaW2QFqAitCE8Ups7IzmGhcN1YWMBT4Qcoc07jU9hOJQ== + "@types/q@^0.0.32": version "0.0.32" resolved "https://registry.yarnpkg.com/@types/q/-/q-0.0.32.tgz#bd284e57c84f1325da702babfc82a5328190c0c5" integrity sha1-vShOV8hPEyXacCur/IKlMoGQwMU= +"@types/react@^16.7.1": + version "16.7.1" + resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.1.tgz#ae76b653d1d7d26b32186bba33c39745316bcdc4" + integrity sha512-kxde2oP2JvHiEXiAfb8WkL+8Aa9txDRD7L8zb3BipMNRoBbcr32xy/kfpbxmWMus71yXgJDqBgLmWil6UXdLzQ== + dependencies: + "@types/prop-types" "*" + csstype "^2.2.0" + "@types/selenium-webdriver@^3.0.0": version "3.0.12" resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.12.tgz#6affe5aed1ba379175075a889adbe2bc3aa62159" @@ -7326,6 +7339,11 @@ cssstyle@^1.0.0, cssstyle@^1.1.1: dependencies: cssom "0.3.x" +csstype@^2.2.0: + version "2.5.7" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.7.tgz#bf9235d5872141eccfb2d16d82993c6b149179ff" + integrity sha512-Nt5VDyOTIIV4/nRFswoCKps1R5CD1hkiyjBE9/thNaNZILLEviVw9yWQw15+O+CpNjQKB/uvdcxFFOrSflY3Yw== + csurf@~1.8.3: version "1.8.3" resolved "https://registry.yarnpkg.com/csurf/-/csurf-1.8.3.tgz#23f2a13bf1d8fce1d0c996588394442cba86a56a" From c51d7c8950eefc5dd652ef3d1a0a1978d0e48d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sat, 10 Nov 2018 10:34:56 +0100 Subject: [PATCH 02/29] Tsconfig configuration update --- addons/notes/tsconfig.json | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json index 45c333812ab4..c499339a6763 100644 --- a/addons/notes/tsconfig.json +++ b/addons/notes/tsconfig.json @@ -1,26 +1,18 @@ { "extends": "../../tsconfig.json", + "compileOnSave": false, "compilerOptions": { - "outDir": "dist", - "target": "es2015", - "module": "es2015", - "moduleResolution": "node", - "declaration": true, - "sourceMap": false, + "rootDir": "./src", "jsx": "react", - "inlineSources": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "importHelpers": true, "types": [ "jest" - ], - "lib": [ - "dom", - "es2015" ] }, + "include": [ + "src/**/*.ts", + "src/**/*.tsx" + ], "exclude": [ - "__tests__/**/*" + "src/__tests__/**/*" ] } From 6dc5f05559a910401495c1b5c3a9bcd63e2c64ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sat, 10 Nov 2018 11:32:11 +0100 Subject: [PATCH 03/29] Added public_api entry point Changed file names for being more clear --- addons/notes/package.json | 2 +- addons/notes/src/{react.ts => addon-react.ts} | 0 addons/notes/src/{index.ts => addon.ts} | 0 addons/notes/src/public_api.ts | 3 +++ 4 files changed, 4 insertions(+), 1 deletion(-) rename addons/notes/src/{react.ts => addon-react.ts} (100%) rename addons/notes/src/{index.ts => addon.ts} (100%) create mode 100644 addons/notes/src/public_api.ts diff --git a/addons/notes/package.json b/addons/notes/package.json index 648cc88e039e..815b96200bb2 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -19,7 +19,7 @@ "url": "https://github.com/storybooks/storybook.git" }, "license": "MIT", - "main": "dist/index.js", + "main": "dist/public_api.js", "jsnext:main": "src/index.js", "scripts": { "prepare": "node ../../scripts/prepare.js" diff --git a/addons/notes/src/react.ts b/addons/notes/src/addon-react.ts similarity index 100% rename from addons/notes/src/react.ts rename to addons/notes/src/addon-react.ts diff --git a/addons/notes/src/index.ts b/addons/notes/src/addon.ts similarity index 100% rename from addons/notes/src/index.ts rename to addons/notes/src/addon.ts diff --git a/addons/notes/src/public_api.ts b/addons/notes/src/public_api.ts new file mode 100644 index 000000000000..051c813a90c2 --- /dev/null +++ b/addons/notes/src/public_api.ts @@ -0,0 +1,3 @@ +export * from './addon'; +export * from './addon-react'; +export * from './register'; From 8891dd4957d2391f7a26c7f5343fe4da39baef98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 11 Nov 2018 11:10:36 +0100 Subject: [PATCH 04/29] Removed addon-react since it's not used anymore Added 'types' file path in package.json Moved addon-notes tsconfig configurations into the root tsconfig --- addons/notes/package.json | 1 + addons/notes/src/addon-react.ts | 22 ---------------------- addons/notes/src/public_api.ts | 2 -- addons/notes/tsconfig.json | 5 +---- tsconfig.json | 11 +++++------ 5 files changed, 7 insertions(+), 34 deletions(-) delete mode 100644 addons/notes/src/addon-react.ts diff --git a/addons/notes/package.json b/addons/notes/package.json index 815b96200bb2..76d45a3e758c 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -20,6 +20,7 @@ }, "license": "MIT", "main": "dist/public_api.js", + "types": "dist/public_api.d.ts", "jsnext:main": "src/index.js", "scripts": { "prepare": "node ../../scripts/prepare.js" diff --git a/addons/notes/src/addon-react.ts b/addons/notes/src/addon-react.ts deleted file mode 100644 index 28c9b2c18e43..000000000000 --- a/addons/notes/src/addon-react.ts +++ /dev/null @@ -1,22 +0,0 @@ -import * as React from 'react'; -import addons from '@storybook/addons'; - -interface WithNotesProps { - notes: string; -} - -export class WithNotes extends React.Component { - static defaultProps: WithNotesProps = { - notes: '', - // todo might need to add children: null and type that - }; - - render() { - const { children, notes } = this.props; - const channel = addons.getChannel(); - - channel.emit('storybook/notes/add_notes', notes); - - return children; - } -} diff --git a/addons/notes/src/public_api.ts b/addons/notes/src/public_api.ts index 051c813a90c2..9762837e93f9 100644 --- a/addons/notes/src/public_api.ts +++ b/addons/notes/src/public_api.ts @@ -1,3 +1 @@ export * from './addon'; -export * from './addon-react'; -export * from './register'; diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json index c499339a6763..94fe326ea096 100644 --- a/addons/notes/tsconfig.json +++ b/addons/notes/tsconfig.json @@ -1,12 +1,9 @@ { "extends": "../../tsconfig.json", - "compileOnSave": false, "compilerOptions": { "rootDir": "./src", "jsx": "react", - "types": [ - "jest" - ] + "module": "commonjs" }, "include": [ "src/**/*.ts", diff --git a/tsconfig.json b/tsconfig.json index 77cec09cfa14..810ca311fcdf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,19 +2,18 @@ "compileOnSave": false, "compilerOptions": { "baseUrl": ".", + "declaration": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "skipLibCheck": true, "noImplicitAny": false, "target": "es5", + "types": [ + "jest" + ], "lib": [ "es2016", "dom" - ], - "paths": { - "@storybook/addons": [ - "lib/addons/dist/index.js" - ] - } + ] } } \ No newline at end of file From dca0f7d64d67f896ec4f35b6d47f9a391adcde23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 11 Nov 2018 11:11:34 +0100 Subject: [PATCH 05/29] Fixed import for addon-notes test file --- addons/notes/src/__tests__/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/notes/src/__tests__/index.ts b/addons/notes/src/__tests__/index.ts index 836a8140cd82..5b8b5472abbc 100644 --- a/addons/notes/src/__tests__/index.ts +++ b/addons/notes/src/__tests__/index.ts @@ -1,5 +1,5 @@ import addons from '@storybook/addons'; -import { withNotes } from '..'; +import { withNotes } from '../addon'; addons.getChannel = jest.fn(); From 3bf2c8ac65f4cea2b8d24ea880852077316ce937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 11 Nov 2018 15:16:26 +0100 Subject: [PATCH 06/29] Added @types/node for allowing the use of 'module' --- package.json | 1 + tsconfig.json | 1 + yarn.lock | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/package.json b/package.json index fd4881068367..59f705ef1edf 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "@babel/preset-react": "^7.0.0", "@babel/runtime": "^7.1.2", "@emotion/snapshot-serializer": "0.8.2", + "@types/node": "^10.12.5", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "^10.0.1", "babel-jest": "^23.6.0", diff --git a/tsconfig.json b/tsconfig.json index 810ca311fcdf..8eb33af0bf73 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "noImplicitAny": false, "target": "es5", "types": [ + "node", "jest" ], "lib": [ diff --git a/yarn.lock b/yarn.lock index 7c9480fdcca4..26e62101d041 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2022,6 +2022,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.1.tgz#da61b64a2930a80fa708e57c45cd5441eb379d5b" integrity sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ== +"@types/node@^10.12.5": + version "10.12.5" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.5.tgz#7e7ea1a9b34d2c8d704cb0b755dffbcda34741ad" + integrity sha512-GzdHjq3t3eGLMv92Al90Iq+EoLL+86mPfQhuglbBFO7HiLdC/rkt+zrzJJumAiBF6nsrBWhou22rPW663AAyFw== + "@types/node@^6.0.0", "@types/node@^6.0.46": version "6.14.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-6.14.0.tgz#85c6998293fc6f2945915419296c7fbb63384f66" From 558da37c7019166a9de5db7574f059def41e835c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 11 Nov 2018 16:00:36 +0100 Subject: [PATCH 07/29] fixed jsnext:main path --- addons/notes/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/notes/package.json b/addons/notes/package.json index 76d45a3e758c..e742b7b6ff83 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -21,7 +21,7 @@ "license": "MIT", "main": "dist/public_api.js", "types": "dist/public_api.d.ts", - "jsnext:main": "src/index.js", + "jsnext:main": "src/public_api.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, From 6823d7888d6c1d26f9ce6ffe1477d7d89270ff7b Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 11 Nov 2018 22:21:43 +0100 Subject: [PATCH 08/29] removed prop-types, they are not needed anymore moved types to the root package.json --- addons/notes/package.json | 7 +------ addons/notes/src/register.tsx | 5 ++--- package.json | 2 ++ yarn.lock | 8 ++++---- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/addons/notes/package.json b/addons/notes/package.json index e742b7b6ff83..4168cf6eb6bc 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -28,12 +28,7 @@ "dependencies": { "@emotion/styled": "^0.10.6", "@storybook/addons": "4.1.0-alpha.1", - "marked": "^0.5.1", - "prop-types": "^15.6.2" - }, - "devDependencies": { - "@types/jest": "^23.3.9", - "@types/react": "^16.7.1" + "marked": "^0.5.1" }, "peerDependencies": { "react": "*" diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index 1798eb54fa5d..077d31053324 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -28,7 +28,7 @@ interface NotesState { const Panel = styled.div({ padding: 10, boxSizing: 'border-box', - width: '100%' + width: '100%', }); export class Notes extends React.Component { @@ -93,7 +93,6 @@ addons.register('storybook/notes', api => { const channel = addons.getChannel(); addons.addPanel('storybook/notes/panel', { title: 'Notes', - // eslint-disable-next-line react/prop-types - render: ({ active }) => + render: ({ active }) => , }); }); diff --git a/package.json b/package.json index 59f705ef1edf..56378738e20a 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,9 @@ "@babel/preset-react": "^7.0.0", "@babel/runtime": "^7.1.2", "@emotion/snapshot-serializer": "0.8.2", + "@types/jest": "^23.3.9", "@types/node": "^10.12.5", + "@types/react": "^16.7.3", "babel-core": "^7.0.0-bridge.0", "babel-eslint": "^10.0.1", "babel-jest": "^23.6.0", diff --git a/yarn.lock b/yarn.lock index 26e62101d041..6065946bae3f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2049,10 +2049,10 @@ resolved "https://registry.yarnpkg.com/@types/q/-/q-0.0.32.tgz#bd284e57c84f1325da702babfc82a5328190c0c5" integrity sha1-vShOV8hPEyXacCur/IKlMoGQwMU= -"@types/react@^16.7.1": - version "16.7.1" - resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.1.tgz#ae76b653d1d7d26b32186bba33c39745316bcdc4" - integrity sha512-kxde2oP2JvHiEXiAfb8WkL+8Aa9txDRD7L8zb3BipMNRoBbcr32xy/kfpbxmWMus71yXgJDqBgLmWil6UXdLzQ== +"@types/react@^16.7.3": + version "16.7.3" + resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.3.tgz#dd96b19b21c450fab7d136f71d48f4b8fc72777e" + integrity sha512-ve/2lnXuLNaTDR1SPvsEX25m+NoNW3PMJxL2jd372UR8oJPwR5+jgtcheUoN27O+qKLFmQy0y0YKRwZcwtny3w== dependencies: "@types/prop-types" "*" csstype "^2.2.0" From b51f8d1d5db8783a845064bf09a58bdd59f81525 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 11 Nov 2018 22:32:12 +0100 Subject: [PATCH 09/29] Moved addon tsconfig configuration to root tsconfig --- addons/notes/tsconfig.json | 4 +--- tsconfig.json | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json index 94fe326ea096..91baa3e9a3ac 100644 --- a/addons/notes/tsconfig.json +++ b/addons/notes/tsconfig.json @@ -1,9 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "rootDir": "./src", - "jsx": "react", - "module": "commonjs" + "rootDir": "./src" }, "include": [ "src/**/*.ts", diff --git a/tsconfig.json b/tsconfig.json index 8eb33af0bf73..01184e383ca6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,8 @@ "experimentalDecorators": true, "skipLibCheck": true, "noImplicitAny": false, + "jsx": "react", + "module": "commonjs", "target": "es5", "types": [ "node", From d37fcf6c2c061f4f68cba3702809220930c9e037 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 11 Nov 2018 22:37:20 +0100 Subject: [PATCH 10/29] Added default export, might fix CI --- addons/notes/src/addon.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/notes/src/addon.ts b/addons/notes/src/addon.ts index 34775c4e41d4..2ff6bb0d7a5e 100644 --- a/addons/notes/src/addon.ts +++ b/addons/notes/src/addon.ts @@ -39,3 +39,5 @@ export const withMarkdownNotes = (text, options) => markdown: text, markdownOptions: options, }); + +export default withNotes; From 5e84f3bd8f9c88ca9b9a271d57fd011b15a293b4 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 11 Nov 2018 23:24:51 +0100 Subject: [PATCH 11/29] Added marked types and updated marked implementation --- addons/notes/package.json | 3 +++ addons/notes/src/addon.ts | 10 +++++----- yarn.lock | 5 +++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/notes/package.json b/addons/notes/package.json index 4168cf6eb6bc..0393ba4b6a7d 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -30,6 +30,9 @@ "@storybook/addons": "4.1.0-alpha.1", "marked": "^0.5.1" }, + "devDependencies": { + "@types/marked": "^0.4.2" + }, "peerDependencies": { "react": "*" } diff --git a/addons/notes/src/addon.ts b/addons/notes/src/addon.ts index 2ff6bb0d7a5e..6adaaf065924 100644 --- a/addons/notes/src/addon.ts +++ b/addons/notes/src/addon.ts @@ -1,8 +1,10 @@ import addons, { makeDecorator } from '@storybook/addons'; -import marked from 'marked'; +import { MarkedOptions, parse as marked } from 'marked'; -function renderMarkdown(text, options) { - return marked(text, { ...marked.defaults, ...options }); +// todo why not just calling marked directly instead of wrapping it? +// todo removed { marked.defaults, options } merge. I believe this was not necessary, have to check +function renderMarkdown(text: string, options?: MarkedOptions) { + return marked(text, options); } export const withNotes = makeDecorator({ @@ -39,5 +41,3 @@ export const withMarkdownNotes = (text, options) => markdown: text, markdownOptions: options, }); - -export default withNotes; diff --git a/yarn.lock b/yarn.lock index 6065946bae3f..ae599f25154b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2017,6 +2017,11 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= +"@types/marked@^0.4.2": + version "0.4.2" + resolved "https://registry.yarnpkg.com/@types/marked/-/marked-0.4.2.tgz#64a89e53ea37f61cc0f3ee1732c555c2dbf6452f" + integrity sha512-cDB930/7MbzaGF6U3IwSQp6XBru8xWajF5PV2YZZeV8DyiliTuld11afVztGI9+yJZ29il5E+NpGA6ooV/Cjkg== + "@types/node@*", "@types/node@~10.12.1": version "10.12.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.1.tgz#da61b64a2930a80fa708e57c45cd5441eb379d5b" From 852973f03fb106dd3d84dbe2ee1a48264209bf27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Thu, 6 Dec 2018 23:08:14 +0100 Subject: [PATCH 12/29] Removed unnecessary function; updated marked dependencies --- addons/notes/package.json | 4 ++-- addons/notes/src/addon.ts | 8 +------- addons/notes/src/register.tsx | 14 +++++++------- yarn.lock | 16 ++++++++-------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/addons/notes/package.json b/addons/notes/package.json index 0393ba4b6a7d..e1b020880bc0 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -28,10 +28,10 @@ "dependencies": { "@emotion/styled": "^0.10.6", "@storybook/addons": "4.1.0-alpha.1", - "marked": "^0.5.1" + "marked": "^0.5.2" }, "devDependencies": { - "@types/marked": "^0.4.2" + "@types/marked": "^0.5.0" }, "peerDependencies": { "react": "*" diff --git a/addons/notes/src/addon.ts b/addons/notes/src/addon.ts index 6adaaf065924..f81dc91db655 100644 --- a/addons/notes/src/addon.ts +++ b/addons/notes/src/addon.ts @@ -1,11 +1,5 @@ import addons, { makeDecorator } from '@storybook/addons'; -import { MarkedOptions, parse as marked } from 'marked'; - -// todo why not just calling marked directly instead of wrapping it? -// todo removed { marked.defaults, options } merge. I believe this was not necessary, have to check -function renderMarkdown(text: string, options?: MarkedOptions) { - return marked(text, options); -} +import { parse as renderMarkdown } from 'marked'; export const withNotes = makeDecorator({ name: 'withNotes', diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index 077d31053324..bb8f250a8063 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -23,6 +23,7 @@ interface NotesProps { interface NotesState { text: string; + someDate: Date; } const Panel = styled.div({ @@ -37,9 +38,9 @@ export class Notes extends React.Component { stopListeningOnStory: any; // todo check correct definition unmounted: any; // todo check correct definition - constructor(...args: any) { - super(args /* todo: This was ...args before, check if this was a bug */); - this.state = { text: '' }; + constructor(args: any) { + super(args); + this.state = { text: 'add', someDate: new Date() }; this.onAddNotes = this.onAddNotes.bind(this); } @@ -74,9 +75,9 @@ export class Notes extends React.Component { const { text } = this.state; const textAfterFormatted = text ? text - .trim() - .replace(/(<\S+.*>)\n/g, '$1') - .replace(/\n/g, '
') + .trim() + .replace(/(<\S+.*>)\n/g, '$1') + .replace(/\n/g, '
') : ''; return active ? ( @@ -88,7 +89,6 @@ export class Notes extends React.Component { } } - addons.register('storybook/notes', api => { const channel = addons.getChannel(); addons.addPanel('storybook/notes/panel', { diff --git a/yarn.lock b/yarn.lock index ae599f25154b..d8937e8c7815 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2017,10 +2017,10 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= -"@types/marked@^0.4.2": - version "0.4.2" - resolved "https://registry.yarnpkg.com/@types/marked/-/marked-0.4.2.tgz#64a89e53ea37f61cc0f3ee1732c555c2dbf6452f" - integrity sha512-cDB930/7MbzaGF6U3IwSQp6XBru8xWajF5PV2YZZeV8DyiliTuld11afVztGI9+yJZ29il5E+NpGA6ooV/Cjkg== +"@types/marked@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@types/marked/-/marked-0.5.0.tgz#4b91c66ee8cf0abb6938e02fdec207279959962e" + integrity sha512-5uRumM3yeMj+JcvWGku/FRJJCmSWZczLd8FJf76a90YCltRHVpjF2gKHiL6U+pi4qyATn7HvxR0Mk7mDySwaOQ== "@types/node@*", "@types/node@~10.12.1": version "10.12.1" @@ -14590,10 +14590,10 @@ marked@^0.3.12: resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.19.tgz#5d47f709c4c9fc3c216b6d46127280f40b39d790" integrity sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg== -marked@^0.5.1: - version "0.5.1" - resolved "https://registry.yarnpkg.com/marked/-/marked-0.5.1.tgz#062f43b88b02ee80901e8e8d8e6a620ddb3aa752" - integrity sha512-iUkBZegCZou4AdwbKTwSW/lNDcz5OuRSl3qdcl31Ia0B2QPG0Jn+tKblh/9/eP9/6+4h27vpoh8wel/vQOV0vw== +marked@^0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/marked/-/marked-0.5.2.tgz#3efdb27b1fd0ecec4f5aba362bddcd18120e5ba9" + integrity sha512-fdZvBa7/vSQIZCi4uuwo2N3q+7jJURpMVCcbaX0S1Mg65WZ5ilXvC67MviJAsdjqqgD+CEq4RKo5AYGgINkVAA== marko-loader@^1.3.3: version "1.3.3" From f25a05b47be4e4d6964f2256ef961bdda7046d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Thu, 6 Dec 2018 23:14:48 +0100 Subject: [PATCH 13/29] Changed addon.ts back to index.ts --- addons/notes/src/__tests__/index.ts | 2 +- addons/notes/src/{addon.ts => index.ts} | 0 addons/notes/src/public_api.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename addons/notes/src/{addon.ts => index.ts} (100%) diff --git a/addons/notes/src/__tests__/index.ts b/addons/notes/src/__tests__/index.ts index 5b8b5472abbc..836a8140cd82 100644 --- a/addons/notes/src/__tests__/index.ts +++ b/addons/notes/src/__tests__/index.ts @@ -1,5 +1,5 @@ import addons from '@storybook/addons'; -import { withNotes } from '../addon'; +import { withNotes } from '..'; addons.getChannel = jest.fn(); diff --git a/addons/notes/src/addon.ts b/addons/notes/src/index.ts similarity index 100% rename from addons/notes/src/addon.ts rename to addons/notes/src/index.ts diff --git a/addons/notes/src/public_api.ts b/addons/notes/src/public_api.ts index 9762837e93f9..dc0dc8965a31 100644 --- a/addons/notes/src/public_api.ts +++ b/addons/notes/src/public_api.ts @@ -1 +1 @@ -export * from './addon'; +export * from '.'; From 94e6e129a50803f894af88f50fac855289e0cfb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sat, 8 Dec 2018 14:28:53 +0100 Subject: [PATCH 14/29] Updated @emotion/styled because the newest version has definition files included --- addons/notes/package.json | 2 +- yarn.lock | 77 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/addons/notes/package.json b/addons/notes/package.json index e1b020880bc0..da2c69aeca5f 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -26,7 +26,7 @@ "prepare": "node ../../scripts/prepare.js" }, "dependencies": { - "@emotion/styled": "^0.10.6", + "@emotion/styled": "^10.0.4", "@storybook/addons": "4.1.0-alpha.1", "marked": "^0.5.2" }, diff --git a/yarn.lock b/yarn.lock index d8937e8c7815..91180fb028d2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1144,11 +1144,23 @@ "@emotion/serialize" "^0.9.1" "@emotion/utils" "^0.8.2" +"@emotion/hash@0.7.1": + version "0.7.1" + resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.7.1.tgz#9833722341379fb7d67f06a4b00ab3c37913da53" + integrity sha512-OYpa/Sg+2GDX+jibUfpZVn1YqSVRpYmTLF2eyAfrFTIJSbwyIrc+YscayoykvaOME/wV4BV0Sa0yqdMrgse6mA== + "@emotion/hash@^0.6.2", "@emotion/hash@^0.6.6": version "0.6.6" resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.6.6.tgz#62266c5f0eac6941fece302abad69f2ee7e25e44" integrity sha512-ojhgxzUHZ7am3D2jHkMzPpsBAiB005GF5YU4ea+8DNPybMk01JJUM9V9YRlF/GE95tcOm8DxQvWA2jq19bGalQ== +"@emotion/is-prop-valid@0.7.3": + version "0.7.3" + resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.7.3.tgz#a6bf4fa5387cbba59d44e698a4680f481a8da6cc" + integrity sha512-uxJqm/sqwXw3YPA5GXX365OBcJGFtxUVkB6WyezqFHlNe9jqUWH5ur2O2M8dGBz61kn1g3ZBlzUunFQXQIClhA== + dependencies: + "@emotion/memoize" "0.7.1" + "@emotion/is-prop-valid@^0.6.8": version "0.6.8" resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.6.8.tgz#68ad02831da41213a2089d2cab4e8ac8b30cbd85" @@ -1156,6 +1168,11 @@ dependencies: "@emotion/memoize" "^0.6.6" +"@emotion/memoize@0.7.1": + version "0.7.1" + resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.1.tgz#e93c13942592cf5ef01aa8297444dc192beee52f" + integrity sha512-Qv4LTqO11jepd5Qmlp3M1YEjBumoTHcHFdgPTQ+sFlIL5myi/7xu/POwP7IRu6odBdmLXdtIs1D6TuW6kbwbbg== + "@emotion/memoize@^0.6.1", "@emotion/memoize@^0.6.6": version "0.6.6" resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.6.6.tgz#004b98298d04c7ca3b4f50ca2035d4f60d2eed1b" @@ -1169,6 +1186,17 @@ "@emotion/cache" "^0.8.8" "@emotion/weak-memoize" "^0.1.3" +"@emotion/serialize@^0.11.2": + version "0.11.2" + resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.11.2.tgz#f6cdf7b20ade02251525add0e50f8a56d47e4a3f" + integrity sha512-6bWsiynUj+KByNXpcSbx/2xj9OI7Vty/IeIvB5ArPswosyp0N0GezDqQ50IjFDfDUPv0LNCtyyKuTtlFy62Epw== + dependencies: + "@emotion/hash" "0.7.1" + "@emotion/memoize" "0.7.1" + "@emotion/unitless" "0.7.3" + "@emotion/utils" "0.11.1" + csstype "^2.5.7" + "@emotion/serialize@^0.9.1": version "0.9.1" resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.9.1.tgz#a494982a6920730dba6303eb018220a2b629c145" @@ -1201,6 +1229,16 @@ "@emotion/serialize" "^0.9.1" "@emotion/utils" "^0.8.2" +"@emotion/styled-base@^10.0.4": + version "10.0.4" + resolved "https://registry.yarnpkg.com/@emotion/styled-base/-/styled-base-10.0.4.tgz#7b8243755a9757f4a0f5504b6b3431c84a0008e2" + integrity sha512-GQl1nv31ASgjCt0FVR/0NyjXXZXuYVDjgrpNi1bPNosSwAKKAMddqJtt6X/f6A2KhmCfresDjscXs5NrdgKAGA== + dependencies: + "@emotion/is-prop-valid" "0.7.3" + "@emotion/serialize" "^0.11.2" + "@emotion/utils" "0.11.1" + object-assign "^4.1.1" + "@emotion/styled@^0.10.6": version "0.10.6" resolved "https://registry.yarnpkg.com/@emotion/styled/-/styled-0.10.6.tgz#1f6af1d3d4bf9fdeb05a4d220046ce11ad21a7ca" @@ -1208,16 +1246,34 @@ dependencies: "@emotion/styled-base" "^0.10.6" +"@emotion/styled@^10.0.4": + version "10.0.4" + resolved "https://registry.yarnpkg.com/@emotion/styled/-/styled-10.0.4.tgz#354d5cac90a4ead45c7d6566f3257b5117d7e30f" + integrity sha512-0iatvVUrgNjU8rl3cl2iMvPqc7lqyHw45dUwfSGHJIV13l1xO8+32IV/AQ34/oOlZlG8U7NDCG8qSzos2pAy+w== + dependencies: + "@emotion/styled-base" "^10.0.4" + babel-plugin-emotion "^10.0.4" + "@emotion/stylis@^0.7.0", "@emotion/stylis@^0.7.1": version "0.7.1" resolved "https://registry.yarnpkg.com/@emotion/stylis/-/stylis-0.7.1.tgz#50f63225e712d99e2b2b39c19c70fff023793ca5" integrity sha512-/SLmSIkN13M//53TtNxgxo57mcJk/UJIDFRKwOiLIBEyBHEcipgR6hNMQ/59Sl4VjCJ0Z/3zeAZyvnSLPG/1HQ== +"@emotion/unitless@0.7.3": + version "0.7.3" + resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.7.3.tgz#6310a047f12d21a1036fb031317219892440416f" + integrity sha512-4zAPlpDEh2VwXswwr/t8xGNDGg8RQiPxtxZ3qQEXyQsBV39ptTdESCjuBvGze1nLMVrxmTIKmnO/nAV8Tqjjzg== + "@emotion/unitless@^0.6.7": version "0.6.7" resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.6.7.tgz#53e9f1892f725b194d5e6a1684a7b394df592397" integrity sha512-Arj1hncvEVqQ2p7Ega08uHLr1JuRYBuO5cIvcA+WWEQ5+VmkOE3ZXzl04NbQxeQpWX78G7u6MqxKuNX3wvYZxg== +"@emotion/utils@0.11.1": + version "0.11.1" + resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-0.11.1.tgz#8529b7412a6eb4b48bdf6e720cc1b8e6e1e17628" + integrity sha512-8M3VN0hetwhsJ8dH8VkVy7xo5/1VoBsDOk/T4SJOeXwTO1c4uIqVNx2qyecLFnnUWD5vvUqHQ1gASSeUN6zcTg== + "@emotion/utils@^0.8.2": version "0.8.2" resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-0.8.2.tgz#576ff7fb1230185b619a75d258cbc98f0867a8dc" @@ -3539,6 +3595,22 @@ babel-plugin-ember-modules-api-polyfill@^2.5.0: dependencies: ember-rfc176-data "^0.3.5" +babel-plugin-emotion@^10.0.4: + version "10.0.4" + resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-10.0.4.tgz#e9387087728efe25c578b7649e11a2776c97e39c" + integrity sha512-hahTaxtYLww0sUWQSWjbhwbASy4JoTpsV9TnJh6xpQUZotJwp5kBnzoDeaOKgNff8kYdMU+In1YRgGM3rlOFGg== + dependencies: + "@babel/helper-module-imports" "^7.0.0" + "@emotion/hash" "0.7.1" + "@emotion/memoize" "0.7.1" + "@emotion/serialize" "^0.11.2" + babel-plugin-macros "^2.0.0" + babel-plugin-syntax-jsx "^6.18.0" + convert-source-map "^1.5.0" + escape-string-regexp "^1.0.5" + find-root "^1.1.0" + source-map "^0.5.7" + babel-plugin-emotion@^9.2.11: version "9.2.11" resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-9.2.11.tgz#319c005a9ee1d15bb447f59fe504c35fd5807728" @@ -7354,6 +7426,11 @@ csstype@^2.2.0: resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.7.tgz#bf9235d5872141eccfb2d16d82993c6b149179ff" integrity sha512-Nt5VDyOTIIV4/nRFswoCKps1R5CD1hkiyjBE9/thNaNZILLEviVw9yWQw15+O+CpNjQKB/uvdcxFFOrSflY3Yw== +csstype@^2.5.7: + version "2.5.8" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.8.tgz#4ce5aa16ea0d562ef9105fa3ae2676f199586a35" + integrity sha512-r4DbsyNJ7slwBSKoGesxDubRWJ71ghG8W2+1HcsDlAo12KGca9dDLv0u98tfdFw7ldBdoA7XmCnI6Q8LpAJXaQ== + csurf@~1.8.3: version "1.8.3" resolved "https://registry.yarnpkg.com/csurf/-/csurf-1.8.3.tgz#23f2a13bf1d8fce1d0c996588394442cba86a56a" From 206b304f08f59fc603ca4fe5e71573a99e0f7c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sat, 8 Dec 2018 14:29:37 +0100 Subject: [PATCH 15/29] Added .tsx to the allowed file extensions for jsx --- .eslintrc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 917bf9b00706..2ed63d421c4e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,7 +27,7 @@ module.exports = { 'import/ignore': ['node_modules\\/(?!@storybook)'], 'import/resolver': { node: { - extensions: ['.js', '.ts'], + extensions: ['.js'], }, }, }, @@ -77,7 +77,7 @@ module.exports = { 'react/jsx-filename-extension': [ warn, { - extensions: ['.js', '.jsx'], + extensions: ['.js', '.jsx', '.tsx'], }, ], 'react/jsx-no-bind': [ From 49b467d89496694276cb7fd6e30e67f08b12e8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sat, 8 Dec 2018 14:30:01 +0100 Subject: [PATCH 16/29] Re-enabled noImplicitAny again --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 01184e383ca6..55ea5bb93317 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "skipLibCheck": true, - "noImplicitAny": false, + "noImplicitAny": true, "jsx": "react", "module": "commonjs", "target": "es5", From 149f4713953f8b83833c55dd653d5135247766e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sat, 8 Dec 2018 14:31:24 +0100 Subject: [PATCH 17/29] Resolved a couple of any to their actual types Also had to introduce a couple of new any assignments because of noImplicitAny: true They still need to be resolved. WIP --- addons/notes/src/index.ts | 4 ++-- addons/notes/src/register.tsx | 23 +++++++++++------------ addons/notes/src/typings.d.ts | 2 ++ 3 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 addons/notes/src/typings.d.ts diff --git a/addons/notes/src/index.ts b/addons/notes/src/index.ts index f81dc91db655..c987c5e24d69 100644 --- a/addons/notes/src/index.ts +++ b/addons/notes/src/index.ts @@ -6,7 +6,7 @@ export const withNotes = makeDecorator({ parameterName: 'notes', skipIfNoParametersOrOptions: true, allowDeprecatedUsage: true, - wrapper: (getStory, context, { options, parameters }) => { + wrapper: (getStory: (context: any) => any, context: any, { options, parameters }: any) => { const channel = addons.getChannel(); const storyOptions = parameters || options; @@ -30,7 +30,7 @@ export const withNotes = makeDecorator({ }, }); -export const withMarkdownNotes = (text, options) => +export const withMarkdownNotes = (text: string, options: any) => withNotes({ markdown: text, markdownOptions: options, diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index bb8f250a8063..8b4488f669d7 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -10,8 +10,8 @@ interface NotesChannel { } interface NotesApi { - onStory: (callback: () => void) => void; - getQueryParam: any; // todo check correct definition + onStory(callback: () => void): () => void; + getQueryParam(queryParamName: string): any; setQueryParams: any; // todo check correct definition } @@ -23,24 +23,23 @@ interface NotesProps { interface NotesState { text: string; - someDate: Date; } const Panel = styled.div({ padding: 10, boxSizing: 'border-box', - width: '100%', + width: '100%' }); export class Notes extends React.Component { - // todo check how react typescript does this, especially unmounted - stopListeningOnStory: any; // todo check correct definition - unmounted: any; // todo check correct definition + stopListeningOnStory: () => void; + + isUnmounted = false; constructor(args: any) { super(args); - this.state = { text: 'add', someDate: new Date() }; + this.state = { text: 'add' }; this.onAddNotes = this.onAddNotes.bind(this); } @@ -61,12 +60,12 @@ export class Notes extends React.Component { this.stopListeningOnStory(); } - this.unmounted = true; + this.isUnmounted = true; const { channel } = this.props; channel.removeListener('storybook/notes/add_notes', this.onAddNotes); } - onAddNotes(text) { + onAddNotes(text: string) { this.setState({ text }); } @@ -89,10 +88,10 @@ export class Notes extends React.Component { } } -addons.register('storybook/notes', api => { +addons.register('storybook/notes', (api: any) => { const channel = addons.getChannel(); addons.addPanel('storybook/notes/panel', { title: 'Notes', - render: ({ active }) => , + render: ({ active }: { active: boolean }) => }); }); diff --git a/addons/notes/src/typings.d.ts b/addons/notes/src/typings.d.ts new file mode 100644 index 000000000000..834bdb142848 --- /dev/null +++ b/addons/notes/src/typings.d.ts @@ -0,0 +1,2 @@ +// Fixes 'noImplicitAny' lint error because @storybook/addons isn't migrated to typescript yet +declare module '@storybook/addons'; From e943ff38d31b60c02181d1f5bb23352c9499fc45 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sat, 8 Dec 2018 15:24:55 +0100 Subject: [PATCH 18/29] Updated NotesApi; refactored "styled" usage --- addons/notes/src/register.tsx | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index 8b4488f669d7..c97079c8ae4d 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -10,9 +10,10 @@ interface NotesChannel { } interface NotesApi { - onStory(callback: () => void): () => void; - getQueryParam(queryParamName: string): any; setQueryParams: any; // todo check correct definition + getQueryParam(queryParamName: string): any; + + onStory(callback: () => void): () => void; } interface NotesProps { @@ -25,23 +26,22 @@ interface NotesState { text: string; } -const Panel = styled.div({ +const Panel = styled('div')` padding: 10, boxSizing: 'border-box', - width: '100%' -}); + width: '100%', +`; export class Notes extends React.Component { stopListeningOnStory: () => void; - + foo: unknown; isUnmounted = false; - constructor(args: any) { - super(args); - this.state = { text: 'add' }; - this.onAddNotes = this.onAddNotes.bind(this); - } + state: NotesState = { text: '' }; + + // todo is this even necessary? Is this some react magic? onAddNotes is a method of this class + // this.onAddNotes = this.onAddNotes.bind(this); componentDidMount() { const { channel, api } = this.props; @@ -74,9 +74,9 @@ export class Notes extends React.Component { const { text } = this.state; const textAfterFormatted = text ? text - .trim() - .replace(/(<\S+.*>)\n/g, '$1') - .replace(/\n/g, '
') + .trim() + .replace(/(<\S+.*>)\n/g, '$1') + .replace(/\n/g, '
') : ''; return active ? ( @@ -92,6 +92,6 @@ addons.register('storybook/notes', (api: any) => { const channel = addons.getChannel(); addons.addPanel('storybook/notes/panel', { title: 'Notes', - render: ({ active }: { active: boolean }) => + render: ({ active }: { active: boolean }) => , }); }); From 14afa9c12a5b59e3281f228f5957f972991c8795 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sat, 8 Dec 2018 15:34:53 +0100 Subject: [PATCH 19/29] Refactoring --- addons/notes/src/register.tsx | 7 ++++--- addons/notes/tsconfig.json | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index c97079c8ae4d..1b0e067aafaa 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -3,10 +3,11 @@ import addons from '@storybook/addons'; import styled from '@emotion/styled'; +// todo this is going to be refactored after the migration of @storybook/channel to TypeScript interface NotesChannel { - on: (listener: string, callback: (text: string) => void) => any; // todo check correct return value definition - emit: any; // todo check correct definition - removeListener: (listener: string, callback: (text: string) => void) => void; + emit: any; + on(listener: string, callback: (text: string) => void): any; + removeListener(listener: string, callback: (text: string) => void): void; } interface NotesApi { diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json index 91baa3e9a3ac..ce10008f17e1 100644 --- a/addons/notes/tsconfig.json +++ b/addons/notes/tsconfig.json @@ -1,7 +1,10 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "rootDir": "./src" + "rootDir": "./src", + "types": [ + "src/typings.d.ts" + ] }, "include": [ "src/**/*.ts", From 88d1f70c890927274d6bc8b97837dd345c69a5c3 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sat, 8 Dec 2018 15:40:19 +0100 Subject: [PATCH 20/29] Re-added .ts to import/resolver in eslint --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2ed63d421c4e..52d06020fa45 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,7 +27,7 @@ module.exports = { 'import/ignore': ['node_modules\\/(?!@storybook)'], 'import/resolver': { node: { - extensions: ['.js'], + extensions: ['.js', '.ts'], }, }, }, From a11cd702b2731795ec2a538a57d5b4f6f35f0df0 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sat, 8 Dec 2018 15:43:25 +0100 Subject: [PATCH 21/29] Added todo for refactoring purpose --- addons/notes/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/notes/src/index.ts b/addons/notes/src/index.ts index c987c5e24d69..57749ebb5434 100644 --- a/addons/notes/src/index.ts +++ b/addons/notes/src/index.ts @@ -1,6 +1,7 @@ import addons, { makeDecorator } from '@storybook/addons'; import { parse as renderMarkdown } from 'marked'; +// todo resolve any after @storybook/addons and @storybook/channels are migrated to TypeScript export const withNotes = makeDecorator({ name: 'withNotes', parameterName: 'notes', From 2d00ee6a3f654b14c768423ebeea9ff899322790 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Sun, 9 Dec 2018 00:28:08 +0200 Subject: [PATCH 22/29] Force eslint to ignore *.ts files --- .eslintignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintignore b/.eslintignore index 73f2bb84a21b..6a611e8ec182 100644 --- a/.eslintignore +++ b/.eslintignore @@ -8,6 +8,7 @@ built-storybooks lib/cli/test *.bundle.js *.js.map +*.ts !.remarkrc.js !.babelrc.js From 79306bdb1057a86a5805450329aa87b5f732aa66 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 9 Dec 2018 11:05:58 +0100 Subject: [PATCH 23/29] Set @emotion/styled back to ^0.10.6 --- addons/notes/package.json | 2 +- yarn.lock | 77 --------------------------------------- 2 files changed, 1 insertion(+), 78 deletions(-) diff --git a/addons/notes/package.json b/addons/notes/package.json index 976bbb95b5ae..78296d4731e7 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -23,7 +23,7 @@ "prepare": "node ../../scripts/prepare.js" }, "dependencies": { - "@emotion/styled": "^10.0.4", + "@emotion/styled": "^0.10.6", "@storybook/addons": "4.1.0-alpha.11", "marked": "^0.5.2" }, diff --git a/yarn.lock b/yarn.lock index b71a1dd04162..803f01ca3174 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1202,23 +1202,11 @@ "@emotion/serialize" "^0.9.1" "@emotion/utils" "^0.8.2" -"@emotion/hash@0.7.1": - version "0.7.1" - resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.7.1.tgz#9833722341379fb7d67f06a4b00ab3c37913da53" - integrity sha512-OYpa/Sg+2GDX+jibUfpZVn1YqSVRpYmTLF2eyAfrFTIJSbwyIrc+YscayoykvaOME/wV4BV0Sa0yqdMrgse6mA== - "@emotion/hash@^0.6.2", "@emotion/hash@^0.6.6": version "0.6.6" resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.6.6.tgz#62266c5f0eac6941fece302abad69f2ee7e25e44" integrity sha512-ojhgxzUHZ7am3D2jHkMzPpsBAiB005GF5YU4ea+8DNPybMk01JJUM9V9YRlF/GE95tcOm8DxQvWA2jq19bGalQ== -"@emotion/is-prop-valid@0.7.3": - version "0.7.3" - resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.7.3.tgz#a6bf4fa5387cbba59d44e698a4680f481a8da6cc" - integrity sha512-uxJqm/sqwXw3YPA5GXX365OBcJGFtxUVkB6WyezqFHlNe9jqUWH5ur2O2M8dGBz61kn1g3ZBlzUunFQXQIClhA== - dependencies: - "@emotion/memoize" "0.7.1" - "@emotion/is-prop-valid@^0.6.8": version "0.6.8" resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.6.8.tgz#68ad02831da41213a2089d2cab4e8ac8b30cbd85" @@ -1226,11 +1214,6 @@ dependencies: "@emotion/memoize" "^0.6.6" -"@emotion/memoize@0.7.1": - version "0.7.1" - resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.1.tgz#e93c13942592cf5ef01aa8297444dc192beee52f" - integrity sha512-Qv4LTqO11jepd5Qmlp3M1YEjBumoTHcHFdgPTQ+sFlIL5myi/7xu/POwP7IRu6odBdmLXdtIs1D6TuW6kbwbbg== - "@emotion/memoize@^0.6.1", "@emotion/memoize@^0.6.6": version "0.6.6" resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.6.6.tgz#004b98298d04c7ca3b4f50ca2035d4f60d2eed1b" @@ -1244,17 +1227,6 @@ "@emotion/cache" "^0.8.8" "@emotion/weak-memoize" "^0.1.3" -"@emotion/serialize@^0.11.2": - version "0.11.2" - resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.11.2.tgz#f6cdf7b20ade02251525add0e50f8a56d47e4a3f" - integrity sha512-6bWsiynUj+KByNXpcSbx/2xj9OI7Vty/IeIvB5ArPswosyp0N0GezDqQ50IjFDfDUPv0LNCtyyKuTtlFy62Epw== - dependencies: - "@emotion/hash" "0.7.1" - "@emotion/memoize" "0.7.1" - "@emotion/unitless" "0.7.3" - "@emotion/utils" "0.11.1" - csstype "^2.5.7" - "@emotion/serialize@^0.9.1": version "0.9.1" resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.9.1.tgz#a494982a6920730dba6303eb018220a2b629c145" @@ -1287,16 +1259,6 @@ "@emotion/serialize" "^0.9.1" "@emotion/utils" "^0.8.2" -"@emotion/styled-base@^10.0.4": - version "10.0.4" - resolved "https://registry.yarnpkg.com/@emotion/styled-base/-/styled-base-10.0.4.tgz#7b8243755a9757f4a0f5504b6b3431c84a0008e2" - integrity sha512-GQl1nv31ASgjCt0FVR/0NyjXXZXuYVDjgrpNi1bPNosSwAKKAMddqJtt6X/f6A2KhmCfresDjscXs5NrdgKAGA== - dependencies: - "@emotion/is-prop-valid" "0.7.3" - "@emotion/serialize" "^0.11.2" - "@emotion/utils" "0.11.1" - object-assign "^4.1.1" - "@emotion/styled@0.10.6", "@emotion/styled@^0.10.6": version "0.10.6" resolved "https://registry.yarnpkg.com/@emotion/styled/-/styled-0.10.6.tgz#1f6af1d3d4bf9fdeb05a4d220046ce11ad21a7ca" @@ -1304,34 +1266,16 @@ dependencies: "@emotion/styled-base" "^0.10.6" -"@emotion/styled@^10.0.4": - version "10.0.4" - resolved "https://registry.yarnpkg.com/@emotion/styled/-/styled-10.0.4.tgz#354d5cac90a4ead45c7d6566f3257b5117d7e30f" - integrity sha512-0iatvVUrgNjU8rl3cl2iMvPqc7lqyHw45dUwfSGHJIV13l1xO8+32IV/AQ34/oOlZlG8U7NDCG8qSzos2pAy+w== - dependencies: - "@emotion/styled-base" "^10.0.4" - babel-plugin-emotion "^10.0.4" - "@emotion/stylis@^0.7.0", "@emotion/stylis@^0.7.1": version "0.7.1" resolved "https://registry.yarnpkg.com/@emotion/stylis/-/stylis-0.7.1.tgz#50f63225e712d99e2b2b39c19c70fff023793ca5" integrity sha512-/SLmSIkN13M//53TtNxgxo57mcJk/UJIDFRKwOiLIBEyBHEcipgR6hNMQ/59Sl4VjCJ0Z/3zeAZyvnSLPG/1HQ== -"@emotion/unitless@0.7.3": - version "0.7.3" - resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.7.3.tgz#6310a047f12d21a1036fb031317219892440416f" - integrity sha512-4zAPlpDEh2VwXswwr/t8xGNDGg8RQiPxtxZ3qQEXyQsBV39ptTdESCjuBvGze1nLMVrxmTIKmnO/nAV8Tqjjzg== - "@emotion/unitless@^0.6.7": version "0.6.7" resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.6.7.tgz#53e9f1892f725b194d5e6a1684a7b394df592397" integrity sha512-Arj1hncvEVqQ2p7Ega08uHLr1JuRYBuO5cIvcA+WWEQ5+VmkOE3ZXzl04NbQxeQpWX78G7u6MqxKuNX3wvYZxg== -"@emotion/utils@0.11.1": - version "0.11.1" - resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-0.11.1.tgz#8529b7412a6eb4b48bdf6e720cc1b8e6e1e17628" - integrity sha512-8M3VN0hetwhsJ8dH8VkVy7xo5/1VoBsDOk/T4SJOeXwTO1c4uIqVNx2qyecLFnnUWD5vvUqHQ1gASSeUN6zcTg== - "@emotion/utils@^0.8.2": version "0.8.2" resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-0.8.2.tgz#576ff7fb1230185b619a75d258cbc98f0867a8dc" @@ -3759,22 +3703,6 @@ babel-plugin-ember-modules-api-polyfill@^2.5.0: dependencies: ember-rfc176-data "^0.3.5" -babel-plugin-emotion@^10.0.4: - version "10.0.4" - resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-10.0.4.tgz#e9387087728efe25c578b7649e11a2776c97e39c" - integrity sha512-hahTaxtYLww0sUWQSWjbhwbASy4JoTpsV9TnJh6xpQUZotJwp5kBnzoDeaOKgNff8kYdMU+In1YRgGM3rlOFGg== - dependencies: - "@babel/helper-module-imports" "^7.0.0" - "@emotion/hash" "0.7.1" - "@emotion/memoize" "0.7.1" - "@emotion/serialize" "^0.11.2" - babel-plugin-macros "^2.0.0" - babel-plugin-syntax-jsx "^6.18.0" - convert-source-map "^1.5.0" - escape-string-regexp "^1.0.5" - find-root "^1.1.0" - source-map "^0.5.7" - babel-plugin-emotion@^9.2.11: version "9.2.11" resolved "https://registry.yarnpkg.com/babel-plugin-emotion/-/babel-plugin-emotion-9.2.11.tgz#319c005a9ee1d15bb447f59fe504c35fd5807728" @@ -7595,11 +7523,6 @@ csstype@^2.2.0: resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.7.tgz#bf9235d5872141eccfb2d16d82993c6b149179ff" integrity sha512-Nt5VDyOTIIV4/nRFswoCKps1R5CD1hkiyjBE9/thNaNZILLEviVw9yWQw15+O+CpNjQKB/uvdcxFFOrSflY3Yw== -csstype@^2.5.7: - version "2.5.8" - resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.5.8.tgz#4ce5aa16ea0d562ef9105fa3ae2676f199586a35" - integrity sha512-r4DbsyNJ7slwBSKoGesxDubRWJ71ghG8W2+1HcsDlAo12KGca9dDLv0u98tfdFw7ldBdoA7XmCnI6Q8LpAJXaQ== - csurf@~1.8.3: version "1.8.3" resolved "https://registry.yarnpkg.com/csurf/-/csurf-1.8.3.tgz#23f2a13bf1d8fce1d0c996588394442cba86a56a" From 876488ceb58c09ca3ab2d47c9d6ae7a45c8a730d Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 9 Dec 2018 11:06:54 +0100 Subject: [PATCH 24/29] Added 'jsx-double' rule for tsx files --- tslint.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tslint.json b/tslint.json index cac74369ad1d..82c490343c31 100644 --- a/tslint.json +++ b/tslint.json @@ -97,7 +97,8 @@ "prefer-const": true, "quotemark": [ true, - "single" + "single", + "jsx-double" ], "radix": true, "semicolon": [ From 018f83ac1e362e012afac5fa74d6cbc3a3f9675b Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 9 Dec 2018 11:11:59 +0100 Subject: [PATCH 25/29] Created @emotion/styled module to satisfy noImplicitAny rule --- addons/notes/src/typings.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/notes/src/typings.d.ts b/addons/notes/src/typings.d.ts index 834bdb142848..84ab86f76adc 100644 --- a/addons/notes/src/typings.d.ts +++ b/addons/notes/src/typings.d.ts @@ -1,2 +1,5 @@ // Fixes 'noImplicitAny' lint error because @storybook/addons isn't migrated to typescript yet declare module '@storybook/addons'; + +// Only necessary for 0.x.x. Version 10.x.x has definition files included +declare module '@emotion/styled'; From d7184fef0004c026eaf7c5a24013d461dcecaec6 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 9 Dec 2018 11:24:09 +0100 Subject: [PATCH 26/29] Fixed build issue --- addons/notes/tsconfig.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json index ce10008f17e1..91baa3e9a3ac 100644 --- a/addons/notes/tsconfig.json +++ b/addons/notes/tsconfig.json @@ -1,10 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "rootDir": "./src", - "types": [ - "src/typings.d.ts" - ] + "rootDir": "./src" }, "include": [ "src/**/*.ts", From c1669d869a221fa4988d17b017db0527c9ff8f2e Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 9 Dec 2018 11:28:18 +0100 Subject: [PATCH 27/29] Reverted @emotion/styled change --- addons/notes/src/register.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index 1b0e067aafaa..a5c34b9cd43d 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -27,11 +27,11 @@ interface NotesState { text: string; } -const Panel = styled('div')` +const Panel = styled.div({ padding: 10, boxSizing: 'border-box', - width: '100%', -`; + width: '100%' +}); export class Notes extends React.Component { From 5312cd4fcacb1432650fd90f7745b4f364b3a73f Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 9 Dec 2018 12:11:30 +0100 Subject: [PATCH 28/29] Refactoring --- addons/notes/src/register.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index a5c34b9cd43d..49523a527fca 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -30,19 +30,20 @@ interface NotesState { const Panel = styled.div({ padding: 10, boxSizing: 'border-box', - width: '100%' + width: '100%', }); export class Notes extends React.Component { stopListeningOnStory: () => void; - foo: unknown; isUnmounted = false; - state: NotesState = { text: '' }; + readonly state: NotesState = { text: '' }; - // todo is this even necessary? Is this some react magic? onAddNotes is a method of this class - // this.onAddNotes = this.onAddNotes.bind(this); + constructor(props: NotesProps) { + super(props); + this.onAddNotes = this.onAddNotes.bind(this); + } componentDidMount() { const { channel, api } = this.props; From 1a4e51033f81cf89529672e328287c403ae5f4c4 Mon Sep 17 00:00:00 2001 From: Kai Roeder Date: Sun, 9 Dec 2018 21:27:42 +0100 Subject: [PATCH 29/29] Added prop-types + typings for prop-types. Restored the old prop-types for non-typescript users --- addons/notes/package.json | 6 ++++-- addons/notes/src/register.tsx | 15 +++++++++++++++ yarn.lock | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/notes/package.json b/addons/notes/package.json index 78296d4731e7..97f87d46c7ee 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -25,10 +25,12 @@ "dependencies": { "@emotion/styled": "^0.10.6", "@storybook/addons": "4.1.0-alpha.11", - "marked": "^0.5.2" + "marked": "^0.5.2", + "prop-types": "^15.6.2" }, "devDependencies": { - "@types/marked": "^0.5.0" + "@types/marked": "^0.5.0", + "@types/prop-types": "^15.5.7" }, "peerDependencies": { "react": "*" diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index 49523a527fca..9b6d15364ce0 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import addons from '@storybook/addons'; +import * as PropTypes from 'prop-types'; import styled from '@emotion/styled'; @@ -35,6 +36,20 @@ const Panel = styled.div({ export class Notes extends React.Component { + static propTypes = { + active: PropTypes.bool.isRequired, + channel: PropTypes.shape({ + on: PropTypes.func, + emit: PropTypes.func, + removeListener: PropTypes.func, + }).isRequired, + api: PropTypes.shape({ + onStory: PropTypes.func, + getQueryParam: PropTypes.func, + setQueryParams: PropTypes.func, + }).isRequired, + }; + stopListeningOnStory: () => void; isUnmounted = false; diff --git a/yarn.lock b/yarn.lock index 803f01ca3174..ac0af1aa1cd0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2223,6 +2223,11 @@ resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.6.tgz#9c03d3fed70a8d517c191b7734da2879b50ca26c" integrity sha512-ZBFR7TROLVzCkswA3Fmqq+IIJt62/T7aY/Dmz+QkU7CaW2QFqAitCE8Ups7IzmGhcN1YWMBT4Qcoc07jU9hOJQ== +"@types/prop-types@^15.5.7": + version "15.5.7" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.7.tgz#c6f1e0d0109ff358b132d98b7b4025c7a7b707c5" + integrity sha512-a6WH0fXkgPNiGIuLjjdpf0n/GnmgWZ4vLuVIJJnDwhmRDPEaiRBcy5ofQPh+EJFua0S1QWmk1745+JqZQGnJ8Q== + "@types/q@^0.0.32": version "0.0.32" resolved "https://registry.yarnpkg.com/@types/q/-/q-0.0.32.tgz#bd284e57c84f1325da702babfc82a5328190c0c5"