diff options
Diffstat (limited to 'packages/react-docs')
26 files changed, 0 insertions, 3003 deletions
diff --git a/packages/react-docs/.npmignore b/packages/react-docs/.npmignore deleted file mode 100644 index d645458f6..000000000 --- a/packages/react-docs/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -.* -yarn-error.log -/src/ -/scripts/ -tsconfig.json -/lib/monorepo_scripts/ diff --git a/packages/react-docs/CHANGELOG.json b/packages/react-docs/CHANGELOG.json deleted file mode 100644 index 8b418fc11..000000000 --- a/packages/react-docs/CHANGELOG.json +++ /dev/null @@ -1,407 +0,0 @@ -[ - { - "version": "2.0.0", - "changes": [ - { - "note": "Upgrade the bignumber.js to v8.0.2", - "pr": 1517 - } - ] - }, - { - "timestamp": 1547561734, - "version": "1.0.25", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547225310, - "version": "1.0.24", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547040760, - "version": "1.0.23", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.22", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1544739608 - }, - { - "version": "1.0.21", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1544570656 - }, - { - "timestamp": 1543401373, - "version": "1.0.20", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1542821676, - "version": "1.0.19", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1542208198, - "version": "1.0.18", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1542134075, - "version": "1.0.17", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1542028948, - "version": "1.0.16", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.15", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1541740904 - }, - { - "timestamp": 1539871071, - "version": "1.0.14", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "1.0.13", - "changes": [ - { - "note": "Dependencies updated" - } - ], - "timestamp": 1538693146 - }, - { - "timestamp": 1538157789, - "version": "1.0.12", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537907159, - "version": "1.0.11", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537875740, - "version": "1.0.10", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1537541580, - "version": "1.0.9", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1536142250, - "version": "1.0.8", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1535377027, - "version": "1.0.7", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1535133899, - "version": "1.0.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1534210131, - "version": "1.0.5", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532619515, - "version": "1.0.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532614997, - "version": "1.0.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532605697, - "version": "1.0.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532357734, - "version": "1.0.1", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1532043000, - "version": "1.0.0", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1531919263, - "version": "0.0.17", - "changes": [ - { - "note": "Nest MD files under versions so that you can update them for future versions", - "pr": 844 - } - ] - }, - { - "timestamp": 1531919263, - "version": "0.0.16", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1531149657, - "version": "0.0.15", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1529397769, - "version": "0.0.14", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "0.0.13", - "changes": [ - { - "note": "Incorrect publish that was unpublished" - } - ], - "timestamp": 1527810075 - }, - { - "timestamp": 1527009133, - "version": "0.0.12", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1525477860, - "version": "0.0.11", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1525466747, - "version": "0.0.10", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1525428773, - "version": "0.0.9", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "0.0.8", - "changes": [ - { - "note": "Added support for rendering default param values", - "pr": 519 - }, - { - "note": "Added support for rendering nested function types within interface types", - "pr": 519 - }, - { - "note": "Improve type comment rendering", - "pr": 535 - } - ], - "timestamp": 1524044013 - }, - { - "timestamp": 1523462196, - "version": "0.0.7", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1522673609, - "version": "0.0.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "0.0.5", - "changes": [ - { - "note": "Handle `reflection` type rendering so that anonymous function type declarations render properly", - "pr": 465 - }, - { - "note": "Rename `MethodSignature` to `Signature` and change it's props so that it can be used to render method and function signatures.", - "pr": 465 - }, - { - "note": "Rename `MethodBlock` to `SignatureBlock` since it is not used to render method and function signature blocks.", - "pr": 465 - }, - { - "note": "Add support for documenting exported functions.", - "pr": 465 - } - ], - "timestamp": 1522658513 - }, - { - "version": "0.0.3", - "changes": [ - { - "note": "Move TS typings from devDependencies to dependencies since they are needed by the package user." - } - ], - "timestamp": 1521298800 - }, - { - "version": "0.0.2", - "changes": [ - { - "note": "Move example out into a separate sub-package" - }, - { - "note": "Consolidate all `console.log` calls into `logUtils` in the `@0xproject/utils` package", - "pr": 452 - } - ], - "timestamp": 1521298800 - } -] diff --git a/packages/react-docs/CHANGELOG.md b/packages/react-docs/CHANGELOG.md deleted file mode 100644 index 5ec82b5be..000000000 --- a/packages/react-docs/CHANGELOG.md +++ /dev/null @@ -1,176 +0,0 @@ -<!-- -changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly. -Edit the package's CHANGELOG.json file only. ---> - -CHANGELOG - -## v1.0.25 - _January 15, 2019_ - - * Dependencies updated - -## v1.0.24 - _January 11, 2019_ - - * Dependencies updated - -## v1.0.23 - _January 9, 2019_ - - * Dependencies updated - -## v1.0.22 - _December 13, 2018_ - - * Dependencies updated - -## v1.0.21 - _December 11, 2018_ - - * Dependencies updated - -## v1.0.20 - _November 28, 2018_ - - * Dependencies updated - -## v1.0.19 - _November 21, 2018_ - - * Dependencies updated - -## v1.0.18 - _November 14, 2018_ - - * Dependencies updated - -## v1.0.17 - _November 13, 2018_ - - * Dependencies updated - -## v1.0.16 - _November 12, 2018_ - - * Dependencies updated - -## v1.0.15 - _November 9, 2018_ - - * Dependencies updated - -## v1.0.14 - _October 18, 2018_ - - * Dependencies updated - -## v1.0.13 - _October 4, 2018_ - - * Dependencies updated - -## v1.0.12 - _September 28, 2018_ - - * Dependencies updated - -## v1.0.11 - _September 25, 2018_ - - * Dependencies updated - -## v1.0.10 - _September 25, 2018_ - - * Dependencies updated - -## v1.0.9 - _September 21, 2018_ - - * Dependencies updated - -## v1.0.8 - _September 5, 2018_ - - * Dependencies updated - -## v1.0.7 - _August 27, 2018_ - - * Dependencies updated - -## v1.0.6 - _August 24, 2018_ - - * Dependencies updated - -## v1.0.5 - _August 14, 2018_ - - * Dependencies updated - -## v1.0.4 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.3 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.2 - _July 26, 2018_ - - * Dependencies updated - -## v1.0.1 - _July 23, 2018_ - - * Dependencies updated - -## v1.0.0 - _July 19, 2018_ - - * Dependencies updated - -## v0.0.17 - _July 18, 2018_ - - * Nest MD files under versions so that you can update them for future versions (#844) - -## v0.0.16 - _July 18, 2018_ - - * Dependencies updated - -## v0.0.15 - _July 9, 2018_ - - * Dependencies updated - -## v0.0.14 - _June 19, 2018_ - - * Dependencies updated - -## v0.0.13 - _May 31, 2018_ - - * Incorrect publish that was unpublished - -## v0.0.12 - _May 22, 2018_ - - * Dependencies updated - -## v0.0.11 - _May 4, 2018_ - - * Dependencies updated - -## v0.0.10 - _May 4, 2018_ - - * Dependencies updated - -## v0.0.9 - _May 4, 2018_ - - * Dependencies updated - -## v0.0.8 - _April 18, 2018_ - - * Added support for rendering default param values (#519) - * Added support for rendering nested function types within interface types (#519) - * Improve type comment rendering (#535) - -## v0.0.7 - _April 11, 2018_ - - * Dependencies updated - -## v0.0.6 - _April 2, 2018_ - - * Dependencies updated - -## v0.0.5 - _April 2, 2018_ - - * Handle `reflection` type rendering so that anonymous function type declarations render properly (#465) - * Rename `MethodSignature` to `Signature` and change it's props so that it can be used to render method and function signatures. (#465) - * Rename `MethodBlock` to `SignatureBlock` since it is not used to render method and function signature blocks. (#465) - * Add support for documenting exported functions. (#465) - -## v0.0.3 - _March 17, 2018_ - - * Move TS typings from devDependencies to dependencies since they are needed by the package user. - -## v0.0.2 - _March 17, 2018_ - - * Move example out into a separate sub-package - * Consolidate all `console.log` calls into `logUtils` in the `@0xproject/utils` package (#452) diff --git a/packages/react-docs/README.md b/packages/react-docs/README.md deleted file mode 100644 index 7b1f4f80a..000000000 --- a/packages/react-docs/README.md +++ /dev/null @@ -1,96 +0,0 @@ -## @0x/react-docs - -#### WARNING: Alpha software. Expect things to break when trying to use. - -A full-page React component for rendering beautiful documentation for Solidity and Typescript code generated with [TypeDoc](http://typedoc.org/) or [sol-doc](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-doc). - -<div style="text-align: center;"> -<img src="https://s3.eu-west-2.amazonaws.com/0x-wiki-images/screenshot.png" style="padding-bottom: 20px; padding-top: 20px;" width="80%" /> -<div>react-docs generating 0x's smart contract docs</div> -</div> - -#### Features - -- Mobile optimized -- Reads Javadoc-style comments in your code to generate class/method/argument/return/type comments. -- Syntax highlighting support for TypeScript & Solidity -- Type declaration linking -- Type declaration popovers to avoid clicking through to the definition -- Section/method/type anchors for easily pointing others to a specific part of your docs. -- Version picker -- Customizable sidebar header -- Supports custom markdown sections so you can easily add an intro or installation instructions. - -## Installation - -```bash -yarn add @0x/react-docs -``` - -## Usage - -This package exposes both a single `Documentation` react component that will render a docs page, as well as all of it's sub-components in case someone wants to build their own layout. - -Currently this package still has some external dependencies outside of the `Documentation` component, so please start your project off by copying the [react-docs-example](https://github.com/0xProject/0x-monorepo/tree/development/packages/react-docs-example) directory and modifying it there. If you need changes in the [react-docs](https://github.com/0xProject/0x-monorepo/tree/development/packages/react-docs) package, fork the 0x monorepo, make the required changes and submit a PR. Until we merge it, you can have your project depend on your own custom fork. - -If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: - -```json -"compilerOptions": { - "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"], -} -``` - -## Future improvements - -Feel free to contribute to these improvements! - -- Allow user to pass in styling for all major elements similar to [Material-UI](http://www.material-ui.com/). -- Allow user to define an alternative font and have it change everywhere. -- Add source links to Solidity docs (currently unsupported by solc, which underlies sol-doc). - -## Contributing - -We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository. - -Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. - -### Install dependencies - -If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: - -```bash -yarn config set workspaces-experimental true -``` - -Then install dependencies - -```bash -yarn install -``` - -### Build - -To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: - -```bash -PKG=@0x/react-docs yarn build -``` - -Or continuously rebuild on change: - -```bash -PKG=@0x/react-docs yarn watch -``` - -### Clean - -```bash -yarn clean -``` - -### Lint - -```bash -yarn lint -``` diff --git a/packages/react-docs/package.json b/packages/react-docs/package.json deleted file mode 100644 index f8f2b6276..000000000 --- a/packages/react-docs/package.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "@0x/react-docs", - "version": "1.0.25", - "engines": { - "node": ">=6.12" - }, - "description": "React documentation component for rendering TypeDoc & sol-doc generated JSON", - "main": "lib/index.js", - "types": "lib/index.d.ts", - "scripts": { - "lint": "tslint --format stylish --project .", - "build": "tsc -b", - "build:ci": "yarn build", - "clean": "shx rm -rf lib" - }, - "author": "Fabio Berger", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/0xProject/0x-monorepo/issues" - }, - "homepage": "https://github.com/0xProject/0x-monorepo/packages/react-docs/README.md", - "repository": { - "type": "git", - "url": "https://github.com/0xProject/0x-monorepo.git" - }, - "devDependencies": { - "@0x/dev-utils": "^1.0.24", - "@0x/tslint-config": "^2.0.2", - "@types/compare-versions": "^3.0.0", - "@types/styled-components": "4.0.0", - "make-promises-safe": "^1.1.0", - "shx": "^0.2.2", - "tslint": "^5.9.1", - "typescript": "3.0.1" - }, - "dependencies": { - "@0x/react-shared": "^1.1.2", - "@0x/types": "^1.5.2", - "@0x/utils": "^3.0.1", - "@types/lodash": "4.14.104", - "@types/material-ui": "^0.20.0", - "@types/node": "*", - "@types/react": "*", - "@types/react-dom": "*", - "@types/react-scroll": "1.5.3", - "basscss": "^8.0.3", - "compare-versions": "^3.0.1", - "lodash": "^4.17.5", - "material-ui": "^0.20.0", - "react": "^16.5.2", - "react-dom": "^16.5.2", - "react-markdown": "^3.2.2", - "react-scroll": "0xproject/react-scroll#pr-330-and-replace-state", - "react-tooltip": "^3.2.7", - "semver": "5.5.0", - "styled-components": "^4.0.1" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/react-docs/src/components/badge.tsx b/packages/react-docs/src/components/badge.tsx deleted file mode 100644 index e3d5be273..000000000 --- a/packages/react-docs/src/components/badge.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { Styles } from '@0x/react-shared'; -import * as React from 'react'; - -const styles: Styles = { - badge: { - width: 50, - fontSize: 11, - height: 10, - borderRadius: 5, - lineHeight: 0.9, - fontFamily: 'Roboto Mono', - marginLeft: 3, - marginRight: 3, - }, -}; - -export interface BadgeProps { - title: string; - backgroundColor: string; -} - -export interface BadgeState { - isHovering: boolean; -} - -export class Badge extends React.Component<BadgeProps, BadgeState> { - constructor(props: BadgeProps) { - super(props); - this.state = { - isHovering: false, - }; - } - public render(): React.ReactNode { - const badgeStyle = { - ...styles.badge, - backgroundColor: this.props.backgroundColor, - opacity: this.state.isHovering ? 0.7 : 1, - }; - return ( - <div - className="p1 center" - style={badgeStyle} - onMouseOver={this._setHoverState.bind(this, true)} - onMouseOut={this._setHoverState.bind(this, false)} - > - {this.props.title} - </div> - ); - } - private _setHoverState(isHovering: boolean): void { - this.setState({ - isHovering, - }); - } -} diff --git a/packages/react-docs/src/components/comment.tsx b/packages/react-docs/src/components/comment.tsx deleted file mode 100644 index 4d34f711e..000000000 --- a/packages/react-docs/src/components/comment.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { colors, MarkdownCodeBlock } from '@0x/react-shared'; -import * as React from 'react'; -import * as ReactMarkdown from 'react-markdown'; - -export interface CommentProps { - comment: string; - className?: string; -} - -const defaultProps = { - className: '', -}; - -export const Comment: React.SFC<CommentProps> = (props: CommentProps) => { - return ( - <div className={`${props.className} comment`} style={{ color: colors.greyTheme }}> - <ReactMarkdown source={props.comment} renderers={{ code: MarkdownCodeBlock }} /> - </div> - ); -}; - -Comment.defaultProps = defaultProps; diff --git a/packages/react-docs/src/components/custom_enum.tsx b/packages/react-docs/src/components/custom_enum.tsx deleted file mode 100644 index e971a012a..000000000 --- a/packages/react-docs/src/components/custom_enum.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { logUtils } from '@0x/utils'; -import * as _ from 'lodash'; -import * as React from 'react'; - -import { CustomType } from '@0x/types'; - -const STRING_ENUM_CODE_PREFIX = ' strEnum('; - -export interface CustomEnumProps { - type: CustomType; -} - -// This component renders custom string enums that was a work-around for versions of -// TypeScript <2.4.0 that did not support them natively. We keep it around to support -// older versions of 0x.js <0.9.0 -export const CustomEnum = (props: CustomEnumProps) => { - const type = props.type; - if (!_.startsWith(type.defaultValue, STRING_ENUM_CODE_PREFIX)) { - logUtils.log('We do not yet support `Variable` types that are not strEnums'); - return null; - } - // Remove the prefix and postfix, leaving only the strEnum values without quotes. - const enumValues = type.defaultValue.slice(10, -3).replace(/'/g, ''); - return ( - <span> - {`{`} - {'\t'} - {enumValues} - <br /> - {`}`} - </span> - ); -}; diff --git a/packages/react-docs/src/components/doc_reference.tsx b/packages/react-docs/src/components/doc_reference.tsx deleted file mode 100644 index 424fe9ecf..000000000 --- a/packages/react-docs/src/components/doc_reference.tsx +++ /dev/null @@ -1,318 +0,0 @@ -import { - colors, - constants as sharedConstants, - EtherscanLinkSuffixes, - HeaderSizes, - Link, - MarkdownSection, - Networks, - SectionHeader, - utils as sharedUtils, -} from '@0x/react-shared'; -import { - DocAgnosticFormat, - Event, - ExternalExportToLink, - Property, - SolidityMethod, - TypeDefinitionByName, - TypescriptFunction, - TypescriptMethod, -} from '@0x/types'; -import * as _ from 'lodash'; -import * as React from 'react'; -import * as semver from 'semver'; - -import { DocsInfo } from '../docs_info'; -import { AddressByContractName, SupportedDocJson } from '../types'; -import { constants } from '../utils/constants'; - -import { Badge } from './badge'; -import { Comment } from './comment'; -import { EventDefinition } from './event_definition'; -import { PropertyBlock } from './property_block'; -import { SignatureBlock } from './signature_block'; -import { TypeDefinition } from './type_definition'; - -const networkNameToColor: { [network: string]: string } = { - [Networks.Kovan]: colors.purple, - [Networks.Ropsten]: colors.red, - [Networks.Mainnet]: colors.turquois, - [Networks.Rinkeby]: colors.darkYellow, -}; - -export interface DocReferenceProps { - selectedVersion: string; - availableVersions: string[]; - docsInfo: DocsInfo; - sourceUrl: string; - docAgnosticFormat?: DocAgnosticFormat; -} - -export interface DocReferenceState {} - -export class DocReference extends React.Component<DocReferenceProps, DocReferenceState> { - public componentDidUpdate(prevProps: DocReferenceProps, _prevState: DocReferenceState): void { - if (!_.isEqual(prevProps.docAgnosticFormat, this.props.docAgnosticFormat)) { - const hash = window.location.hash.slice(1); - sharedUtils.scrollToHash(hash, sharedConstants.SCROLL_CONTAINER_ID); - } - } - public render(): React.ReactNode { - const subMenus = _.values(this.props.docsInfo.markdownMenu); - const orderedSectionNames = _.flatten(subMenus); - - const typeDefinitionByName = this.props.docsInfo.getTypeDefinitionsByName(this.props.docAgnosticFormat); - const renderedSections = _.map(orderedSectionNames, this._renderSection.bind(this, typeDefinitionByName)); - - return ( - <div> - <div id={sharedConstants.SCROLL_TOP_ID} /> - {renderedSections} - </div> - ); - } - private _renderSection(typeDefinitionByName: TypeDefinitionByName, sectionName: string): React.ReactNode { - const markdownVersions = _.keys(this.props.docsInfo.sectionNameToMarkdownByVersion); - const eligibleVersions = _.filter(markdownVersions, mdVersion => { - return semver.lte(mdVersion, this.props.selectedVersion); - }); - if (_.isEmpty(eligibleVersions)) { - throw new Error( - `No eligible markdown sections found for ${this.props.docsInfo.displayName} version ${ - this.props.selectedVersion - }.`, - ); - } - const sortedEligibleVersions = eligibleVersions.sort(semver.rcompare.bind(semver)); - const closestVersion = sortedEligibleVersions[0]; - const markdownFileIfExists = this.props.docsInfo.sectionNameToMarkdownByVersion[closestVersion][sectionName]; - if (!_.isUndefined(markdownFileIfExists)) { - // Special-case replace the `introduction` sectionName with the package name - const isIntroductionSection = sectionName === 'introduction'; - const headerSize = isIntroductionSection ? HeaderSizes.H1 : HeaderSizes.H3; - return ( - <MarkdownSection - key={`markdown-section-${sectionName}`} - sectionName={sectionName} - headerSize={headerSize} - markdownContent={markdownFileIfExists} - alternativeSectionTitle={isIntroductionSection ? this.props.docsInfo.displayName : undefined} - /> - ); - } - - const docSection = this.props.docAgnosticFormat[sectionName]; - if (_.isUndefined(docSection)) { - return null; - } - - const isExportedFunctionSection = - docSection.functions.length === 1 && - _.isEmpty(docSection.types) && - _.isEmpty(docSection.methods) && - _.isEmpty(docSection.constructors) && - _.isEmpty(docSection.properties) && - _.isEmpty(docSection.events); - - const sortedTypes = _.sortBy(docSection.types, 'name'); - const typeDefs = _.map(sortedTypes, (customType, i) => { - return ( - <TypeDefinition - sectionName={sectionName} - key={`type-${customType.name}-${i}`} - customType={customType} - docsInfo={this.props.docsInfo} - typeDefinitionByName={typeDefinitionByName} - isInPopover={false} - /> - ); - }); - - const sortedProperties = _.sortBy(docSection.properties, 'name'); - const propertyDefs = _.map( - sortedProperties, - this._renderProperty.bind(this, sectionName, typeDefinitionByName), - ); - - const sortedMethods = _.sortBy(docSection.methods, 'name'); - const methodDefs = _.map(sortedMethods, method => { - return this._renderSignatureBlocks(method, sectionName, typeDefinitionByName); - }); - - const sortedFunctions = _.sortBy(docSection.functions, 'name'); - const functionDefs = _.map(sortedFunctions, func => { - return this._renderSignatureBlocks(func, sectionName, typeDefinitionByName); - }); - - const sortedEvents = _.sortBy(docSection.events, 'name'); - const eventDefs = _.map(sortedEvents, (event: Event, i: number) => { - return ( - <EventDefinition - key={`event-${event.name}-${i}`} - event={event} - sectionName={sectionName} - docsInfo={this.props.docsInfo} - /> - ); - }); - const headerStyle: React.CSSProperties = { - fontWeight: 100, - }; - return ( - <div key={`section-${sectionName}`} className="py2 pr3 md-pl2 sm-pl3"> - <div className="flex pb2"> - <div style={{ marginRight: 7 }}> - <SectionHeader sectionName={sectionName} /> - </div> - {this._renderNetworkBadgesIfExists(sectionName)} - </div> - {docSection.comment && <Comment comment={docSection.comment} />} - {!_.isEmpty(docSection.constructors) && ( - <div> - <h2 style={headerStyle}>Constructor</h2> - {this._renderConstructors(docSection.constructors, sectionName, typeDefinitionByName)} - </div> - )} - {!_.isEmpty(docSection.properties) && ( - <div> - <h2 style={headerStyle}>Properties</h2> - <div>{propertyDefs}</div> - </div> - )} - {!_.isEmpty(docSection.methods) && ( - <div> - <h2 style={headerStyle}>Methods</h2> - <div>{methodDefs}</div> - </div> - )} - {!_.isEmpty(docSection.functions) && ( - <div> - {!isExportedFunctionSection && ( - <div style={{ ...headerStyle, fontSize: '1.5em' }}>Functions</div> - )} - <div>{functionDefs}</div> - </div> - )} - {!_.isUndefined(docSection.events) && docSection.events.length > 0 && ( - <div> - <h2 style={headerStyle}>Events</h2> - <div>{eventDefs}</div> - </div> - )} - {!_.isUndefined(docSection.externalExportToLink) && - this._renderExternalExports(docSection.externalExportToLink)} - {!_.isUndefined(typeDefs) && typeDefs.length > 0 && ( - <div> - <div>{typeDefs}</div> - </div> - )} - <div - style={{ - width: '100%', - height: 1, - backgroundColor: colors.grey300, - marginTop: 32, - marginBottom: 12, - }} - /> - </div> - ); - } - private _renderExternalExports(externalExportToLink: ExternalExportToLink): React.ReactNode { - const externalExports = _.map(externalExportToLink, (link: string, exportName: string) => { - return ( - <div className="pt2" key={`external-export-${exportName}`}> - <code className={`hljs ${constants.TYPE_TO_SYNTAX[this.props.docsInfo.type]}`}> - {`import { `} - <Link to={link} shouldOpenInNewTab={true} fontColor={colors.lightBlueA700}> - {exportName} - </Link> - {` } from '${this.props.docsInfo.packageName}'`} - </code> - </div> - ); - }); - return <div>{externalExports}</div>; - } - private _renderNetworkBadgesIfExists(sectionName: string): React.ReactNode { - if (this.props.docsInfo.type !== SupportedDocJson.SolDoc) { - return null; - } - - const networkToAddressByContractName = this.props.docsInfo.contractsByVersionByNetworkId[ - this.props.selectedVersion - ]; - const badges = _.map( - networkToAddressByContractName, - (addressByContractName: AddressByContractName, networkName: string) => { - const contractAddress = addressByContractName[sectionName]; - if (_.isUndefined(contractAddress)) { - return null; - } - const linkIfExists = sharedUtils.getEtherScanLinkIfExists( - contractAddress, - sharedConstants.NETWORK_ID_BY_NAME[networkName], - EtherscanLinkSuffixes.Address, - ); - return ( - <div style={{ marginTop: 8 }}> - <Link - key={`badge-${networkName}-${sectionName}`} - to={linkIfExists} - shouldOpenInNewTab={true} - fontColor={colors.white} - > - <Badge title={networkName} backgroundColor={networkNameToColor[networkName]} /> - </Link> - </div> - ); - }, - ); - return badges; - } - private _renderConstructors( - constructors: SolidityMethod[] | TypescriptMethod[], - sectionName: string, - typeDefinitionByName: TypeDefinitionByName, - ): React.ReactNode { - const constructorDefs = _.map(constructors, constructor => { - return this._renderSignatureBlocks(constructor, sectionName, typeDefinitionByName); - }); - return <div>{constructorDefs}</div>; - } - private _renderProperty( - sectionName: string, - typeDefinitionByName: TypeDefinitionByName, - property: Property, - ): React.ReactNode { - return ( - <PropertyBlock - key={`property-${property.name}-${property.type.name}`} - property={property} - sectionName={sectionName} - docsInfo={this.props.docsInfo} - sourceUrl={this.props.sourceUrl} - selectedVersion={this.props.selectedVersion} - typeDefinitionByName={typeDefinitionByName} - /> - ); - } - private _renderSignatureBlocks( - method: SolidityMethod | TypescriptFunction | TypescriptMethod, - sectionName: string, - typeDefinitionByName: TypeDefinitionByName, - ): React.ReactNode { - return ( - <SignatureBlock - key={`method-${method.name}-${sectionName}`} - sectionName={sectionName} - method={method} - typeDefinitionByName={typeDefinitionByName} - libraryVersion={this.props.selectedVersion} - docsInfo={this.props.docsInfo} - sourceUrl={this.props.sourceUrl} - /> - ); - } -} diff --git a/packages/react-docs/src/components/enum.tsx b/packages/react-docs/src/components/enum.tsx deleted file mode 100644 index dee866790..000000000 --- a/packages/react-docs/src/components/enum.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import * as _ from 'lodash'; -import * as React from 'react'; - -import { EnumValue } from '../types'; - -export interface EnumProps { - values: EnumValue[]; -} - -export const Enum = (props: EnumProps) => { - const values = _.map(props.values, value => { - const defaultValueIfAny = !_.isUndefined(value.defaultValue) ? ` = ${value.defaultValue}` : ''; - return `\n\t${value.name}${defaultValueIfAny},`; - }); - return ( - <span> - {`{`} - {values} - <br /> - {`}`} - </span> - ); -}; diff --git a/packages/react-docs/src/components/event_definition.tsx b/packages/react-docs/src/components/event_definition.tsx deleted file mode 100644 index b76769788..000000000 --- a/packages/react-docs/src/components/event_definition.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import { AnchorTitle, colors, HeaderSizes } from '@0x/react-shared'; -import { Event, EventArg } from '@0x/types'; -import * as _ from 'lodash'; -import * as React from 'react'; - -import { DocsInfo } from '../docs_info'; - -import { Type } from './type'; - -export interface EventDefinitionProps { - event: Event; - sectionName: string; - docsInfo: DocsInfo; -} - -export interface EventDefinitionState { - shouldShowAnchor: boolean; -} - -export class EventDefinition extends React.Component<EventDefinitionProps, EventDefinitionState> { - constructor(props: EventDefinitionProps) { - super(props); - this.state = { - shouldShowAnchor: false, - }; - } - public render(): React.ReactNode { - const event = this.props.event; - const id = `${this.props.sectionName}-${event.name}`; - return ( - <div - id={id} - className="pb2" - style={{ overflow: 'hidden', width: '100%' }} - onMouseOver={this._setAnchorVisibility.bind(this, true)} - onMouseOut={this._setAnchorVisibility.bind(this, false)} - > - <AnchorTitle - headerSize={HeaderSizes.H3} - title={`Event ${event.name}`} - id={id} - shouldShowAnchor={this.state.shouldShowAnchor} - /> - <div style={{ fontSize: 16 }}> - <pre> - <code className="hljs solidity">{this._renderEventCode()}</code> - </pre> - </div> - </div> - ); - } - private _renderEventCode(): React.ReactNode { - const indexed = <span style={{ color: colors.green }}> indexed</span>; - const eventArgs = _.map(this.props.event.eventArgs, (eventArg: EventArg) => { - const type = ( - <Type - type={eventArg.type} - sectionName={this.props.sectionName} - docsInfo={this.props.docsInfo} - isInPopover={false} - /> - ); - return ( - <span key={`eventArg-${eventArg.name}`}> - {eventArg.name} - {eventArg.isIndexed ? indexed : ''}: {type}, - </span> - ); - }); - const argList = _.reduce(eventArgs, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, '\n\t', curr]; - }); - return ( - <span> - {`{`} - <br /> - {'\t'} - {argList} - <br /> - {`}`} - </span> - ); - } - private _setAnchorVisibility(shouldShowAnchor: boolean): void { - this.setState({ - shouldShowAnchor, - }); - } -} diff --git a/packages/react-docs/src/components/interface.tsx b/packages/react-docs/src/components/interface.tsx deleted file mode 100644 index 06896159f..000000000 --- a/packages/react-docs/src/components/interface.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import * as _ from 'lodash'; -import * as React from 'react'; - -import { CustomType, TypeDefinitionByName } from '@0x/types'; - -import { DocsInfo } from '../docs_info'; - -import { Signature } from './signature'; -import { Type } from './type'; - -const defaultProps = {}; - -export interface InterfaceProps { - type: CustomType; - sectionName: string; - docsInfo: DocsInfo; - typeDefinitionByName: TypeDefinitionByName; - isInPopover: boolean; -} - -export const Interface: React.SFC<InterfaceProps> = (props: InterfaceProps): any => { - const type = props.type; - const properties = _.map(type.children, (property, i) => { - return ( - <span key={`property-${property.name}-${property.type}-${type.name}-${i}`}> - {property.name}:{' '} - {property.type && !_.isUndefined(property.type.method) ? ( - <Signature - name={property.type.method.name} - returnType={property.type.method.returnType} - parameters={property.type.method.parameters} - typeParameter={property.type.method.typeParameter} - sectionName={props.sectionName} - shouldHideMethodName={true} - shouldUseArrowSyntax={true} - docsInfo={props.docsInfo} - typeDefinitionByName={props.typeDefinitionByName} - isInPopover={props.isInPopover} - /> - ) : ( - <Type - type={property.type} - sectionName={props.sectionName} - docsInfo={props.docsInfo} - typeDefinitionByName={props.typeDefinitionByName} - isInPopover={props.isInPopover} - /> - )} - , - </span> - ); - }); - const hasIndexSignature = !_.isUndefined(type.indexSignature); - if (hasIndexSignature) { - const is = type.indexSignature; - const param = ( - <span key={`indexSigParams-${is.keyName}-${is.keyType}-${type.name}`}> - {is.keyName}:{' '} - <Type - type={is.keyType} - sectionName={props.sectionName} - docsInfo={props.docsInfo} - typeDefinitionByName={props.typeDefinitionByName} - isInPopover={props.isInPopover} - /> - </span> - ); - properties.push( - <span key={`indexSignature-${type.name}-${is.keyType.name}`}> - [{param}]: {is.valueName}, - </span>, - ); - } - const propertyList = _.reduce(properties, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, '\n\t', curr]; - }); - return ( - <span> - {`{`} - <br /> - {'\t'} - {propertyList} - <br /> - {`}`} - </span> - ); -}; - -Interface.defaultProps = defaultProps; diff --git a/packages/react-docs/src/components/property_block.tsx b/packages/react-docs/src/components/property_block.tsx deleted file mode 100644 index d0bd84802..000000000 --- a/packages/react-docs/src/components/property_block.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import { AnchorTitle, HeaderSizes } from '@0x/react-shared'; -import { Property, TypeDefinitionByName } from '@0x/types'; -import * as React from 'react'; - -import { DocsInfo } from '../docs_info'; -import { constants } from '../utils/constants'; - -import { Comment } from './comment'; -import { SourceLink } from './source_link'; -import { Type } from './type'; - -export interface PropertyBlockProps { - property: Property; - sectionName: string; - docsInfo: DocsInfo; - sourceUrl: string; - selectedVersion: string; - typeDefinitionByName: TypeDefinitionByName; -} - -export interface PropertyBlockState { - shouldShowAnchor: boolean; -} - -export class PropertyBlock extends React.Component<PropertyBlockProps, PropertyBlockState> { - constructor(props: PropertyBlockProps) { - super(props); - this.state = { - shouldShowAnchor: false, - }; - } - public render(): React.ReactNode { - const property = this.props.property; - const sectionName = this.props.sectionName; - return ( - <div - id={`${this.props.sectionName}-${property.name}`} - className="pb4 pt2" - key={`property-${property.name}-${property.type.name}`} - onMouseOver={this._setAnchorVisibility.bind(this, true)} - onMouseOut={this._setAnchorVisibility.bind(this, false)} - > - <div className="pb2" style={{ lineHeight: 1.3 }}> - <AnchorTitle - headerSize={HeaderSizes.H3} - title={property.name} - id={`${sectionName}-${property.name}`} - shouldShowAnchor={this.state.shouldShowAnchor} - /> - </div> - <code className={`hljs ${constants.TYPE_TO_SYNTAX[this.props.docsInfo.type]}`}> - {(property as any).callPath} - {property.name}:{' '} - <Type - type={property.type} - sectionName={sectionName} - docsInfo={this.props.docsInfo} - typeDefinitionByName={this.props.typeDefinitionByName} - isInPopover={false} - /> - </code> - {property.source && ( - <SourceLink - version={this.props.selectedVersion} - source={property.source} - sourceUrl={this.props.sourceUrl} - /> - )} - {property.comment && <Comment comment={property.comment} className="py2" />} - </div> - ); - } - private _setAnchorVisibility(shouldShowAnchor: boolean): void { - this.setState({ - shouldShowAnchor, - }); - } -} diff --git a/packages/react-docs/src/components/signature.tsx b/packages/react-docs/src/components/signature.tsx deleted file mode 100644 index c229999b1..000000000 --- a/packages/react-docs/src/components/signature.tsx +++ /dev/null @@ -1,164 +0,0 @@ -import * as _ from 'lodash'; -import * as React from 'react'; - -import { Parameter, Type as TypeDef, TypeDefinitionByName, TypeParameter } from '@0x/types'; - -import { DocsInfo } from '../docs_info'; - -import { Type } from './type'; - -export interface SignatureProps { - name: string; - returnType: TypeDef; - parameters: Parameter[]; - sectionName: string; - shouldHideMethodName?: boolean; - shouldUseArrowSyntax?: boolean; - typeDefinitionByName?: TypeDefinitionByName; - typeParameter?: TypeParameter; - callPath?: string; - docsInfo: DocsInfo; - isInPopover: boolean; - isFallback?: boolean; -} - -const defaultProps = { - shouldHideMethodName: false, - shouldUseArrowSyntax: false, - callPath: '', - isFallback: false, -}; - -export const Signature: React.SFC<SignatureProps> = (props: SignatureProps) => { - const sectionName = props.sectionName; - const parameters = renderParameters( - props.parameters, - props.docsInfo, - sectionName, - props.isInPopover, - props.name, - props.typeDefinitionByName, - ); - const paramStringArray: any[] = []; - // HACK: For now we don't put params on newlines if there are less then 2 of them. - // Ideally we would check the character length of the resulting method signature and - // if it exceeds the available space, put params on their own lines. - const hasMoreThenTwoParams = parameters.length > 2; - _.each(parameters, (param: React.ReactNode, i: number) => { - const finalParam = hasMoreThenTwoParams ? ( - <span className="pl2" key={`param-${i}`}> - {param} - </span> - ) : ( - param - ); - paramStringArray.push(finalParam); - const comma = hasMoreThenTwoParams ? ( - <span key={`param-comma-${i}`}> - , <br /> - </span> - ) : ( - ', ' - ); - paramStringArray.push(comma); - }); - if (!hasMoreThenTwoParams) { - paramStringArray.pop(); - } - const methodName = props.shouldHideMethodName ? '' : props.name; - const typeParameterIfExists = _.isUndefined(props.typeParameter) - ? undefined - : renderTypeParameter( - props.typeParameter, - props.docsInfo, - sectionName, - props.isInPopover, - props.typeDefinitionByName, - ); - return ( - <span style={{ fontSize: 15 }}> - {props.callPath} - {props.isFallback ? '' : methodName} - {typeParameterIfExists}({hasMoreThenTwoParams && <br />} - {paramStringArray}) - {props.returnType && ( - <span> - {props.shouldUseArrowSyntax ? ' => ' : ': '}{' '} - <Type - type={props.returnType} - sectionName={sectionName} - typeDefinitionByName={props.typeDefinitionByName} - docsInfo={props.docsInfo} - isInPopover={props.isInPopover} - /> - </span> - )} - </span> - ); -}; - -Signature.defaultProps = defaultProps; - -function renderParameters( - parameters: Parameter[], - docsInfo: DocsInfo, - sectionName: string, - isInPopover: boolean, - name: string, - typeDefinitionByName?: TypeDefinitionByName, -): React.ReactNode[] { - const params = _.map(parameters, (p: Parameter, i: number) => { - const isOptional = p.isOptional; - const hasDefaultValue = !_.isUndefined(p.defaultValue); - const type = ( - <Type - type={p.type} - sectionName={sectionName} - typeDefinitionByName={typeDefinitionByName} - docsInfo={docsInfo} - isInPopover={isInPopover} - /> - ); - return ( - <span key={`param-${JSON.stringify(p.type)}-${name}-${i}`}> - {!_.isEmpty(p.name) && ( - <span> - {p.name} - {isOptional && '?'}:{' '} - </span> - )} - {type} - {hasDefaultValue && ` = ${p.defaultValue}`} - </span> - ); - }); - return params; -} - -function renderTypeParameter( - typeParameter: TypeParameter, - docsInfo: DocsInfo, - sectionName: string, - isInPopover: boolean, - typeDefinitionByName?: TypeDefinitionByName, -): React.ReactNode { - const typeParam = ( - <span> - {`<${typeParameter.name}`} - {!_.isUndefined(typeParameter.type) && ( - <span> - {' extends '} - <Type - type={typeParameter.type} - sectionName={sectionName} - typeDefinitionByName={typeDefinitionByName} - docsInfo={docsInfo} - isInPopover={isInPopover} - /> - </span> - )} - {`>`} - </span> - ); - return typeParam; -} diff --git a/packages/react-docs/src/components/signature_block.tsx b/packages/react-docs/src/components/signature_block.tsx deleted file mode 100644 index 3189d86cf..000000000 --- a/packages/react-docs/src/components/signature_block.tsx +++ /dev/null @@ -1,153 +0,0 @@ -import { AnchorTitle, colors, HeaderSizes, Styles } from '@0x/react-shared'; -import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptFunction, TypescriptMethod } from '@0x/types'; -import * as _ from 'lodash'; -import * as React from 'react'; - -import { DocsInfo } from '../docs_info'; -import { constants } from '../utils/constants'; - -import { Comment } from './comment'; -import { Signature } from './signature'; -import { SourceLink } from './source_link'; - -export interface SignatureBlockProps { - method: SolidityMethod | TypescriptFunction | TypescriptMethod; - sectionName: string; - libraryVersion: string; - typeDefinitionByName: TypeDefinitionByName; - docsInfo: DocsInfo; - sourceUrl: string; -} - -export interface SignatureBlockState { - shouldShowAnchor: boolean; -} - -const styles: Styles = { - chip: { - fontSize: 13, - color: colors.white, - height: 11, - borderRadius: 14, - lineHeight: 0.9, - }, -}; - -export class SignatureBlock extends React.Component<SignatureBlockProps, SignatureBlockState> { - constructor(props: SignatureBlockProps) { - super(props); - this.state = { - shouldShowAnchor: false, - }; - } - public render(): React.ReactNode { - const method = this.props.method; - - const isFallback = (method as SolidityMethod).isFallback; - const hasExclusivelyNamedParams = !_.isUndefined(_.find(method.parameters, p => !_.isEmpty(p.name))); - return ( - <div - id={`${this.props.sectionName}-${method.name}`} - style={{ overflow: 'hidden', width: '100%' }} - className="pb4 pt2" - onMouseOver={this._setAnchorVisibility.bind(this, true)} - onMouseOut={this._setAnchorVisibility.bind(this, false)} - > - {!(method as TypescriptMethod).isConstructor && ( - <div className="flex pb2 pt2"> - {(method as TypescriptMethod).isStatic && this._renderChip('Static')} - {(method as SolidityMethod).isConstant && this._renderChip('Constant')} - {(method as SolidityMethod).isPayable && this._renderChip('Payable')} - {isFallback && this._renderChip('Fallback', colors.lightGreenA700)} - <div style={{ lineHeight: 1.3 }}> - <AnchorTitle - headerSize={HeaderSizes.H3} - title={isFallback ? '' : method.name} - id={`${this.props.sectionName}-${method.name}`} - shouldShowAnchor={this.state.shouldShowAnchor} - /> - </div> - </div> - )} - <code className={`hljs ${constants.TYPE_TO_SYNTAX[this.props.docsInfo.type]}`}> - <Signature - name={method.name} - returnType={method.returnType} - parameters={method.parameters} - typeParameter={(method as TypescriptMethod).typeParameter} - callPath={(method as TypescriptMethod).callPath} - sectionName={this.props.sectionName} - typeDefinitionByName={this.props.typeDefinitionByName} - docsInfo={this.props.docsInfo} - isInPopover={false} - isFallback={isFallback} - /> - </code> - {(method as TypescriptMethod).source && ( - <SourceLink - version={this.props.libraryVersion} - source={(method as TypescriptMethod).source} - sourceUrl={this.props.sourceUrl} - /> - )} - {method.comment && <Comment comment={method.comment} className="py2" />} - {method.parameters && !_.isEmpty(method.parameters) && hasExclusivelyNamedParams && ( - <div> - <h4 className="pb1 thin" style={{ borderBottom: '1px solid #e1e8ed' }}> - ARGUMENTS - </h4> - {this._renderParameterDescriptions(method.parameters, method.name)} - </div> - )} - {method.returnComment && ( - <div className="pt1 comment"> - <h4 className="pb1 thin" style={{ borderBottom: '1px solid #e1e8ed' }}> - RETURNS - </h4> - <Comment comment={method.returnComment} /> - </div> - )} - </div> - ); - } - private _renderChip(text: string, backgroundColor: string = colors.lightBlueA700): React.ReactNode { - return ( - <div className="p1 mr1" style={{ ...styles.chip, backgroundColor }}> - {text} - </div> - ); - } - private _renderParameterDescriptions(parameters: Parameter[], name: string): React.ReactNode { - const descriptions = _.map(parameters, (parameter: Parameter, i: number) => { - const isOptional = parameter.isOptional; - return ( - <div - key={`param-description-${parameter.name}-${name}-${i}`} - className="flex pb1 mb2" - style={{ borderBottom: '1px solid #f0f4f7' }} - > - <div className="pl2 col lg-col-4 md-col-4 sm-col-12 col-12"> - <div - className="bold" - style={{ overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }} - > - {parameter.name} - </div> - <div className="pt1" style={{ color: colors.grey, fontSize: 14 }}> - {isOptional && 'optional'} - </div> - </div> - <div className="col lg-col-8 md-col-8 sm-col-12 col-12" style={{ paddingLeft: 5 }}> - {parameter.comment && <Comment comment={parameter.comment} />} - </div> - </div> - ); - }); - return descriptions; - } - private _setAnchorVisibility(shouldShowAnchor: boolean): void { - this.setState({ - shouldShowAnchor, - }); - } -} diff --git a/packages/react-docs/src/components/source_link.tsx b/packages/react-docs/src/components/source_link.tsx deleted file mode 100644 index 6459824c2..000000000 --- a/packages/react-docs/src/components/source_link.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { colors, Link } from '@0x/react-shared'; -import { Source } from '@0x/types'; -import * as React from 'react'; - -export interface SourceLinkProps { - source: Source; - sourceUrl: string; - version: string; -} - -export const SourceLink = (props: SourceLinkProps) => { - const src = props.source; - const sourceCodeUrl = `${props.sourceUrl}/${src.fileName}#L${src.line}`; - return ( - <div className="pt2" style={{ fontSize: 14 }}> - <Link to={sourceCodeUrl} shouldOpenInNewTab={true} textDecoration="underline" fontColor={colors.grey}> - {'Source'} - </Link> - </div> - ); -}; diff --git a/packages/react-docs/src/components/type.tsx b/packages/react-docs/src/components/type.tsx deleted file mode 100644 index 894c3f560..000000000 --- a/packages/react-docs/src/components/type.tsx +++ /dev/null @@ -1,271 +0,0 @@ -import { colors, Link, utils as sharedUtils } from '@0x/react-shared'; -import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from '@0x/types'; -import { errorUtils } from '@0x/utils'; -import * as _ from 'lodash'; -import * as React from 'react'; -import * as ReactTooltip from 'react-tooltip'; - -import { DocsInfo } from '../docs_info'; - -import { Signature } from './signature'; -import { TypeDefinition } from './type_definition'; - -const basicJsTypes = ['string', 'number', 'undefined', 'null', 'boolean']; -const basicSolidityTypes = ['bytes', 'bytes4', 'bytes32', 'uint8', 'uint256', 'address']; - -const defaultProps = {}; - -export interface TypeProps { - type: TypeDef; - docsInfo: DocsInfo; - sectionName: string; - typeDefinitionByName?: TypeDefinitionByName; - isInPopover: boolean; -} - -// The return type needs to be `any` here so that we can recursively define <Type /> components within -// <Type /> components (e.g when rendering the union type). -export const Type: React.SFC<TypeProps> = (props: TypeProps): any => { - const type = props.type; - const isReference = type.typeDocType === TypeDocTypes.Reference; - const isArray = type.typeDocType === TypeDocTypes.Array; - let typeNameColor = 'inherit'; - let typeName: string | React.ReactNode; - let typeArgs: React.ReactNode[] = []; - switch (type.typeDocType) { - case TypeDocTypes.Intrinsic: - case TypeDocTypes.Unknown: - typeName = type.name; - typeNameColor = colors.orange; - break; - - case TypeDocTypes.Reference: - typeName = type.name; - typeArgs = _.map(type.typeArguments, (arg: TypeDef) => { - if (arg.typeDocType === TypeDocTypes.Array) { - const key = `type-${arg.elementType.name}-${arg.elementType.typeDocType}`; - return ( - <span> - <Type - key={key} - type={arg} - sectionName={props.sectionName} - typeDefinitionByName={props.typeDefinitionByName} - docsInfo={props.docsInfo} - isInPopover={props.isInPopover} - /> - [] - </span> - ); - } else { - const subType = ( - <Type - key={`type-${arg.name}-${arg.value}-${arg.typeDocType}`} - type={arg} - sectionName={props.sectionName} - typeDefinitionByName={props.typeDefinitionByName} - docsInfo={props.docsInfo} - isInPopover={props.isInPopover} - /> - ); - return subType; - } - }); - break; - - case TypeDocTypes.StringLiteral: - typeName = `'${type.value}'`; - typeNameColor = colors.green; - break; - - case TypeDocTypes.Array: - typeName = type.elementType.name; - if (_.includes(basicJsTypes, typeName) || _.includes(basicSolidityTypes, typeName)) { - typeNameColor = colors.orange; - } - break; - - case TypeDocTypes.Union: - const unionTypes = _.map(type.types, t => { - return ( - <Type - key={`type-${t.name}-${t.value}-${t.typeDocType}`} - type={t} - sectionName={props.sectionName} - typeDefinitionByName={props.typeDefinitionByName} - docsInfo={props.docsInfo} - isInPopover={props.isInPopover} - /> - ); - }); - typeName = _.reduce(unionTypes, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, '|', curr]; - }); - break; - - case TypeDocTypes.Reflection: - if (!_.isUndefined(type.method)) { - typeName = ( - <Signature - name={type.method.name} - returnType={type.method.returnType} - parameters={type.method.parameters} - typeParameter={type.method.typeParameter} - sectionName={props.sectionName} - shouldHideMethodName={true} - shouldUseArrowSyntax={true} - docsInfo={props.docsInfo} - typeDefinitionByName={props.typeDefinitionByName} - isInPopover={props.isInPopover} - /> - ); - } else if (!_.isUndefined(type.indexSignature)) { - const is = type.indexSignature; - const param = ( - <span key={`indexSigParams-${is.keyName}-${is.keyType}-${type.name}`}> - {is.keyName}:{' '} - <Type - type={is.keyType} - sectionName={props.sectionName} - docsInfo={props.docsInfo} - typeDefinitionByName={props.typeDefinitionByName} - isInPopover={props.isInPopover} - /> - </span> - ); - typeName = ( - <span key={`indexSignature-${type.name}-${is.keyType.name}`}> - {'{'}[{param}]: {is.valueName} - {'}'} - </span> - ); - } else { - throw new Error(`Unrecognized Reflection type that isn't a Method nor an Index Signature`); - } - - break; - - case TypeDocTypes.TypeParameter: - typeName = type.name; - break; - - case TypeDocTypes.Intersection: - const intersectionsTypes = _.map(type.types, t => { - return ( - <Type - key={`type-${t.name}-${t.value}-${t.typeDocType}`} - type={t} - sectionName={props.sectionName} - typeDefinitionByName={props.typeDefinitionByName} - docsInfo={props.docsInfo} - isInPopover={props.isInPopover} - /> - ); - }); - typeName = _.reduce(intersectionsTypes, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, '&', curr]; - }); - break; - - case TypeDocTypes.Tuple: - const tupleTypes = _.map(type.tupleElements, (t, i) => { - return ( - <Type - key={`type-tuple-${t.name}-${t.typeDocType}-${i}`} - type={t} - sectionName={props.sectionName} - typeDefinitionByName={props.typeDefinitionByName} - docsInfo={props.docsInfo} - isInPopover={props.isInPopover} - /> - ); - }); - typeName = ( - <div> - [ - {_.reduce(tupleTypes, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, ', ', curr]; - })} - ] - </div> - ); - break; - - default: - throw errorUtils.spawnSwitchErr('type.typeDocType', type.typeDocType); - } - // HACK: Normalize BigNumber to simply BigNumber. For some reason the type - // name is unpredictably one or the other. - if (typeName === 'BigNumber') { - typeName = 'BigNumber'; - } - const commaSeparatedTypeArgs = _.reduce(typeArgs, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, ', ', curr]; - }); - - const isExportedClassReference = !!props.type.isExportedClassReference; - const typeNameUrlIfExists = !_.isUndefined(props.type.externalLink) ? props.type.externalLink : undefined; - if (!_.isUndefined(typeNameUrlIfExists)) { - typeName = props.isInPopover ? ( - <span style={{ color: colors.lightBlueA700, cursor: 'pointer' }}>{typeName}</span> - ) : ( - <Link to={typeNameUrlIfExists} shouldOpenInNewTab={true} fontColor={colors.lightBlueA700}> - {typeName} - </Link> - ); - } else if ( - (isReference || isArray) && - ((props.typeDefinitionByName && props.typeDefinitionByName[typeName as string]) || isExportedClassReference) - ) { - const id = Math.random().toString(); - const typeDefinitionAnchorId = isExportedClassReference - ? props.type.name - : `${props.docsInfo.typeSectionName}-${typeName}`; - typeName = ( - <span> - {sharedUtils.isUserOnMobile() || props.isInPopover || isExportedClassReference ? ( - <span style={{ color: colors.lightBlueA700, cursor: 'pointer' }}>{typeName}</span> - ) : ( - <Link to={typeDefinitionAnchorId}> - <span - data-tip={true} - data-for={id} - style={{ - color: colors.lightBlueA700, - cursor: 'pointer', - display: 'inline-block', - }} - > - {typeName} - <ReactTooltip type="light" effect="solid" id={id} className="typeTooltip"> - <TypeDefinition - sectionName={props.sectionName} - customType={props.typeDefinitionByName[typeName as string]} - shouldAddId={false} - docsInfo={props.docsInfo} - typeDefinitionByName={props.typeDefinitionByName} - isInPopover={true} - /> - </ReactTooltip> - </span> - </Link> - )} - </span> - ); - } - return ( - <span> - <span style={{ color: typeNameColor }}>{typeName}</span> - {isArray && '[]'} - {!_.isEmpty(typeArgs) && ( - <span> - {'<'} - {commaSeparatedTypeArgs} - {'>'} - </span> - )} - </span> - ); -}; - -Type.defaultProps = defaultProps; diff --git a/packages/react-docs/src/components/type_definition.tsx b/packages/react-docs/src/components/type_definition.tsx deleted file mode 100644 index a1fde51da..000000000 --- a/packages/react-docs/src/components/type_definition.tsx +++ /dev/null @@ -1,188 +0,0 @@ -import { AnchorTitle, colors, HeaderSizes } from '@0x/react-shared'; -import { CustomType, CustomTypeChild, TypeDefinitionByName, TypeDocTypes } from '@0x/types'; -import { errorUtils } from '@0x/utils'; -import * as _ from 'lodash'; -import * as React from 'react'; - -import { DocsInfo } from '../docs_info'; -import { KindString, SupportedDocJson } from '../types'; -import { constants } from '../utils/constants'; - -import { Comment } from './comment'; -import { CustomEnum } from './custom_enum'; -import { Enum } from './enum'; -import { Interface } from './interface'; -import { Signature } from './signature'; -import { Type } from './type'; - -export interface TypeDefinitionProps { - sectionName: string; - customType: CustomType; - shouldAddId?: boolean; - docsInfo: DocsInfo; - typeDefinitionByName?: TypeDefinitionByName; - isInPopover?: boolean; -} - -export interface TypeDefinitionState { - shouldShowAnchor: boolean; -} - -export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDefinitionState> { - public static defaultProps: Partial<TypeDefinitionProps> = { - shouldAddId: true, - isInPopover: false, - }; - constructor(props: TypeDefinitionProps) { - super(props); - this.state = { - shouldShowAnchor: false, - }; - } - public render(): React.ReactNode { - const customType = this.props.customType; - - let typePrefix: string; - let codeSnippet: React.ReactNode; - switch (customType.kindString) { - case KindString.Interface: - typePrefix = this.props.docsInfo.type === SupportedDocJson.SolDoc ? 'Struct' : 'Interface'; - codeSnippet = ( - <Interface - type={customType} - sectionName={this.props.sectionName} - docsInfo={this.props.docsInfo} - typeDefinitionByName={this.props.typeDefinitionByName} - isInPopover={this.props.isInPopover} - /> - ); - break; - - case KindString.Variable: - typePrefix = 'Enum'; - codeSnippet = <CustomEnum type={customType} />; - break; - - case KindString.Enumeration: - typePrefix = 'Enum'; - const enumValues = _.map(customType.children, (c: CustomTypeChild) => { - return { - name: c.name, - defaultValue: c.defaultValue, - }; - }); - codeSnippet = <Enum values={enumValues} />; - break; - - case KindString.TypeAlias: - typePrefix = 'Type Alias'; - codeSnippet = ( - <span> - <span style={{ color: colors.lightPurple }}>type</span> {customType.name} ={' '} - {customType.type.typeDocType !== TypeDocTypes.Reflection ? ( - <Type - type={customType.type} - sectionName={this.props.sectionName} - docsInfo={this.props.docsInfo} - typeDefinitionByName={this.props.typeDefinitionByName} - isInPopover={this.props.isInPopover} - /> - ) : ( - <Signature - name={customType.type.method.name} - returnType={customType.type.method.returnType} - parameters={customType.type.method.parameters} - typeParameter={customType.type.method.typeParameter} - callPath={customType.type.method.callPath} - sectionName={this.props.sectionName} - shouldHideMethodName={true} - shouldUseArrowSyntax={true} - docsInfo={this.props.docsInfo} - typeDefinitionByName={this.props.typeDefinitionByName} - isInPopover={this.props.isInPopover} - /> - )} - </span> - ); - break; - - default: - throw errorUtils.spawnSwitchErr('type.kindString', customType.kindString); - } - - const typeDefinitionAnchorId = `${this.props.sectionName}-${customType.name}`; - return ( - <div - id={this.props.shouldAddId ? typeDefinitionAnchorId : ''} - className="pb2 pt2" - style={{ overflow: 'hidden', width: '100%' }} - onMouseOver={this._setAnchorVisibility.bind(this, true)} - onMouseOut={this._setAnchorVisibility.bind(this, false)} - > - <AnchorTitle - headerSize={HeaderSizes.H3} - title={`${typePrefix} ${customType.name}`} - id={this.props.shouldAddId ? typeDefinitionAnchorId : ''} - shouldShowAnchor={this.state.shouldShowAnchor} - isDisabled={this.props.isInPopover} - /> - <div style={{ fontSize: 16 }}> - <pre> - <code className={`hljs ${constants.TYPE_TO_SYNTAX[this.props.docsInfo.type]}`}> - {codeSnippet} - </code> - </pre> - </div> - <div style={{ maxWidth: 620 }}> - {customType.comment && ( - <Comment comment={this._formatComment(customType.comment)} className="py2" /> - )} - </div> - </div> - ); - } - private _setAnchorVisibility(shouldShowAnchor: boolean): void { - this.setState({ - shouldShowAnchor, - }); - } - /** - * Type definition comments usually describe the type as a whole or the individual - * properties within the type. Since TypeDoc just treats these comments simply as - * one paragraph, we do some additional formatting so that we can display individual - * property comments on their own lines. - * E.g: - * Interface SomeConfig - * { - * networkId: number, - * derivationPath: string, - * } - * networkId: The ethereum networkId to set as the chainId from EIP155 - * derivationPath: Initial derivation path to use e.g 44'/60'/0' - * - * Each property description should be on a new line. - */ - private _formatComment(text: string): string { - const NEW_LINE_REGEX = /(\r\n|\n|\r)/gm; - const sanitizedText = text.replace(NEW_LINE_REGEX, ' '); - const PROPERTY_DESCRIPTION_DIVIDER = ':'; - if (!_.includes(sanitizedText, PROPERTY_DESCRIPTION_DIVIDER)) { - return sanitizedText; - } - const segments = sanitizedText.split(PROPERTY_DESCRIPTION_DIVIDER); - _.each(segments, (s: string, i: number) => { - if (i === 0) { - segments[i] = `**${s}**`; - return; - } else if (i === segments.length - 1) { - return; - } - const words = s.split(' '); - const property = words[words.length - 1]; - words[words.length - 1] = `\n\n**${property}**`; - segments[i] = words.join(' '); - }); - const final = segments.join(PROPERTY_DESCRIPTION_DIVIDER); - return final; - } -} diff --git a/packages/react-docs/src/docs_info.ts b/packages/react-docs/src/docs_info.ts deleted file mode 100644 index 76f7784ba..000000000 --- a/packages/react-docs/src/docs_info.ts +++ /dev/null @@ -1,118 +0,0 @@ -import { ALink, utils as sharedUtils } from '@0x/react-shared'; -import { DocAgnosticFormat, ObjectMap, TypeDefinitionByName } from '@0x/types'; -import * as _ from 'lodash'; - -import { - ContractsByVersionByNetworkId, - DocsInfoConfig, - DocsMenu, - SectionNameToMarkdownByVersion, - SectionsMap, - SupportedDocJson, -} from './types'; -import { constants } from './utils/constants'; - -export class DocsInfo { - public id: string; - public type: SupportedDocJson; - public displayName: string; - public packageName: string; - public packageUrl: string; - public markdownMenu: DocsMenu; - public typeSectionName: string; - public sections: SectionsMap; - public sectionNameToMarkdownByVersion: SectionNameToMarkdownByVersion; - public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId; - constructor(config: DocsInfoConfig) { - this.id = config.id; - this.type = config.type; - this.markdownMenu = config.markdownMenu; - this.displayName = config.displayName; - this.packageName = config.packageName; - this.packageUrl = config.packageUrl; - this.typeSectionName = config.type === SupportedDocJson.SolDoc ? 'structs' : 'types'; - this.sections = config.markdownSections; - this.sectionNameToMarkdownByVersion = config.sectionNameToMarkdownByVersion; - this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId; - } - public getTypeDefinitionsByName(docAgnosticFormat: DocAgnosticFormat): ObjectMap<TypeDefinitionByName> { - if (_.isUndefined(docAgnosticFormat[this.typeSectionName])) { - return {}; - } - - const section = docAgnosticFormat[this.typeSectionName]; - const typeDefinitionByName = _.keyBy(section.types, 'name') as any; - return typeDefinitionByName; - } - public getSectionNameToLinks(docAgnosticFormat: DocAgnosticFormat): ObjectMap<ALink[]> { - const sectionNameToLinks: ObjectMap<ALink[]> = {}; - _.each(this.markdownMenu, (linkTitles, sectionName) => { - sectionNameToLinks[sectionName] = []; - _.each(linkTitles, linkTitle => { - const to = sharedUtils.getIdFromName(linkTitle); - const links = sectionNameToLinks[sectionName]; - links.push({ - title: linkTitle, - to, - }); - }); - }); - - if (_.isUndefined(docAgnosticFormat)) { - return sectionNameToLinks; - } - - const docSections = _.keys(this.sections); - _.each(docSections, sectionName => { - const docSection = docAgnosticFormat[sectionName]; - if (_.isUndefined(docSection) || sectionName === constants.EXTERNAL_EXPORTS_SECTION_NAME) { - return; // no-op - } - - const isExportedFunctionSection = - docSection.functions.length === 1 && - _.isEmpty(docSection.types) && - _.isEmpty(docSection.methods) && - _.isEmpty(docSection.constructors) && - _.isEmpty(docSection.properties) && - _.isEmpty(docSection.events); - - if (sectionName === this.typeSectionName) { - const sortedTypesNames = _.sortBy(docSection.types, 'name'); - const typeNames = _.map(sortedTypesNames, t => t.name); - const typeLinks = _.map(typeNames, typeName => { - return { - to: `${sectionName}-${typeName}`, - title: typeName, - }; - }); - sectionNameToLinks[sectionName] = typeLinks; - } else if (isExportedFunctionSection) { - // Noop so that we don't have the method listed underneath itself. - } else { - let eventNames: string[] = []; - if (!_.isUndefined(docSection.events)) { - const sortedEventNames = _.sortBy(docSection.events, 'name'); - eventNames = _.map(sortedEventNames, m => m.name); - } - const propertiesSortedByName = _.sortBy(docSection.properties, 'name'); - const propertyNames = _.map(propertiesSortedByName, m => m.name); - const methodsSortedByName = _.sortBy(docSection.methods, 'name'); - const methodNames = _.map(methodsSortedByName, m => m.name); - const sortedFunctionNames = _.sortBy(docSection.functions, 'name'); - const functionNames = _.map(sortedFunctionNames, m => m.name); - const names = [...eventNames, ...propertyNames, ...functionNames, ...methodNames]; - - const links = _.map(names, name => { - return { - to: `${sectionName}-${name}`, - title: name, - }; - }); - - sectionNameToLinks[sectionName] = links; - } - }); - return sectionNameToLinks; - } -} diff --git a/packages/react-docs/src/globals.d.ts b/packages/react-docs/src/globals.d.ts deleted file mode 100644 index 94e63a32d..000000000 --- a/packages/react-docs/src/globals.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare module '*.json' { - const json: any; - /* tslint:disable */ - export default json; - /* tslint:enable */ -} diff --git a/packages/react-docs/src/index.ts b/packages/react-docs/src/index.ts deleted file mode 100644 index a5ed788b1..000000000 --- a/packages/react-docs/src/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -export { DocAgnosticFormat, GeneratedDocJson } from '@0x/types'; - -// Exported to give users of this library added flexibility if they want to build -// a docs page from scratch using the individual components. -export { Badge } from './components/badge'; -export { Comment } from './components/comment'; -export { CustomEnum } from './components/custom_enum'; -export { DocReference } from './components/doc_reference'; -export { Enum } from './components/enum'; -export { EventDefinition } from './components/event_definition'; -export { Interface } from './components/interface'; -export { SignatureBlock } from './components/signature_block'; -export { Signature } from './components/signature'; -export { SourceLink } from './components/source_link'; -export { TypeDefinition } from './components/type_definition'; -export { Type } from './components/type'; -export { TypeDocUtils } from './utils/typedoc_utils'; - -export { DocsInfo } from './docs_info'; - -export { DocsInfoConfig, DocsMenu, SupportedDocJson } from './types'; - -export { constants } from './utils/constants'; diff --git a/packages/react-docs/src/types.ts b/packages/react-docs/src/types.ts deleted file mode 100644 index 153448513..000000000 --- a/packages/react-docs/src/types.ts +++ /dev/null @@ -1,66 +0,0 @@ -export interface SectionNameToMarkdownByVersion { - [version: string]: { [sectionName: string]: string }; -} - -export interface DocsInfoConfig { - id: string; - packageName: string; - type: SupportedDocJson; - displayName: string; - packageUrl: string; - markdownMenu: DocsMenu; - markdownSections: SectionsMap; - sectionNameToMarkdownByVersion: SectionNameToMarkdownByVersion; - contractsByVersionByNetworkId?: ContractsByVersionByNetworkId; -} - -export interface DocsMenu { - [sectionName: string]: string[]; -} - -export interface SectionsMap { - [sectionName: string]: string; -} - -// Exception: We don't make the values uppercase because these KindString's need to -// match up those returned by TypeDoc -export enum KindString { - Constructor = 'Constructor', - Property = 'Property', - Method = 'Method', - Interface = 'Interface', - TypeAlias = 'Type alias', - ObjectLiteral = 'Object literal', - Variable = 'Variable', - Function = 'Function', - Enumeration = 'Enumeration', - Class = 'Class', -} - -export enum SupportedDocJson { - SolDoc = 'SOL_DOC', - TypeDoc = 'TYPEDOC', -} - -export interface ContractsByVersionByNetworkId { - [version: string]: { - [networkName: string]: { - [contractName: string]: string; - }; - }; -} - -export interface AddressByContractName { - [contractName: string]: string; -} - -export interface EnumValue { - name: string; - defaultValue?: string; -} - -export enum AbiTypes { - Constructor = 'constructor', - Function = 'function', - Event = 'event', -} diff --git a/packages/react-docs/src/utils/constants.ts b/packages/react-docs/src/utils/constants.ts deleted file mode 100644 index b5b6cc00d..000000000 --- a/packages/react-docs/src/utils/constants.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { SupportedDocJson } from '../types'; - -export const constants = { - TYPES_SECTION_NAME: 'types', - EXTERNAL_EXPORTS_SECTION_NAME: 'external exports', - TYPE_TO_SYNTAX: { - [SupportedDocJson.SolDoc]: 'solidity', - [SupportedDocJson.TypeDoc]: 'typescript', - } as { [supportedDocType: string]: string }, -}; diff --git a/packages/react-docs/src/utils/typedoc_utils.ts b/packages/react-docs/src/utils/typedoc_utils.ts deleted file mode 100644 index f74ec3e28..000000000 --- a/packages/react-docs/src/utils/typedoc_utils.ts +++ /dev/null @@ -1,507 +0,0 @@ -import { - CustomType, - CustomTypeChild, - DocAgnosticFormat, - DocSection, - ExternalExportToLink, - ExternalTypeToLink, - GeneratedDocJson, - IndexSignature, - Parameter, - Property, - Type, - TypeDocNode, - TypeDocType, - TypeDocTypes, - TypeParameter, - TypescriptFunction, - TypescriptMethod, -} from '@0x/types'; -import { errorUtils } from '@0x/utils'; -import * as _ from 'lodash'; - -import { DocsInfo } from '../docs_info'; -import { KindString } from '../types'; - -import { constants } from './constants'; - -export class TypeDocUtils { - private readonly _typeDocNameOrder: string[]; - private readonly _externalTypeToLink: ExternalTypeToLink; - private readonly _externalExportToLink: ExternalExportToLink; - private readonly _docsInfo: DocsInfo; - private readonly _typeDocJson: TypeDocNode; - private readonly _classNames: string[]; - constructor(generatedDocJson: GeneratedDocJson, docsInfo: DocsInfo) { - this._docsInfo = docsInfo; - const exportPathOrder = generatedDocJson.metadata.exportPathOrder; - const exportPathToTypedocNames = generatedDocJson.metadata.exportPathToTypedocNames; - this._externalTypeToLink = generatedDocJson.metadata.externalTypeToLink; - this._externalExportToLink = generatedDocJson.metadata.externalExportToLink; - this._typeDocJson = generatedDocJson.typedocJson; - - this._typeDocNameOrder = _.compact( - _.flatten( - _.map(exportPathOrder, exportPath => { - return exportPathToTypedocNames[exportPath]; - }), - ), - ); - - this._classNames = []; - _.each(this._typeDocJson.children, file => { - _.each(file.children, child => { - if (child.kindString === KindString.Class) { - this._classNames.push(child.name); - } - }); - }); - } - public isType(entity: TypeDocNode): boolean { - return ( - entity.kindString === KindString.Interface || - entity.kindString === KindString.Function || - entity.kindString === KindString.TypeAlias || - entity.kindString === KindString.Variable || - entity.kindString === KindString.Enumeration - ); - } - public isMethod(entity: TypeDocNode): boolean { - return entity.kindString === KindString.Method; - } - public isConstructor(entity: TypeDocNode): boolean { - return entity.kindString === KindString.Constructor; - } - public isProperty(entity: TypeDocNode): boolean { - return entity.kindString === KindString.Property; - } - public isUnderscorePrefixed(name: string): boolean { - return _.startsWith(name, '_'); - } - public getModuleDefinitionsBySectionName(versionDocObj: TypeDocNode, configModulePaths: string[]): TypeDocNode[] { - const moduleDefinitions: TypeDocNode[] = []; - const jsonModules = versionDocObj.children; - _.each(jsonModules, jsonMod => { - _.each(configModulePaths, configModulePath => { - if (_.includes(configModulePath, jsonMod.name)) { - moduleDefinitions.push(jsonMod); - } - }); - }); - return moduleDefinitions; - } - public convertToDocAgnosticFormat(): DocAgnosticFormat { - const docAgnosticFormat: DocAgnosticFormat = {}; - - if (!_.isEmpty(this._externalExportToLink)) { - this._docsInfo.sections[constants.EXTERNAL_EXPORTS_SECTION_NAME] = constants.EXTERNAL_EXPORTS_SECTION_NAME; - this._docsInfo.markdownMenu[constants.EXTERNAL_EXPORTS_SECTION_NAME] = [ - constants.EXTERNAL_EXPORTS_SECTION_NAME, - ]; - const docSection: DocSection = { - comment: 'This package also re-exports some third-party libraries for your convenience.', - constructors: [], - methods: [], - functions: [], - properties: [], - types: [], - externalExportToLink: this._externalExportToLink, - }; - docAgnosticFormat[constants.EXTERNAL_EXPORTS_SECTION_NAME] = docSection; - } - - const typeEntities: TypeDocNode[] = []; - _.each(this._typeDocNameOrder, typeDocName => { - const fileChildIndex = _.findIndex(this._typeDocJson.children, child => child.name === typeDocName); - const fileChild = this._typeDocJson.children[fileChildIndex]; - let sectionName: string; - _.each(fileChild.children, child => { - switch (child.kindString) { - case KindString.Class: - case KindString.ObjectLiteral: { - sectionName = child.name; - this._docsInfo.sections[sectionName] = sectionName; - this._docsInfo.markdownMenu[sectionName] = [sectionName]; - const entities = child.children; - const commentObj = child.comment; - const sectionComment = !_.isUndefined(commentObj) ? commentObj.shortText : ''; - const isClassOrObjectLiteral = true; - const docSection = this._convertEntitiesToDocSection( - entities, - sectionName, - isClassOrObjectLiteral, - ); - docSection.comment = sectionComment; - docAgnosticFormat[sectionName] = docSection; - break; - } - case KindString.Function: { - sectionName = child.name; - this._docsInfo.sections[sectionName] = sectionName; - this._docsInfo.markdownMenu[sectionName] = [sectionName]; - const entities = [child]; - const commentObj = child.comment; - const SectionComment = !_.isUndefined(commentObj) ? commentObj.shortText : ''; - const docSection = this._convertEntitiesToDocSection(entities, sectionName); - docSection.comment = SectionComment; - docAgnosticFormat[sectionName] = docSection; - break; - } - case KindString.Interface: - case KindString.Variable: - case KindString.Enumeration: - case KindString.TypeAlias: - typeEntities.push(child); - break; - default: - throw errorUtils.spawnSwitchErr('kindString', child.kindString); - } - }); - }); - if (!_.isEmpty(typeEntities)) { - this._docsInfo.sections[constants.TYPES_SECTION_NAME] = constants.TYPES_SECTION_NAME; - this._docsInfo.markdownMenu[constants.TYPES_SECTION_NAME] = [constants.TYPES_SECTION_NAME]; - const docSection = this._convertEntitiesToDocSection(typeEntities, constants.TYPES_SECTION_NAME); - docAgnosticFormat[constants.TYPES_SECTION_NAME] = docSection; - } - - return docAgnosticFormat; - } - private _convertEntitiesToDocSection( - entities: TypeDocNode[], - sectionName: string, - isClassOrObjectLiteral: boolean = false, - ): DocSection { - const docSection: DocSection = { - comment: '', - constructors: [], - methods: [], - functions: [], - properties: [], - types: [], - }; - - let isConstructor; - _.each(entities, entity => { - switch (entity.kindString) { - case KindString.Constructor: - isConstructor = true; - const constructor = this._convertMethod(entity, isConstructor, sectionName); - docSection.constructors.push(constructor); - break; - - case KindString.Function: - if (entity.flags.isExported) { - const funcName = entity.signatures[0].name; - if (!this.isUnderscorePrefixed(funcName)) { - const func = this._convertFunction(entity, sectionName, isClassOrObjectLiteral); - docSection.functions.push(func); - } - } - break; - - case KindString.Method: - if (entity.flags.isPublic && !this.isUnderscorePrefixed(entity.name)) { - isConstructor = false; - const method = this._convertMethod(entity, isConstructor, sectionName); - docSection.methods.push(method); - } - break; - - case KindString.Property: { - if (!this.isUnderscorePrefixed(entity.name)) { - const property = this._convertProperty(entity, sectionName); - docSection.properties.push(property); - } - break; - } - - case KindString.Variable: - if (isClassOrObjectLiteral) { - // Render as a property - const property = this._convertProperty(entity, sectionName); - docSection.properties.push(property); - } else { - // Otherwise, render as a type - const customType = this._convertCustomType(entity, sectionName); - const seenTypeNames = _.map(docSection.types, t => t.name); - const isUnseen = !_.includes(seenTypeNames, customType.name); - if (isUnseen) { - docSection.types.push(customType); - } - } - break; - - case KindString.Interface: - case KindString.Enumeration: - case KindString.TypeAlias: { - const customType = this._convertCustomType(entity, sectionName); - const seenTypeNames = _.map(docSection.types, t => t.name); - const isUnseen = !_.includes(seenTypeNames, customType.name); - if (isUnseen) { - docSection.types.push(customType); - } - break; - } - - case KindString.Class: - // We currently do not support more then a single class per file - // except for the types section, where we ignore classes since we - // only want to render type definitions. - break; - - default: - throw errorUtils.spawnSwitchErr('kindString', entity.kindString); - } - }); - return docSection; - } - private _convertCustomType(entity: TypeDocNode, sectionName: string): CustomType { - const typeIfExists = !_.isUndefined(entity.type) ? this._convertType(entity.type, sectionName) : undefined; - const isConstructor = false; - const methodIfExists = !_.isUndefined(entity.declaration) - ? this._convertMethod(entity.declaration, isConstructor, sectionName) - : undefined; - const doesIndexSignatureExist = !_.isUndefined(entity.indexSignature); - const indexSignature = entity.indexSignature; - const indexSignatureIfExists = doesIndexSignatureExist - ? this._convertIndexSignature(indexSignature, sectionName) - : undefined; - const commentIfExists = - !_.isUndefined(entity.comment) && !_.isUndefined(entity.comment.shortText) - ? entity.comment.shortText - : undefined; - - const childrenIfExist = !_.isUndefined(entity.children) - ? _.map(entity.children, (child: TypeDocNode) => { - let childTypeIfExists = !_.isUndefined(child.type) - ? this._convertType(child.type, sectionName) - : undefined; - if (child.kindString === KindString.Method) { - childTypeIfExists = { - name: child.name, - typeDocType: TypeDocTypes.Reflection, - method: this._convertMethod(child, isConstructor, sectionName), - }; - } - const c: CustomTypeChild = { - name: child.name, - type: childTypeIfExists, - defaultValue: child.defaultValue, - }; - return c; - }) - : undefined; - - const customType = { - name: entity.name, - kindString: entity.kindString, - type: typeIfExists, - method: methodIfExists, - indexSignature: indexSignatureIfExists, - defaultValue: entity.defaultValue, - comment: commentIfExists, - children: childrenIfExist, - }; - return customType; - } - private _convertIndexSignature(entity: TypeDocNode, sectionName: string): IndexSignature { - const key = entity.parameters[0]; - const indexSignature = { - keyName: key.name, - keyType: this._convertType(key.type, sectionName), - valueName: entity.type.name, - }; - return indexSignature; - } - private _convertProperty(entity: TypeDocNode, sectionName: string): Property { - const source = entity.sources[0]; - const commentIfExists = !_.isUndefined(entity.comment) ? entity.comment.shortText : undefined; - const isConstructor = false; - const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic; - const callPath = this._getCallPath(sectionName, isStatic, isConstructor, entity.name); - const property = { - name: entity.name, - type: this._convertType(entity.type, sectionName), - source: { - fileName: source.fileName, - line: source.line, - }, - comment: commentIfExists, - callPath, - }; - return property; - } - private _convertMethod(entity: TypeDocNode, isConstructor: boolean, sectionName: string): TypescriptMethod { - const signature = entity.signatures[0]; - const source = entity.sources[0]; - const hasComment = !_.isUndefined(signature.comment); - const isStatic = _.isUndefined(entity.flags.isStatic) ? false : entity.flags.isStatic; - - const parameters = _.map(signature.parameters, param => { - return this._convertParameter(param, sectionName); - }); - const returnType = this._convertType(signature.type, sectionName); - const typeParameter = _.isUndefined(signature.typeParameter) - ? undefined - : this._convertTypeParameter(signature.typeParameter[0], sectionName); - - const callPath = this._getCallPath(sectionName, isStatic, isConstructor, entity.name); - const method = { - isConstructor, - isStatic, - name: signature.name, - comment: hasComment ? signature.comment.shortText : undefined, - returnComment: hasComment && signature.comment.returns ? signature.comment.returns : undefined, - source: { - fileName: source.fileName, - line: source.line, - callPath, - parameters, - returnType, - typeParameter, - }, - callPath, - parameters, - returnType, - typeParameter, - }; - return method; - } - private _getCallPath(sectionName: string, isStatic: boolean, isConstructor: boolean, entityName: string): string { - // HACK: we use the fact that the sectionName is the same as the property name at the top-level - // of the public interface. In the future, we shouldn't use this hack but rather get it from the JSON. - let callPath; - if (isConstructor || entityName === '__type') { - callPath = ''; - } else { - const prefix = isStatic ? sectionName : this._getLowercaseSectionName(sectionName); - callPath = `${prefix}.`; - } - return callPath; - } - private _getLowercaseSectionName(sectionName: string): string { - if (_.startsWith(sectionName, 'ERC')) { - return `${sectionName.slice(0, 3).toLowerCase()}${sectionName.slice(3)}`; - } - return `${sectionName[0].toLowerCase()}${sectionName.slice(1)}`; - } - private _convertFunction(entity: TypeDocNode, sectionName: string, isObjectLiteral: boolean): TypescriptFunction { - const signature = entity.signatures[0]; - const source = entity.sources[0]; - const hasComment = !_.isUndefined(signature.comment); - - const parameters = _.map(signature.parameters, param => { - return this._convertParameter(param, sectionName); - }); - const returnType = this._convertType(signature.type, sectionName); - const typeParameter = _.isUndefined(signature.typeParameter) - ? undefined - : this._convertTypeParameter(signature.typeParameter[0], sectionName); - - let callPath = ''; - if (isObjectLiteral) { - const isConstructor = false; - const isStatic = false; - callPath = this._getCallPath(sectionName, isStatic, isConstructor, entity.name); - } - const func = { - name: signature.name, - comment: hasComment ? signature.comment.shortText : undefined, - returnComment: hasComment && signature.comment.returns ? signature.comment.returns : undefined, - callPath, - source: { - fileName: source.fileName, - line: source.line, - }, - parameters, - returnType, - typeParameter, - }; - return func; - } - private _convertTypeParameter(entity: TypeDocNode, sectionName: string): TypeParameter { - let type; - if (!_.isUndefined(entity.type)) { - type = this._convertType(entity.type, sectionName); - } - const parameter = { - name: entity.name, - type, - }; - return parameter; - } - private _convertParameter(entity: TypeDocNode, sectionName: string): Parameter { - let comment = '<No comment>'; - if (entity.comment && entity.comment.shortText) { - comment = entity.comment.shortText; - } else if (entity.comment && entity.comment.text) { - comment = entity.comment.text; - } - - const isOptional = !_.isUndefined(entity.flags.isOptional) ? entity.flags.isOptional : false; - - const type = this._convertType(entity.type, sectionName); - - const parameter = { - name: entity.name, - comment, - isOptional, - defaultValue: entity.defaultValue, - type, - }; - return parameter; - } - private _convertType(entity: TypeDocType, sectionName: string): Type { - const typeArguments = _.map(entity.typeArguments, typeArgument => { - return this._convertType(typeArgument, sectionName); - }); - const types = _.map(entity.types, t => { - return this._convertType(t, sectionName); - }); - - let indexSignatureIfExists; - let methodIfExists; - let tupleElementsIfExists; - const doesIndexSignatureExist = - !_.isUndefined(entity.declaration) && !_.isUndefined(entity.declaration.indexSignature); - if (doesIndexSignatureExist) { - const indexSignature = entity.declaration.indexSignature; - indexSignatureIfExists = this._convertIndexSignature(indexSignature, sectionName); - } else if (!_.isUndefined(entity.declaration)) { - const isConstructor = false; - methodIfExists = this._convertMethod(entity.declaration, isConstructor, sectionName); - } else if (entity.type === TypeDocTypes.Tuple) { - tupleElementsIfExists = _.map(entity.elements, el => { - // the following line is required due to an open tslint issue, https://github.com/palantir/tslint/issues/3540 - // tslint:disable-next-line:no-unnecessary-type-assertion - return { name: el.name, typeDocType: el.type as TypeDocTypes }; - }); - } - - const elementTypeIfExists = !_.isUndefined(entity.elementType) - ? { - name: entity.elementType.name, - typeDocType: entity.elementType.type, - } - : undefined; - - const type: Type = { - name: entity.name, - value: entity.value, - isExportedClassReference: _.includes(this._classNames, entity.name), - typeDocType: entity.type, - typeArguments, - elementType: elementTypeIfExists, - types, - method: methodIfExists, - indexSignature: indexSignatureIfExists, - tupleElements: tupleElementsIfExists, - }; - const externalLinkIfExists = this._externalTypeToLink[entity.name]; - if (!_.isUndefined(externalLinkIfExists)) { - type.externalLink = externalLinkIfExists; - } - return type; - } -} // tslint:disable:max-file-line-count diff --git a/packages/react-docs/tsconfig.json b/packages/react-docs/tsconfig.json deleted file mode 100644 index 76e2cd027..000000000 --- a/packages/react-docs/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "rootDir": "src", - "jsx": "react", - "baseUrl": ".", - "strictNullChecks": false, - "paths": { - "*": ["node_modules/@types/*", "*"] - } - }, - "include": ["./src/**/*"] -} diff --git a/packages/react-docs/tslint.json b/packages/react-docs/tslint.json deleted file mode 100644 index c3f6d9cae..000000000 --- a/packages/react-docs/tslint.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": ["@0x/tslint-config"], - "rules": { - "no-object-literal-type-assertion": false, - "completed-docs": false, - "prefer-function-over-method": false, - "custom-no-magic-numbers": false - } -} |