From 0b1ba9f9971bea9003dfb30fca535c17ce62ad08 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 6 Mar 2018 16:31:55 +0100 Subject: Move Documentation to the `@0xproject/react-docs` package --- .../website/ts/pages/documentation/comment.tsx | 23 -- .../website/ts/pages/documentation/custom_enum.tsx | 32 -- .../website/ts/pages/documentation/doc_page.tsx | 5 +- .../website/ts/pages/documentation/docs_info.ts | 119 -------- .../ts/pages/documentation/documentation.tsx | 336 --------------------- packages/website/ts/pages/documentation/enum.tsx | 22 -- .../ts/pages/documentation/event_definition.tsx | 82 ----- .../website/ts/pages/documentation/interface.tsx | 61 ---- .../ts/pages/documentation/method_block.tsx | 147 --------- .../ts/pages/documentation/method_signature.tsx | 126 -------- .../website/ts/pages/documentation/source_link.tsx | 22 -- packages/website/ts/pages/documentation/type.tsx | 229 -------------- .../ts/pages/documentation/type_definition.tsx | 126 -------- 13 files changed, 2 insertions(+), 1328 deletions(-) delete mode 100644 packages/website/ts/pages/documentation/comment.tsx delete mode 100644 packages/website/ts/pages/documentation/custom_enum.tsx delete mode 100644 packages/website/ts/pages/documentation/docs_info.ts delete mode 100644 packages/website/ts/pages/documentation/documentation.tsx delete mode 100644 packages/website/ts/pages/documentation/enum.tsx delete mode 100644 packages/website/ts/pages/documentation/event_definition.tsx delete mode 100644 packages/website/ts/pages/documentation/interface.tsx delete mode 100644 packages/website/ts/pages/documentation/method_block.tsx delete mode 100644 packages/website/ts/pages/documentation/method_signature.tsx delete mode 100644 packages/website/ts/pages/documentation/source_link.tsx delete mode 100644 packages/website/ts/pages/documentation/type.tsx delete mode 100644 packages/website/ts/pages/documentation/type_definition.tsx (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/documentation/comment.tsx b/packages/website/ts/pages/documentation/comment.tsx deleted file mode 100644 index b8902679a..000000000 --- a/packages/website/ts/pages/documentation/comment.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { MarkdownCodeBlock } from '@0xproject/react-shared'; -import * as _ from 'lodash'; -import * as React from 'react'; -import * as ReactMarkdown from 'react-markdown'; - -interface CommentProps { - comment: string; - className?: string; -} - -const defaultProps = { - className: '', -}; - -export const Comment: React.SFC = (props: CommentProps) => { - return ( -
- -
- ); -}; - -Comment.defaultProps = defaultProps; diff --git a/packages/website/ts/pages/documentation/custom_enum.tsx b/packages/website/ts/pages/documentation/custom_enum.tsx deleted file mode 100644 index 8d50a2f52..000000000 --- a/packages/website/ts/pages/documentation/custom_enum.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import * as _ from 'lodash'; -import * as React from 'react'; -import { CustomType } from 'ts/types'; -import { utils } from 'ts/utils/utils'; - -const STRING_ENUM_CODE_PREFIX = ' strEnum('; - -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 function CustomEnum(props: CustomEnumProps) { - const type = props.type; - if (!_.startsWith(type.defaultValue, STRING_ENUM_CODE_PREFIX)) { - utils.consoleLog('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 ( - - {`{`} - {'\t'} - {enumValues} -
- {`}`} -
- ); -} diff --git a/packages/website/ts/pages/documentation/doc_page.tsx b/packages/website/ts/pages/documentation/doc_page.tsx index 83da81189..9bf6b528e 100644 --- a/packages/website/ts/pages/documentation/doc_page.tsx +++ b/packages/website/ts/pages/documentation/doc_page.tsx @@ -1,3 +1,4 @@ +import { DocAgnosticFormat, DocsInfo, Documentation, DoxityDocObj } from '@0xproject/react-docs'; import { MenuSubsectionsBySection } from '@0xproject/react-shared'; import findVersions = require('find-versions'); import * as _ from 'lodash'; @@ -5,10 +6,8 @@ import * as React from 'react'; import DocumentTitle = require('react-document-title'); import semverSort = require('semver-sort'); import { TopBar } from 'ts/components/top_bar/top_bar'; -import { DocsInfo } from 'ts/pages/documentation/docs_info'; -import { Documentation } from 'ts/pages/documentation/documentation'; import { Dispatcher } from 'ts/redux/dispatcher'; -import { DocAgnosticFormat, DocPackages, DoxityDocObj, Environments } from 'ts/types'; +import { DocPackages, Environments } from 'ts/types'; import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; import { docUtils } from 'ts/utils/doc_utils'; diff --git a/packages/website/ts/pages/documentation/docs_info.ts b/packages/website/ts/pages/documentation/docs_info.ts deleted file mode 100644 index 09fb7a2bc..000000000 --- a/packages/website/ts/pages/documentation/docs_info.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { MenuSubsectionsBySection } from '@0xproject/react-shared'; -import compareVersions = require('compare-versions'); -import * as _ from 'lodash'; -import { - ContractsByVersionByNetworkId, - DocAgnosticFormat, - DocsInfoConfig, - DocsMenu, - DoxityDocObj, - SectionsMap, - SupportedDocJson, - TypeDocNode, -} from 'ts/types'; -import { doxityUtils } from 'ts/utils/doxity_utils'; -import { typeDocUtils } from 'ts/utils/typedoc_utils'; - -export class DocsInfo { - public id: string; - public type: SupportedDocJson; - public displayName: string; - public packageUrl: string; - public menu: DocsMenu; - public sections: SectionsMap; - public sectionNameToMarkdown: { [sectionName: string]: string }; - public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId; - private _docsInfo: DocsInfoConfig; - constructor(config: DocsInfoConfig) { - this.id = config.id; - this.type = config.type; - this.displayName = config.displayName; - this.packageUrl = config.packageUrl; - this.sections = config.sections; - this.sectionNameToMarkdown = config.sectionNameToMarkdown; - this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId; - this._docsInfo = config; - } - public isPublicType(typeName: string): boolean { - if (_.isUndefined(this._docsInfo.publicTypes)) { - return false; - } - const isPublic = _.includes(this._docsInfo.publicTypes, typeName); - return isPublic; - } - public getModulePathsIfExists(sectionName: string): string[] { - const modulePathsIfExists = this._docsInfo.sectionNameToModulePath[sectionName]; - return modulePathsIfExists; - } - public getMenu(selectedVersion?: string): { [section: string]: string[] } { - if (_.isUndefined(selectedVersion) || _.isUndefined(this._docsInfo.menuSubsectionToVersionWhenIntroduced)) { - return this._docsInfo.menu; - } - - const finalMenu = _.cloneDeep(this._docsInfo.menu); - if (_.isUndefined(finalMenu.contracts)) { - return finalMenu; - } - - // TODO: refactor to include more sections then simply the `contracts` section - finalMenu.contracts = _.filter(finalMenu.contracts, (contractName: string) => { - const versionIntroducedIfExists = this._docsInfo.menuSubsectionToVersionWhenIntroduced[contractName]; - if (!_.isUndefined(versionIntroducedIfExists)) { - const existsInSelectedVersion = compareVersions(selectedVersion, versionIntroducedIfExists) >= 0; - return existsInSelectedVersion; - } else { - return true; - } - }); - return finalMenu; - } - public getMenuSubsectionsBySection(docAgnosticFormat?: DocAgnosticFormat): MenuSubsectionsBySection { - const menuSubsectionsBySection = {} as MenuSubsectionsBySection; - if (_.isUndefined(docAgnosticFormat)) { - return menuSubsectionsBySection; - } - - const docSections = _.keys(this.sections); - _.each(docSections, sectionName => { - const docSection = docAgnosticFormat[sectionName]; - if (_.isUndefined(docSection)) { - return; // no-op - } - - if (!_.isUndefined(this.sections.types) && sectionName === this.sections.types) { - const sortedTypesNames = _.sortBy(docSection.types, 'name'); - const typeNames = _.map(sortedTypesNames, t => t.name); - menuSubsectionsBySection[sectionName] = typeNames; - } else { - let eventNames: string[] = []; - if (!_.isUndefined(docSection.events)) { - const sortedEventNames = _.sortBy(docSection.events, 'name'); - eventNames = _.map(sortedEventNames, m => m.name); - } - const sortedMethodNames = _.sortBy(docSection.methods, 'name'); - const methodNames = _.map(sortedMethodNames, m => m.name); - menuSubsectionsBySection[sectionName] = [...methodNames, ...eventNames]; - } - }); - return menuSubsectionsBySection; - } - public getTypeDefinitionsByName(docAgnosticFormat: DocAgnosticFormat) { - if (_.isUndefined(this.sections.types)) { - return {}; - } - - const typeDocSection = docAgnosticFormat[this.sections.types]; - const typeDefinitionByName = _.keyBy(typeDocSection.types, 'name'); - return typeDefinitionByName; - } - public isVisibleConstructor(sectionName: string): boolean { - return _.includes(this._docsInfo.visibleConstructors, sectionName); - } - public convertToDocAgnosticFormat(docObj: DoxityDocObj | TypeDocNode): DocAgnosticFormat { - if (this.type === SupportedDocJson.Doxity) { - return doxityUtils.convertToDocAgnosticFormat(docObj as DoxityDocObj); - } else { - return typeDocUtils.convertToDocAgnosticFormat(docObj as TypeDocNode, this); - } - } -} diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx deleted file mode 100644 index 3229bbd93..000000000 --- a/packages/website/ts/pages/documentation/documentation.tsx +++ /dev/null @@ -1,336 +0,0 @@ -import { - colors, - constants as sharedConstants, - MarkdownSection, - MenuSubsectionsBySection, - NestedSidebarMenu, - SectionHeader, - Styles, - utils as sharedUtils, -} from '@0xproject/react-shared'; -import * as _ from 'lodash'; -import CircularProgress from 'material-ui/CircularProgress'; -import * as React from 'react'; -import { scroller } from 'react-scroll'; -import { Badge } from 'ts/components/ui/badge'; -import { Comment } from 'ts/pages/documentation/comment'; -import { DocsInfo } from 'ts/pages/documentation/docs_info'; -import { EventDefinition } from 'ts/pages/documentation/event_definition'; -import { MethodBlock } from 'ts/pages/documentation/method_block'; -import { SourceLink } from 'ts/pages/documentation/source_link'; -import { Type } from 'ts/pages/documentation/type'; -import { TypeDefinition } from 'ts/pages/documentation/type_definition'; -import { - AddressByContractName, - DocAgnosticFormat, - DoxityDocObj, - EtherscanLinkSuffixes, - Event, - Networks, - Property, - SolidityMethod, - SupportedDocJson, - TypeDefinitionByName, - TypescriptMethod, -} from 'ts/types'; -import { constants } from 'ts/utils/constants'; -import { utils } from 'ts/utils/utils'; - -const TOP_BAR_HEIGHT = 60; - -const networkNameToColor: { [network: string]: string } = { - [Networks.Kovan]: colors.purple, - [Networks.Ropsten]: colors.red, - [Networks.Mainnet]: colors.turquois, - [Networks.Rinkeby]: colors.darkYellow, -}; - -export interface DocumentationProps { - location: Location; - docsVersion: string; - availableDocVersions: string[]; - docsInfo: DocsInfo; - docAgnosticFormat?: DocAgnosticFormat; - menuSubsectionsBySection: MenuSubsectionsBySection; - sourceUrl: string; -} - -interface DocumentationState {} - -const styles: Styles = { - mainContainers: { - position: 'absolute', - top: 1, - left: 0, - bottom: 0, - right: 0, - overflowZ: 'hidden', - overflowY: 'scroll', - minHeight: `calc(100vh - ${TOP_BAR_HEIGHT}px)`, - WebkitOverflowScrolling: 'touch', - }, - menuContainer: { - borderColor: colors.grey300, - maxWidth: 330, - marginLeft: 20, - }, -}; - -export class Documentation extends React.Component { - public componentDidUpdate(prevProps: DocumentationProps, prevState: DocumentationState) { - if (!_.isEqual(prevProps.docAgnosticFormat, this.props.docAgnosticFormat)) { - const hash = this.props.location.hash.slice(1); - sharedUtils.scrollToHash(hash, sharedConstants.SCROLL_CONTAINER_ID); - } - } - public render() { - return ( -
- {_.isUndefined(this.props.docAgnosticFormat) ? ( - this._renderLoading() - ) : ( -
-
-
-
- -
-
-
-
-
- {this._renderDocumentation()} -
-
-
-
- )} -
- ); - } - private _renderLoading() { - return ( -
-
-
- -
-
- Loading documentation... -
-
-
- ); - } - private _renderDocumentation(): React.ReactNode { - const subMenus = _.values(this.props.docsInfo.getMenu()); - const orderedSectionNames = _.flatten(subMenus); - - const typeDefinitionByName = this.props.docsInfo.getTypeDefinitionsByName(this.props.docAgnosticFormat); - const renderedSections = _.map(orderedSectionNames, this._renderSection.bind(this, typeDefinitionByName)); - - return renderedSections; - } - private _renderSection(typeDefinitionByName: TypeDefinitionByName, sectionName: string): React.ReactNode { - const markdownFileIfExists = this.props.docsInfo.sectionNameToMarkdown[sectionName]; - if (!_.isUndefined(markdownFileIfExists)) { - return ( - - ); - } - - const docSection = this.props.docAgnosticFormat[sectionName]; - if (_.isUndefined(docSection)) { - return null; - } - - const sortedTypes = _.sortBy(docSection.types, 'name'); - const typeDefs = _.map(sortedTypes, customType => { - return ( - - ); - }); - - const sortedProperties = _.sortBy(docSection.properties, 'name'); - const propertyDefs = _.map(sortedProperties, this._renderProperty.bind(this, sectionName)); - - const sortedMethods = _.sortBy(docSection.methods, 'name'); - const methodDefs = _.map(sortedMethods, method => { - const isConstructor = false; - return this._renderMethodBlocks(method, sectionName, isConstructor, typeDefinitionByName); - }); - - const sortedEvents = _.sortBy(docSection.events, 'name'); - const eventDefs = _.map(sortedEvents, (event: Event, i: number) => { - return ( - - ); - }); - return ( -
-
-
- -
- {this._renderNetworkBadgesIfExists(sectionName)} -
- {docSection.comment && } - {docSection.constructors.length > 0 && - this.props.docsInfo.isVisibleConstructor(sectionName) && ( -
-

Constructor

- {this._renderConstructors(docSection.constructors, sectionName, typeDefinitionByName)} -
- )} - {docSection.properties.length > 0 && ( -
-

Properties

-
{propertyDefs}
-
- )} - {docSection.methods.length > 0 && ( -
-

Methods

-
{methodDefs}
-
- )} - {!_.isUndefined(docSection.events) && - docSection.events.length > 0 && ( -
-

Events

-
{eventDefs}
-
- )} - {!_.isUndefined(typeDefs) && - typeDefs.length > 0 && ( -
-
{typeDefs}
-
- )} -
- ); - } - private _renderNetworkBadgesIfExists(sectionName: string) { - if (this.props.docsInfo.type !== SupportedDocJson.Doxity) { - return null; - } - - const networkToAddressByContractName = this.props.docsInfo.contractsByVersionByNetworkId[ - this.props.docsVersion - ]; - const badges = _.map( - networkToAddressByContractName, - (addressByContractName: AddressByContractName, networkName: string) => { - const contractAddress = addressByContractName[sectionName]; - if (_.isUndefined(contractAddress)) { - return null; - } - const linkIfExists = utils.getEtherScanLinkIfExists( - contractAddress, - constants.NETWORK_ID_BY_NAME[networkName], - EtherscanLinkSuffixes.Address, - ); - return ( - - - - ); - }, - ); - return badges; - } - private _renderConstructors( - constructors: SolidityMethod[] | TypescriptMethod[], - sectionName: string, - typeDefinitionByName: TypeDefinitionByName, - ): React.ReactNode { - const constructorDefs = _.map(constructors, constructor => { - return this._renderMethodBlocks(constructor, sectionName, constructor.isConstructor, typeDefinitionByName); - }); - return
{constructorDefs}
; - } - private _renderProperty(sectionName: string, property: Property): React.ReactNode { - return ( -
- - {property.name}: - - - {property.source && ( - - )} - {property.comment && } -
- ); - } - private _renderMethodBlocks( - method: SolidityMethod | TypescriptMethod, - sectionName: string, - isConstructor: boolean, - typeDefinitionByName: TypeDefinitionByName, - ): React.ReactNode { - return ( - - ); - } -} diff --git a/packages/website/ts/pages/documentation/enum.tsx b/packages/website/ts/pages/documentation/enum.tsx deleted file mode 100644 index 7dfdee771..000000000 --- a/packages/website/ts/pages/documentation/enum.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import * as _ from 'lodash'; -import * as React from 'react'; -import { EnumValue } from 'ts/types'; - -interface EnumProps { - values: EnumValue[]; -} - -export function Enum(props: EnumProps) { - const values = _.map(props.values, (value, i) => { - const defaultValueIfAny = !_.isUndefined(value.defaultValue) ? ` = ${value.defaultValue}` : ''; - return `\n\t${value.name}${defaultValueIfAny},`; - }); - return ( - - {`{`} - {values} -
- {`}`} -
- ); -} diff --git a/packages/website/ts/pages/documentation/event_definition.tsx b/packages/website/ts/pages/documentation/event_definition.tsx deleted file mode 100644 index 06d8a3d79..000000000 --- a/packages/website/ts/pages/documentation/event_definition.tsx +++ /dev/null @@ -1,82 +0,0 @@ -import { AnchorTitle, colors, HeaderSizes } from '@0xproject/react-shared'; -import * as _ from 'lodash'; -import * as React from 'react'; -import { DocsInfo } from 'ts/pages/documentation/docs_info'; -import { Type } from 'ts/pages/documentation/type'; -import { Event, EventArg } from 'ts/types'; - -interface EventDefinitionProps { - event: Event; - sectionName: string; - docsInfo: DocsInfo; -} - -interface EventDefinitionState { - shouldShowAnchor: boolean; -} - -export class EventDefinition extends React.Component { - constructor(props: EventDefinitionProps) { - super(props); - this.state = { - shouldShowAnchor: false, - }; - } - public render() { - const event = this.props.event; - const id = `${this.props.sectionName}-${event.name}`; - return ( -
- -
-
-                        {this._renderEventCode()}
-                    
-
-
- ); - } - private _renderEventCode() { - const indexed = indexed; - const eventArgs = _.map(this.props.event.eventArgs, (eventArg: EventArg) => { - const type = ( - - ); - return ( - - {eventArg.name} - {eventArg.isIndexed ? indexed : ''}: {type}, - - ); - }); - const argList = _.reduce(eventArgs, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, '\n\t', curr]; - }); - return ( - - {`{`} -
- {'\t'} - {argList} -
- {`}`} -
- ); - } - private _setAnchorVisibility(shouldShowAnchor: boolean) { - this.setState({ - shouldShowAnchor, - }); - } -} diff --git a/packages/website/ts/pages/documentation/interface.tsx b/packages/website/ts/pages/documentation/interface.tsx deleted file mode 100644 index 16a772125..000000000 --- a/packages/website/ts/pages/documentation/interface.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import * as _ from 'lodash'; -import * as React from 'react'; -import { DocsInfo } from 'ts/pages/documentation/docs_info'; -import { MethodSignature } from 'ts/pages/documentation/method_signature'; -import { Type } from 'ts/pages/documentation/type'; -import { CustomType, TypeDocTypes } from 'ts/types'; - -interface InterfaceProps { - type: CustomType; - sectionName: string; - docsInfo: DocsInfo; -} - -export function Interface(props: InterfaceProps) { - const type = props.type; - const properties = _.map(type.children, property => { - return ( - - {property.name}:{' '} - {property.type.typeDocType !== TypeDocTypes.Reflection ? ( - - ) : ( - - )}, - - ); - }); - const hasIndexSignature = !_.isUndefined(type.indexSignature); - if (hasIndexSignature) { - const is = type.indexSignature; - const param = ( - - {is.keyName}: - - ); - properties.push( - - [{param}]: {is.valueName}, - , - ); - } - const propertyList = _.reduce(properties, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, '\n\t', curr]; - }); - return ( - - {`{`} -
- {'\t'} - {propertyList} -
- {`}`} -
- ); -} diff --git a/packages/website/ts/pages/documentation/method_block.tsx b/packages/website/ts/pages/documentation/method_block.tsx deleted file mode 100644 index a52ab55c3..000000000 --- a/packages/website/ts/pages/documentation/method_block.tsx +++ /dev/null @@ -1,147 +0,0 @@ -import { AnchorTitle, colors, HeaderSizes, Styles } from '@0xproject/react-shared'; -import * as _ from 'lodash'; -import * as React from 'react'; -import { Comment } from 'ts/pages/documentation/comment'; -import { DocsInfo } from 'ts/pages/documentation/docs_info'; -import { MethodSignature } from 'ts/pages/documentation/method_signature'; -import { SourceLink } from 'ts/pages/documentation/source_link'; -import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod } from 'ts/types'; -import { typeDocUtils } from 'ts/utils/typedoc_utils'; - -interface MethodBlockProps { - method: SolidityMethod | TypescriptMethod; - sectionName: string; - libraryVersion: string; - typeDefinitionByName: TypeDefinitionByName; - docsInfo: DocsInfo; - sourceUrl: string; -} - -interface MethodBlockState { - shouldShowAnchor: boolean; -} - -const styles: Styles = { - chip: { - fontSize: 13, - backgroundColor: colors.lightBlueA700, - color: colors.white, - height: 11, - borderRadius: 14, - lineHeight: 0.9, - }, -}; - -export class MethodBlock extends React.Component { - constructor(props: MethodBlockProps) { - super(props); - this.state = { - shouldShowAnchor: false, - }; - } - public render() { - const method = this.props.method; - if (typeDocUtils.isPrivateOrProtectedProperty(method.name)) { - return null; - } - - return ( -
- {!method.isConstructor && ( -
- {(method as TypescriptMethod).isStatic && this._renderChip('Static')} - {(method as SolidityMethod).isConstant && this._renderChip('Constant')} - {(method as SolidityMethod).isPayable && this._renderChip('Payable')} -
- -
-
- )} - - - - {(method as TypescriptMethod).source && ( - - )} - {method.comment && } - {method.parameters && - !_.isEmpty(method.parameters) && ( -
-

- ARGUMENTS -

- {this._renderParameterDescriptions(method.parameters)} -
- )} - {method.returnComment && ( -
-

- RETURNS -

- -
- )} -
- ); - } - private _renderChip(text: string) { - return ( -
- {text} -
- ); - } - private _renderParameterDescriptions(parameters: Parameter[]) { - const descriptions = _.map(parameters, parameter => { - const isOptional = parameter.isOptional; - return ( -
-
-
- {parameter.name} -
-
- {isOptional && 'optional'} -
-
-
- {parameter.comment && } -
-
- ); - }); - return descriptions; - } - private _setAnchorVisibility(shouldShowAnchor: boolean) { - this.setState({ - shouldShowAnchor, - }); - } -} diff --git a/packages/website/ts/pages/documentation/method_signature.tsx b/packages/website/ts/pages/documentation/method_signature.tsx deleted file mode 100644 index 22294e428..000000000 --- a/packages/website/ts/pages/documentation/method_signature.tsx +++ /dev/null @@ -1,126 +0,0 @@ -import * as _ from 'lodash'; -import * as React from 'react'; -import * as ReactDOM from 'react-dom'; -import { DocsInfo } from 'ts/pages/documentation/docs_info'; -import { Type } from 'ts/pages/documentation/type'; -import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod } from 'ts/types'; -import { constants } from 'ts/utils/constants'; - -interface MethodSignatureProps { - method: TypescriptMethod | SolidityMethod; - sectionName: string; - shouldHideMethodName?: boolean; - shouldUseArrowSyntax?: boolean; - typeDefinitionByName?: TypeDefinitionByName; - docsInfo: DocsInfo; -} - -const defaultProps = { - shouldHideMethodName: false, - shouldUseArrowSyntax: false, -}; - -export const MethodSignature: React.SFC = (props: MethodSignatureProps) => { - const sectionName = constants.TYPES_SECTION_NAME; - const parameters = renderParameters(props.method, props.docsInfo, sectionName, 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 ? ( - - {param} - - ) : ( - param - ); - paramStringArray.push(finalParam); - const comma = hasMoreThenTwoParams ? ( - - ,
-
- ) : ( - ', ' - ); - paramStringArray.push(comma); - }); - if (!hasMoreThenTwoParams) { - paramStringArray.pop(); - } - const methodName = props.shouldHideMethodName ? '' : props.method.name; - const typeParameterIfExists = _.isUndefined((props.method as TypescriptMethod).typeParameter) - ? undefined - : renderTypeParameter(props.method, props.docsInfo, sectionName, props.typeDefinitionByName); - return ( - - {props.method.callPath} - {methodName} - {typeParameterIfExists}({hasMoreThenTwoParams &&
} - {paramStringArray}) - {props.method.returnType && ( - - {props.shouldUseArrowSyntax ? ' => ' : ': '}{' '} - - - )} -
- ); -}; - -MethodSignature.defaultProps = defaultProps; - -function renderParameters( - method: TypescriptMethod | SolidityMethod, - docsInfo: DocsInfo, - sectionName: string, - typeDefinitionByName?: TypeDefinitionByName, -) { - const parameters = method.parameters; - const params = _.map(parameters, (p: Parameter) => { - const isOptional = p.isOptional; - const type = ( - - ); - return ( - - {p.name} - {isOptional && '?'}: {type} - - ); - }); - return params; -} - -function renderTypeParameter( - method: TypescriptMethod, - docsInfo: DocsInfo, - sectionName: string, - typeDefinitionByName?: TypeDefinitionByName, -) { - const typeParameter = method.typeParameter; - const typeParam = ( - - {`<${typeParameter.name} extends `} - - {`>`} - - ); - return typeParam; -} diff --git a/packages/website/ts/pages/documentation/source_link.tsx b/packages/website/ts/pages/documentation/source_link.tsx deleted file mode 100644 index d39ad14c4..000000000 --- a/packages/website/ts/pages/documentation/source_link.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { colors } from '@0xproject/react-shared'; -import * as _ from 'lodash'; -import * as React from 'react'; -import { Source } from 'ts/types'; - -interface SourceLinkProps { - source: Source; - sourceUrl: string; - version: string; -} - -export function SourceLink(props: SourceLinkProps) { - const src = props.source; - const sourceCodeUrl = `${props.sourceUrl}/${src.fileName}#L${src.line}`; - return ( - - ); -} diff --git a/packages/website/ts/pages/documentation/type.tsx b/packages/website/ts/pages/documentation/type.tsx deleted file mode 100644 index 2c90a0567..000000000 --- a/packages/website/ts/pages/documentation/type.tsx +++ /dev/null @@ -1,229 +0,0 @@ -import { colors, constants as sharedConstants, utils as sharedUtils } from '@0xproject/react-shared'; -import * as _ from 'lodash'; -import * as React from 'react'; -import { Link as ScrollLink } from 'react-scroll'; -import * as ReactTooltip from 'react-tooltip'; -import { DocsInfo } from 'ts/pages/documentation/docs_info'; -import { TypeDefinition } from 'ts/pages/documentation/type_definition'; -import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from 'ts/types'; -import { constants } from 'ts/utils/constants'; -import { utils } from 'ts/utils/utils'; - -// Some types reference other libraries. For these types, we want to link the user to the relevant documentation. -const typeToUrl: { [typeName: string]: string } = { - Web3: constants.URL_WEB3_DOCS, - Provider: constants.URL_WEB3_PROVIDER_DOCS, - BigNumber: constants.URL_BIGNUMBERJS_GITHUB, - DecodedLogEntryEvent: constants.URL_WEB3_DECODED_LOG_ENTRY_EVENT, - LogEntryEvent: constants.URL_WEB3_LOG_ENTRY_EVENT, -}; - -const typePrefix: { [typeName: string]: string } = { - Provider: 'Web3', - DecodedLogEntryEvent: 'Web3', - LogEntryEvent: 'Web3', -}; - -const typeToSection: { [typeName: string]: string } = { - ExchangeWrapper: 'exchange', - TokenWrapper: 'token', - TokenRegistryWrapper: 'tokenRegistry', - EtherTokenWrapper: 'etherToken', - ProxyWrapper: 'proxy', - TokenTransferProxyWrapper: 'proxy', - OrderStateWatcher: 'orderWatcher', -}; - -interface TypeProps { - type: TypeDef; - docsInfo: DocsInfo; - sectionName: string; - typeDefinitionByName?: TypeDefinitionByName; -} - -// The return type needs to be `any` here so that we can recursively define components within -// components (e.g when rendering the union type). -export function Type(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 ( - - [] - - ); - } else { - const subType = ( - - ); - return subType; - } - }); - break; - - case TypeDocTypes.StringLiteral: - typeName = `'${type.value}'`; - typeNameColor = colors.green; - break; - - case TypeDocTypes.Array: - typeName = type.elementType.name; - break; - - case TypeDocTypes.Union: - const unionTypes = _.map(type.types, t => { - return ( - - ); - }); - typeName = _.reduce(unionTypes, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, '|', curr]; - }); - break; - - case TypeDocTypes.TypeParameter: - typeName = type.name; - break; - - case TypeDocTypes.Intersection: - const intersectionsTypes = _.map(type.types, t => { - return ( - - ); - }); - typeName = _.reduce(intersectionsTypes, (prev: React.ReactNode, curr: React.ReactNode) => { - return [prev, '&', curr]; - }); - break; - - default: - throw utils.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 typeNameUrlIfExists = typeToUrl[typeName as string]; - const typePrefixIfExists = typePrefix[typeName as string]; - const sectionNameIfExists = typeToSection[typeName as string]; - if (!_.isUndefined(typeNameUrlIfExists)) { - typeName = ( - - {!_.isUndefined(typePrefixIfExists) ? `${typePrefixIfExists}.` : ''} - {typeName} - - ); - } else if ( - (isReference || isArray) && - (props.docsInfo.isPublicType(typeName as string) || !_.isUndefined(sectionNameIfExists)) - ) { - const id = Math.random().toString(); - const typeDefinitionAnchorId = _.isUndefined(sectionNameIfExists) - ? `${props.sectionName}-${typeName}` - : sectionNameIfExists; - let typeDefinition; - if (props.typeDefinitionByName) { - typeDefinition = props.typeDefinitionByName[typeName as string]; - } - typeName = ( - - {_.isUndefined(typeDefinition) || utils.isUserOnMobile() ? ( - - {typeName} - - ) : ( - - {typeName} - - - - - )} - - ); - } - return ( - - {typeName} - {isArray && '[]'} - {!_.isEmpty(typeArgs) && ( - - {'<'} - {commaSeparatedTypeArgs} - {'>'} - - )} - - ); -} diff --git a/packages/website/ts/pages/documentation/type_definition.tsx b/packages/website/ts/pages/documentation/type_definition.tsx deleted file mode 100644 index 60f307c68..000000000 --- a/packages/website/ts/pages/documentation/type_definition.tsx +++ /dev/null @@ -1,126 +0,0 @@ -import { AnchorTitle, colors, HeaderSizes } from '@0xproject/react-shared'; -import * as _ from 'lodash'; -import * as React from 'react'; -import { Comment } from 'ts/pages/documentation/comment'; -import { CustomEnum } from 'ts/pages/documentation/custom_enum'; -import { DocsInfo } from 'ts/pages/documentation/docs_info'; -import { Enum } from 'ts/pages/documentation/enum'; -import { Interface } from 'ts/pages/documentation/interface'; -import { MethodSignature } from 'ts/pages/documentation/method_signature'; -import { Type } from 'ts/pages/documentation/type'; -import { CustomType, CustomTypeChild, KindString, TypeDocTypes } from 'ts/types'; -import { utils } from 'ts/utils/utils'; - -interface TypeDefinitionProps { - sectionName: string; - customType: CustomType; - shouldAddId?: boolean; - docsInfo: DocsInfo; -} - -interface TypeDefinitionState { - shouldShowAnchor: boolean; -} - -export class TypeDefinition extends React.Component { - public static defaultProps: Partial = { - shouldAddId: true, - }; - constructor(props: TypeDefinitionProps) { - super(props); - this.state = { - shouldShowAnchor: false, - }; - } - public render() { - const customType = this.props.customType; - if (!this.props.docsInfo.isPublicType(customType.name)) { - return null; // no-op - } - - let typePrefix: string; - let codeSnippet: React.ReactNode; - switch (customType.kindString) { - case KindString.Interface: - typePrefix = 'Interface'; - codeSnippet = ( - - ); - break; - - case KindString.Variable: - typePrefix = 'Enum'; - codeSnippet = ; - break; - - case KindString.Enumeration: - typePrefix = 'Enum'; - const enumValues = _.map(customType.children, (c: CustomTypeChild) => { - return { - name: c.name, - defaultValue: c.defaultValue, - }; - }); - codeSnippet = ; - break; - - case KindString.TypeAlias: - typePrefix = 'Type Alias'; - codeSnippet = ( - - type {customType.name} ={' '} - {customType.type.typeDocType !== TypeDocTypes.Reflection ? ( - - ) : ( - - )} - - ); - break; - - default: - throw utils.spawnSwitchErr('type.kindString', customType.kindString); - } - - const typeDefinitionAnchorId = `${this.props.sectionName}-${customType.name}`; - return ( -
- -
-
-                        {codeSnippet}
-                    
-
-
- {customType.comment && } -
-
- ); - } - private _setAnchorVisibility(shouldShowAnchor: boolean) { - this.setState({ - shouldShowAnchor, - }); - } -} -- cgit v1.2.3