aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-docs
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-04-02 20:23:07 +0800
committerFabio Berger <me@fabioberger.com>2018-04-02 20:23:07 +0800
commit8162394797342cef268cc8072fc860326974e269 (patch)
tree2826b02715a8cb794571be6c7dccdb395329361c /packages/react-docs
parentfd001186dd281a11920246c6b9afcefe1d55bc23 (diff)
parent695b697cdf6c73bb4b5f920869ce128f9a9e7523 (diff)
downloaddexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.gz
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.bz2
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.lz
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.xz
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.tar.zst
dexon-0x-contracts-8162394797342cef268cc8072fc860326974e269.zip
Merge branch 'development'
* development: (175 commits) small README fixes Update docs list in README Add manual postpublish command to all public packages and update CHANGELOG.json Fix postpublish util to ignore namespace Fix release notes bug Should print out `lerna publish` stdout so we can see if anything went wrong Publish Updated CHANGELOGS Generate CHANGELOG.json files Fix hasty find/replace Default to 4sp Update moment, no longer need separate moment types Move prettify command to utils and also call it on CHANGELOG.md Add prettier run on generated CHANGELOG.json and fix scripts Remove semi-colons from monorepo-scripts package.json Get rid of ; in top-level package.json Fix TSLint error Make dry-run configurable from top-level package.json Improve naming Run prettier, update deployer CHANGELOG ...
Diffstat (limited to 'packages/react-docs')
-rw-r--r--packages/react-docs/.npmignore1
-rw-r--r--packages/react-docs/CHANGELOG.json53
-rw-r--r--packages/react-docs/CHANGELOG.md14
-rw-r--r--packages/react-docs/README.md8
-rw-r--r--packages/react-docs/package.json21
-rw-r--r--packages/react-docs/src/components/documentation.tsx32
-rw-r--r--packages/react-docs/src/components/interface.tsx10
-rw-r--r--packages/react-docs/src/components/signature.tsx (renamed from packages/react-docs/src/components/method_signature.tsx)35
-rw-r--r--packages/react-docs/src/components/signature_block.tsx (renamed from packages/react-docs/src/components/method_block.tsx)24
-rw-r--r--packages/react-docs/src/components/type.tsx18
-rw-r--r--packages/react-docs/src/components/type_definition.tsx10
-rw-r--r--packages/react-docs/src/docs_info.ts3
-rw-r--r--packages/react-docs/src/index.ts4
-rw-r--r--packages/react-docs/src/types.ts16
-rw-r--r--packages/react-docs/src/utils/doxity_utils.ts1
-rw-r--r--packages/react-docs/src/utils/typedoc_utils.ts71
-rw-r--r--packages/react-docs/tsconfig.json2
17 files changed, 258 insertions, 65 deletions
diff --git a/packages/react-docs/.npmignore b/packages/react-docs/.npmignore
index 87bc30436..d645458f6 100644
--- a/packages/react-docs/.npmignore
+++ b/packages/react-docs/.npmignore
@@ -3,3 +3,4 @@ yarn-error.log
/src/
/scripts/
tsconfig.json
+/lib/monorepo_scripts/
diff --git a/packages/react-docs/CHANGELOG.json b/packages/react-docs/CHANGELOG.json
new file mode 100644
index 000000000..5131bdbe4
--- /dev/null
+++ b/packages/react-docs/CHANGELOG.json
@@ -0,0 +1,53 @@
+[
+ {
+ "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,
+ "isPublished": true
+ },
+ {
+ "version": "0.0.3",
+ "changes": [
+ {
+ "note":
+ "Move TS typings from devDependencies to dependencies since they are needed by the package user."
+ }
+ ],
+ "timestamp": 1521298800,
+ "isPublished": true
+ },
+ {
+ "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,
+ "isPublished": true
+ }
+]
diff --git a/packages/react-docs/CHANGELOG.md b/packages/react-docs/CHANGELOG.md
index 7c46013b1..c9d2680ea 100644
--- a/packages/react-docs/CHANGELOG.md
+++ b/packages/react-docs/CHANGELOG.md
@@ -1,4 +1,16 @@
-# CHANGELOG
+<!--
+This file is auto-generated using the monorepo-scripts package. Don't edit directly.
+Edit the package's CHANGELOG.json file only.
+-->
+
+CHANGELOG
+
+## 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 18, 2018_
diff --git a/packages/react-docs/README.md b/packages/react-docs/README.md
index cad05ca67..9be370f10 100644
--- a/packages/react-docs/README.md
+++ b/packages/react-docs/README.md
@@ -33,6 +33,14 @@ This package exposes both a single `Documentation` react component that will ren
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/@0xproject/typescript-typings/types", "node_modules/@types"],
+}
+```
+
## Future improvements
Feel free to contribute to these improvements!
diff --git a/packages/react-docs/package.json b/packages/react-docs/package.json
index 06480a948..15e6a10d5 100644
--- a/packages/react-docs/package.json
+++ b/packages/react-docs/package.json
@@ -1,6 +1,6 @@
{
"name": "@0xproject/react-docs",
- "version": "0.0.4",
+ "version": "0.0.5",
"description": "React documentation component for rendering TypeDoc & Doxity generated JSON",
"main": "lib/index.js",
"types": "lib/index.d.ts",
@@ -8,7 +8,8 @@
"lint": "tslint --project . 'src/**/*.ts' 'src/**/*.tsx'",
"build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts",
"build:watch": "tsc -w",
- "clean": "shx rm -rf lib scripts"
+ "clean": "shx rm -rf lib scripts",
+ "manual:postpublish": "yarn build; node ./scripts/postpublish.js"
},
"author": "Fabio Berger",
"license": "Apache-2.0",
@@ -21,22 +22,22 @@
"url": "https://github.com/0xProject/0x-monorepo.git"
},
"devDependencies": {
- "@0xproject/dev-utils": "^0.3.2",
- "@0xproject/monorepo-scripts": "^0.1.14",
- "@0xproject/tslint-config": "^0.4.12",
+ "@0xproject/dev-utils": "^0.3.3",
+ "@0xproject/monorepo-scripts": "^0.1.15",
+ "@0xproject/tslint-config": "^0.4.13",
"copyfiles": "^1.2.0",
"shx": "^0.2.2",
"tslint": "^5.9.1",
"typescript": "2.7.1"
},
"dependencies": {
- "@0xproject/react-shared": "^0.0.4",
- "@0xproject/utils": "^0.4.3",
- "@types/lodash": "^4.14.86",
+ "@0xproject/react-shared": "^0.1.0",
+ "@0xproject/utils": "^0.4.4",
+ "@types/lodash": "4.14.104",
"@types/material-ui": "0.18.0",
"@types/node": "^8.0.53",
- "@types/react": "^15.0.15",
- "@types/react-dom": "^0.14.23",
+ "@types/react": "^16.0.34",
+ "@types/react-dom": "^16.0.3",
"@types/react-scroll": "0.0.31",
"@types/react-tap-event-plugin": "0.0.30",
"basscss": "^8.0.3",
diff --git a/packages/react-docs/src/components/documentation.tsx b/packages/react-docs/src/components/documentation.tsx
index b46358159..14fe175cf 100644
--- a/packages/react-docs/src/components/documentation.tsx
+++ b/packages/react-docs/src/components/documentation.tsx
@@ -25,6 +25,7 @@ import {
SolidityMethod,
SupportedDocJson,
TypeDefinitionByName,
+ TypescriptFunction,
TypescriptMethod,
} from '../types';
import { constants } from '../utils/constants';
@@ -33,7 +34,7 @@ import { utils } from '../utils/utils';
import { Badge } from './badge';
import { Comment } from './comment';
import { EventDefinition } from './event_definition';
-import { MethodBlock } from './method_block';
+import { SignatureBlock } from './signature_block';
import { SourceLink } from './source_link';
import { Type } from './type';
import { TypeDefinition } from './type_definition';
@@ -216,8 +217,12 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
const sortedMethods = _.sortBy(docSection.methods, 'name');
const methodDefs = _.map(sortedMethods, method => {
- const isConstructor = false;
- return this._renderMethodBlocks(method, sectionName, isConstructor, typeDefinitionByName);
+ 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');
@@ -243,25 +248,31 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
{this._renderNetworkBadgesIfExists(sectionName)}
</div>
{docSection.comment && <Comment comment={docSection.comment} />}
- {docSection.constructors.length > 0 &&
+ {!_.isEmpty(docSection.constructors) &&
this.props.docsInfo.isVisibleConstructor(sectionName) && (
<div>
<h2 style={headerStyle}>Constructor</h2>
{this._renderConstructors(docSection.constructors, sectionName, typeDefinitionByName)}
</div>
)}
- {docSection.properties.length > 0 && (
+ {!_.isEmpty(docSection.properties) && (
<div>
<h2 style={headerStyle}>Properties</h2>
<div>{propertyDefs}</div>
</div>
)}
- {docSection.methods.length > 0 && (
+ {!_.isEmpty(docSection.methods) && (
<div>
<h2 style={headerStyle}>Methods</h2>
<div>{methodDefs}</div>
</div>
)}
+ {!_.isEmpty(docSection.functions) && (
+ <div>
+ <h2 style={headerStyle}>Functions</h2>
+ <div>{functionDefs}</div>
+ </div>
+ )}
{!_.isUndefined(docSection.events) &&
docSection.events.length > 0 && (
<div>
@@ -318,7 +329,7 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
typeDefinitionByName: TypeDefinitionByName,
): React.ReactNode {
const constructorDefs = _.map(constructors, constructor => {
- return this._renderMethodBlocks(constructor, sectionName, constructor.isConstructor, typeDefinitionByName);
+ return this._renderSignatureBlocks(constructor, sectionName, typeDefinitionByName);
});
return <div>{constructorDefs}</div>;
}
@@ -340,14 +351,13 @@ export class Documentation extends React.Component<DocumentationProps, Documenta
</div>
);
}
- private _renderMethodBlocks(
- method: SolidityMethod | TypescriptMethod,
+ private _renderSignatureBlocks(
+ method: SolidityMethod | TypescriptFunction | TypescriptMethod,
sectionName: string,
- isConstructor: boolean,
typeDefinitionByName: TypeDefinitionByName,
): React.ReactNode {
return (
- <MethodBlock
+ <SignatureBlock
key={`method-${method.name}-${sectionName}`}
sectionName={sectionName}
method={method}
diff --git a/packages/react-docs/src/components/interface.tsx b/packages/react-docs/src/components/interface.tsx
index 01f4942ef..541e164e3 100644
--- a/packages/react-docs/src/components/interface.tsx
+++ b/packages/react-docs/src/components/interface.tsx
@@ -4,7 +4,7 @@ import * as React from 'react';
import { DocsInfo } from '../docs_info';
import { CustomType, TypeDocTypes } from '../types';
-import { MethodSignature } from './method_signature';
+import { Signature } from './signature';
import { Type } from './type';
export interface InterfaceProps {
@@ -22,8 +22,12 @@ export function Interface(props: InterfaceProps) {
{property.type.typeDocType !== TypeDocTypes.Reflection ? (
<Type type={property.type} sectionName={props.sectionName} docsInfo={props.docsInfo} />
) : (
- <MethodSignature
- method={property.type.method}
+ <Signature
+ name={property.type.method.name}
+ returnType={property.type.method.returnType}
+ parameters={property.type.method.parameters}
+ typeParameter={property.type.method.typeParameter}
+ callPath={property.type.method.callPath}
sectionName={props.sectionName}
shouldHideMethodName={true}
shouldUseArrowSyntax={true}
diff --git a/packages/react-docs/src/components/method_signature.tsx b/packages/react-docs/src/components/signature.tsx
index 1400182ea..83fb1e246 100644
--- a/packages/react-docs/src/components/method_signature.tsx
+++ b/packages/react-docs/src/components/signature.tsx
@@ -3,28 +3,33 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { DocsInfo } from '../docs_info';
-import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod } from '../types';
+import { Parameter, Type as TypeDef, TypeDefinitionByName, TypeParameter } from '../types';
import { constants } from '../utils/constants';
import { Type } from './type';
-export interface MethodSignatureProps {
- method: TypescriptMethod | SolidityMethod;
+export interface SignatureProps {
+ name: string;
+ returnType: TypeDef;
+ parameters: Parameter[];
sectionName: string;
shouldHideMethodName?: boolean;
shouldUseArrowSyntax?: boolean;
typeDefinitionByName?: TypeDefinitionByName;
+ typeParameter?: TypeParameter;
+ callPath?: string;
docsInfo: DocsInfo;
}
const defaultProps = {
shouldHideMethodName: false,
shouldUseArrowSyntax: false,
+ callPath: '',
};
-export const MethodSignature: React.SFC<MethodSignatureProps> = (props: MethodSignatureProps) => {
+export const Signature: React.SFC<SignatureProps> = (props: SignatureProps) => {
const sectionName = constants.TYPES_SECTION_NAME;
- const parameters = renderParameters(props.method, props.docsInfo, sectionName, props.typeDefinitionByName);
+ const parameters = renderParameters(props.parameters, 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
@@ -51,21 +56,21 @@ export const MethodSignature: React.SFC<MethodSignatureProps> = (props: MethodSi
if (!hasMoreThenTwoParams) {
paramStringArray.pop();
}
- const methodName = props.shouldHideMethodName ? '' : props.method.name;
- const typeParameterIfExists = _.isUndefined((props.method as TypescriptMethod).typeParameter)
+ const methodName = props.shouldHideMethodName ? '' : props.name;
+ const typeParameterIfExists = _.isUndefined(props.typeParameter)
? undefined
- : renderTypeParameter(props.method, props.docsInfo, sectionName, props.typeDefinitionByName);
+ : renderTypeParameter(props.typeParameter, props.docsInfo, sectionName, props.typeDefinitionByName);
return (
<span style={{ fontSize: 15 }}>
- {props.method.callPath}
+ {props.callPath}
{methodName}
{typeParameterIfExists}({hasMoreThenTwoParams && <br />}
{paramStringArray})
- {props.method.returnType && (
+ {props.returnType && (
<span>
{props.shouldUseArrowSyntax ? ' => ' : ': '}{' '}
<Type
- type={props.method.returnType}
+ type={props.returnType}
sectionName={sectionName}
typeDefinitionByName={props.typeDefinitionByName}
docsInfo={props.docsInfo}
@@ -76,15 +81,14 @@ export const MethodSignature: React.SFC<MethodSignatureProps> = (props: MethodSi
);
};
-MethodSignature.defaultProps = defaultProps;
+Signature.defaultProps = defaultProps;
function renderParameters(
- method: TypescriptMethod | SolidityMethod,
+ parameters: Parameter[],
docsInfo: DocsInfo,
sectionName: string,
typeDefinitionByName?: TypeDefinitionByName,
) {
- const parameters = method.parameters;
const params = _.map(parameters, (p: Parameter) => {
const isOptional = p.isOptional;
const type = (
@@ -106,12 +110,11 @@ function renderParameters(
}
function renderTypeParameter(
- method: TypescriptMethod,
+ typeParameter: TypeParameter,
docsInfo: DocsInfo,
sectionName: string,
typeDefinitionByName?: TypeDefinitionByName,
) {
- const typeParameter = method.typeParameter;
const typeParam = (
<span>
{`<${typeParameter.name} extends `}
diff --git a/packages/react-docs/src/components/method_block.tsx b/packages/react-docs/src/components/signature_block.tsx
index 44a1db8af..6475d3995 100644
--- a/packages/react-docs/src/components/method_block.tsx
+++ b/packages/react-docs/src/components/signature_block.tsx
@@ -3,16 +3,16 @@ import * as _ from 'lodash';
import * as React from 'react';
import { DocsInfo } from '../docs_info';
-import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod } from '../types';
+import { Parameter, SolidityMethod, TypeDefinitionByName, TypescriptFunction, TypescriptMethod } from '../types';
import { constants } from '../utils/constants';
import { typeDocUtils } from '../utils/typedoc_utils';
import { Comment } from './comment';
-import { MethodSignature } from './method_signature';
+import { Signature } from './signature';
import { SourceLink } from './source_link';
-export interface MethodBlockProps {
- method: SolidityMethod | TypescriptMethod;
+export interface SignatureBlockProps {
+ method: SolidityMethod | TypescriptFunction | TypescriptMethod;
sectionName: string;
libraryVersion: string;
typeDefinitionByName: TypeDefinitionByName;
@@ -20,7 +20,7 @@ export interface MethodBlockProps {
sourceUrl: string;
}
-export interface MethodBlockState {
+export interface SignatureBlockState {
shouldShowAnchor: boolean;
}
@@ -35,8 +35,8 @@ const styles: Styles = {
},
};
-export class MethodBlock extends React.Component<MethodBlockProps, MethodBlockState> {
- constructor(props: MethodBlockProps) {
+export class SignatureBlock extends React.Component<SignatureBlockProps, SignatureBlockState> {
+ constructor(props: SignatureBlockProps) {
super(props);
this.state = {
shouldShowAnchor: false,
@@ -56,7 +56,7 @@ export class MethodBlock extends React.Component<MethodBlockProps, MethodBlockSt
onMouseOver={this._setAnchorVisibility.bind(this, true)}
onMouseOut={this._setAnchorVisibility.bind(this, false)}
>
- {!method.isConstructor && (
+ {!(method as TypescriptMethod).isConstructor && (
<div className="flex pb2 pt2">
{(method as TypescriptMethod).isStatic && this._renderChip('Static')}
{(method as SolidityMethod).isConstant && this._renderChip('Constant')}
@@ -72,8 +72,12 @@ export class MethodBlock extends React.Component<MethodBlockProps, MethodBlockSt
</div>
)}
<code className={`hljs ${constants.TYPE_TO_SYNTAX[this.props.docsInfo.type]}`}>
- <MethodSignature
- method={method}
+ <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}
diff --git a/packages/react-docs/src/components/type.tsx b/packages/react-docs/src/components/type.tsx
index 56425a5df..fd4562ce3 100644
--- a/packages/react-docs/src/components/type.tsx
+++ b/packages/react-docs/src/components/type.tsx
@@ -9,6 +9,7 @@ import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from '../types';
import { constants } from '../utils/constants';
import { utils } from '../utils/utils';
+import { Signature } from './signature';
import { TypeDefinition } from './type_definition';
const typeToSection: { [typeName: string]: string } = {
@@ -101,6 +102,23 @@ export function Type(props: TypeProps): any {
});
break;
+ case TypeDocTypes.Reflection:
+ typeName = (
+ <Signature
+ name={type.method.name}
+ returnType={type.method.returnType}
+ parameters={type.method.parameters}
+ typeParameter={type.method.typeParameter}
+ callPath={type.method.callPath}
+ sectionName={props.sectionName}
+ shouldHideMethodName={true}
+ shouldUseArrowSyntax={true}
+ docsInfo={props.docsInfo}
+ typeDefinitionByName={props.typeDefinitionByName}
+ />
+ );
+ break;
+
case TypeDocTypes.TypeParameter:
typeName = type.name;
break;
diff --git a/packages/react-docs/src/components/type_definition.tsx b/packages/react-docs/src/components/type_definition.tsx
index 68ef4c465..7a1c86da5 100644
--- a/packages/react-docs/src/components/type_definition.tsx
+++ b/packages/react-docs/src/components/type_definition.tsx
@@ -11,7 +11,7 @@ import { Comment } from './comment';
import { CustomEnum } from './custom_enum';
import { Enum } from './enum';
import { Interface } from './interface';
-import { MethodSignature } from './method_signature';
+import { Signature } from './signature';
import { Type } from './type';
export interface TypeDefinitionProps {
@@ -79,8 +79,12 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
docsInfo={this.props.docsInfo}
/>
) : (
- <MethodSignature
- method={customType.type.method}
+ <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}
diff --git a/packages/react-docs/src/docs_info.ts b/packages/react-docs/src/docs_info.ts
index 68bddef06..0030568a1 100644
--- a/packages/react-docs/src/docs_info.ts
+++ b/packages/react-docs/src/docs_info.ts
@@ -97,6 +97,9 @@ export class DocsInfo {
const sortedMethodNames = _.sortBy(docSection.methods, 'name');
const methodNames = _.map(sortedMethodNames, m => m.name);
menuSubsectionsBySection[sectionName] = [...methodNames, ...eventNames];
+ const sortedFunctionNames = _.sortBy(docSection.functions, 'name');
+ const functionNames = _.map(sortedFunctionNames, m => m.name);
+ menuSubsectionsBySection[sectionName] = [...eventNames, ...functionNames, ...methodNames];
}
});
return menuSubsectionsBySection;
diff --git a/packages/react-docs/src/index.ts b/packages/react-docs/src/index.ts
index a62c91376..30f5011b7 100644
--- a/packages/react-docs/src/index.ts
+++ b/packages/react-docs/src/index.ts
@@ -7,8 +7,8 @@ export { Documentation } from './components/documentation';
export { Enum } from './components/enum';
export { EventDefinition } from './components/event_definition';
export { Interface } from './components/interface';
-export { MethodBlock } from './components/method_block';
-export { MethodSignature } from './components/method_signature';
+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';
diff --git a/packages/react-docs/src/types.ts b/packages/react-docs/src/types.ts
index d192af313..2a300c164 100644
--- a/packages/react-docs/src/types.ts
+++ b/packages/react-docs/src/types.ts
@@ -42,6 +42,7 @@ export interface TypeDocFlags {
isStatic?: boolean;
isOptional?: boolean;
isPublic?: boolean;
+ isExported?: boolean;
}
export interface TypeDocGroup {
@@ -96,6 +97,7 @@ export enum KindString {
Variable = 'Variable',
Function = 'Function',
Enumeration = 'Enumeration',
+ Class = 'Class',
}
export interface DocAgnosticFormat {
@@ -108,6 +110,7 @@ export interface DocSection {
methods: Array<TypescriptMethod | SolidityMethod>;
properties: Property[];
types: CustomType[];
+ functions?: TypescriptFunction[];
events?: Event[];
}
@@ -117,6 +120,11 @@ export interface TypescriptMethod extends BaseMethod {
typeParameter?: TypeParameter;
}
+export interface TypescriptFunction extends BaseFunction {
+ source?: Source;
+ typeParameter?: TypeParameter;
+}
+
export interface SolidityMethod extends BaseMethod {
isConstant?: boolean;
isPayable?: boolean;
@@ -205,6 +213,14 @@ export interface BaseMethod {
comment?: string;
}
+export interface BaseFunction {
+ name: string;
+ returnComment?: string | undefined;
+ parameters: Parameter[];
+ returnType: Type;
+ comment?: string;
+}
+
export interface TypeDefinitionByName {
[typeName: string]: CustomType;
}
diff --git a/packages/react-docs/src/utils/doxity_utils.ts b/packages/react-docs/src/utils/doxity_utils.ts
index 26dea6966..1b91690e0 100644
--- a/packages/react-docs/src/utils/doxity_utils.ts
+++ b/packages/react-docs/src/utils/doxity_utils.ts
@@ -116,6 +116,7 @@ export const doxityUtils = {
methods,
properties,
types: [],
+ functions: [],
events,
};
docAgnosticFormat[contractName] = docSection;
diff --git a/packages/react-docs/src/utils/typedoc_utils.ts b/packages/react-docs/src/utils/typedoc_utils.ts
index e4cea1e40..02f5b4049 100644
--- a/packages/react-docs/src/utils/typedoc_utils.ts
+++ b/packages/react-docs/src/utils/typedoc_utils.ts
@@ -15,6 +15,7 @@ import {
TypeDocNode,
TypeDocType,
TypeParameter,
+ TypescriptFunction,
TypescriptMethod,
} from '../types';
import { utils } from '../utils/utils';
@@ -81,17 +82,22 @@ export const typeDocUtils = {
}
}
- // Since the `types.ts` file is the only file that does not export a module/class but
- // instead has each type export itself, we do not need to go down two levels of nesting
- // for it.
let entities;
let packageComment = '';
- if (sectionName === docsInfo.sections.types) {
- entities = packageDefinitionWithMergedChildren.children;
- } else {
+ // HACK: We assume 1 exported class per file
+ const classChildren = _.filter(packageDefinitionWithMergedChildren.children, (child: TypeDocNode) => {
+ return child.kindString === KindString.Class;
+ });
+ if (classChildren.length > 1 && sectionName !== 'types') {
+ throw new Error('`react-docs` only supports projects with 1 exported class per file');
+ }
+ const isClassExport = packageDefinitionWithMergedChildren.children[0].kindString === KindString.Class;
+ if (isClassExport) {
entities = packageDefinitionWithMergedChildren.children[0].children;
const commentObj = packageDefinitionWithMergedChildren.children[0].comment;
packageComment = !_.isUndefined(commentObj) ? commentObj.shortText : packageComment;
+ } else {
+ entities = packageDefinitionWithMergedChildren.children;
}
const docSection = typeDocUtils._convertEntitiesToDocSection(entities, docsInfo, sectionName);
@@ -105,6 +111,7 @@ export const typeDocUtils = {
comment: '',
constructors: [],
methods: [],
+ functions: [],
properties: [],
types: [],
};
@@ -124,6 +131,13 @@ export const typeDocUtils = {
docSection.constructors.push(constructor);
break;
+ case KindString.Function:
+ if (entity.flags.isExported) {
+ const func = typeDocUtils._convertFunction(entity, docsInfo.sections, sectionName, docsInfo.id);
+ docSection.functions.push(func);
+ }
+ break;
+
case KindString.Method:
if (entity.flags.isPublic) {
isConstructor = false;
@@ -151,7 +165,6 @@ export const typeDocUtils = {
break;
case KindString.Interface:
- case KindString.Function:
case KindString.Variable:
case KindString.Enumeration:
case KindString.TypeAlias:
@@ -162,10 +175,20 @@ export const typeDocUtils = {
sectionName,
docsInfo.id,
);
- docSection.types.push(customType);
+ 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 utils.spawnSwitchErr('kindString', entity.kindString);
}
@@ -303,6 +326,38 @@ export const typeDocUtils = {
};
return method;
},
+ _convertFunction(
+ entity: TypeDocNode,
+ sections: SectionsMap,
+ sectionName: string,
+ docId: string,
+ ): TypescriptFunction {
+ const signature = entity.signatures[0];
+ const source = entity.sources[0];
+ const hasComment = !_.isUndefined(signature.comment);
+
+ const parameters = _.map(signature.parameters, param => {
+ return typeDocUtils._convertParameter(param, sections, sectionName, docId);
+ });
+ const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId);
+ const typeParameter = _.isUndefined(signature.typeParameter)
+ ? undefined
+ : typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId);
+
+ const func = {
+ 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,
+ },
+ parameters,
+ returnType,
+ typeParameter,
+ };
+ return func;
+ },
_convertTypeParameter(
entity: TypeDocNode,
sections: SectionsMap,
diff --git a/packages/react-docs/tsconfig.json b/packages/react-docs/tsconfig.json
index 9af6638a2..82f44a62c 100644
--- a/packages/react-docs/tsconfig.json
+++ b/packages/react-docs/tsconfig.json
@@ -9,5 +9,5 @@
"*": ["node_modules/@types/*", "*"]
}
},
- "include": ["./src/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"]
+ "include": ["./src/**/*"]
}