From e31309f213e9b900225b077cb27792958ba1ad5d Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 7 Mar 2018 13:57:17 +0100 Subject: Allow user to change versions in demo example --- packages/react-docs/example/ts/docs.tsx | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 packages/react-docs/example/ts/docs.tsx (limited to 'packages/react-docs/example/ts/docs.tsx') diff --git a/packages/react-docs/example/ts/docs.tsx b/packages/react-docs/example/ts/docs.tsx new file mode 100644 index 000000000..98cd5b355 --- /dev/null +++ b/packages/react-docs/example/ts/docs.tsx @@ -0,0 +1,93 @@ +import * as _ from 'lodash'; +import * as React from 'react'; + +import { Documentation } from '../../src/ts/components/documentation'; +import { DocsInfo } from '../../src/ts/docs_info'; +import { DocAgnosticFormat, DocsInfoConfig, SupportedDocJson, TypeDocNode } from '../../src/ts/types'; + +import * as v1TypeDocJson from './json/0.1.12.json'; +import * as v2TypeDocJson from './json/0.2.0.json'; + +/* tslint:disable:no-var-requires */ +const IntroMarkdown = require('md/introduction'); +/* tslint:enable:no-var-requires */ + +const docSections = { + introduction: 'introduction', + web3Wrapper: 'web3Wrapper', +}; + +const docsInfoConfig: DocsInfoConfig = { + id: 'web3Wrapper', + type: SupportedDocJson.TypeDoc, + displayName: 'Web3 Wrapper', + packageUrl: 'https://github.com/0xProject/0x-monorepo', + menu: { + introduction: [docSections.introduction], + web3Wrapper: [docSections.web3Wrapper], + }, + sectionNameToMarkdown: { + [docSections.introduction]: IntroMarkdown, + }, + // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is + // currently no way to extract the re-exported types from index.ts via TypeDoc :( + publicTypes: ['TxData', 'TransactionReceipt', 'RawLogEntry'], + sectionNameToModulePath: { + [docSections.web3Wrapper]: ['"index"'], + }, + menuSubsectionToVersionWhenIntroduced: {}, + sections: docSections, + visibleConstructors: [docSections.web3Wrapper], +}; +const docsInfo = new DocsInfo(docsInfoConfig); + +const availableVersions = ['0.1.12', '0.2.0']; +const versionToDocJSON: { [semver: string]: object } = { + '0.1.12': v1TypeDocJson, + '0.2.0': v2TypeDocJson, +}; + +export interface DocsProps {} + +interface DocsState { + selectedVersion: string; + docAgnosticFormat?: DocAgnosticFormat; +} + +export class Docs extends React.Component { + constructor(props: DocsProps) { + super(props); + this.state = { + selectedVersion: '0.2.0', + docAgnosticFormat: docsInfo.convertToDocAgnosticFormat(v1TypeDocJson), + }; + } + public render() { + const menuSubsectionsBySection = _.isUndefined(this.state.docAgnosticFormat) + ? {} + : docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat); + return ( + + ); + } + private _onVersionSelected(semver: string) { + const selectedDocJSON = versionToDocJSON[semver]; + this.setState({ + selectedVersion: semver, + docAgnosticFormat: docsInfo.convertToDocAgnosticFormat(selectedDocJSON as TypeDocNode), + }); + } + private _getSourceUrl() { + const sourceUrl = `${docsInfoConfig.packageUrl}/blob/@0xproject/web3-wrapper%40${ + this.state.selectedVersion + }/packages/web3-wrapper`; + return sourceUrl; + } +} -- cgit v1.2.3 From 5356b0e1186ab8bb835c118507ae27947ca6e8c2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 7 Mar 2018 14:11:14 +0100 Subject: Small improvements to docs --- packages/react-docs/example/ts/docs.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'packages/react-docs/example/ts/docs.tsx') diff --git a/packages/react-docs/example/ts/docs.tsx b/packages/react-docs/example/ts/docs.tsx index 98cd5b355..caff83422 100644 --- a/packages/react-docs/example/ts/docs.tsx +++ b/packages/react-docs/example/ts/docs.tsx @@ -5,7 +5,7 @@ import { Documentation } from '../../src/ts/components/documentation'; import { DocsInfo } from '../../src/ts/docs_info'; import { DocAgnosticFormat, DocsInfoConfig, SupportedDocJson, TypeDocNode } from '../../src/ts/types'; -import * as v1TypeDocJson from './json/0.1.12.json'; +import * as v0TypeDocJson from './json/0.1.12.json'; import * as v2TypeDocJson from './json/0.2.0.json'; /* tslint:disable:no-var-requires */ @@ -43,8 +43,8 @@ const docsInfo = new DocsInfo(docsInfoConfig); const availableVersions = ['0.1.12', '0.2.0']; const versionToDocJSON: { [semver: string]: object } = { - '0.1.12': v1TypeDocJson, - '0.2.0': v2TypeDocJson, + [availableVersions[0]]: v0TypeDocJson, + [availableVersions[1]]: v2TypeDocJson, }; export interface DocsProps {} @@ -58,8 +58,8 @@ export class Docs extends React.Component { constructor(props: DocsProps) { super(props); this.state = { - selectedVersion: '0.2.0', - docAgnosticFormat: docsInfo.convertToDocAgnosticFormat(v1TypeDocJson), + selectedVersion: availableVersions[1], + docAgnosticFormat: docsInfo.convertToDocAgnosticFormat(v0TypeDocJson), }; } public render() { -- cgit v1.2.3 From a3e15c910c4722dbd3c0b5d8bd4ef28abe1667eb Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 7 Mar 2018 14:23:00 +0100 Subject: Update 0.2.0 doc json to include types --- packages/react-docs/example/ts/docs.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'packages/react-docs/example/ts/docs.tsx') diff --git a/packages/react-docs/example/ts/docs.tsx b/packages/react-docs/example/ts/docs.tsx index caff83422..c4b165c13 100644 --- a/packages/react-docs/example/ts/docs.tsx +++ b/packages/react-docs/example/ts/docs.tsx @@ -4,6 +4,7 @@ import * as React from 'react'; import { Documentation } from '../../src/ts/components/documentation'; import { DocsInfo } from '../../src/ts/docs_info'; import { DocAgnosticFormat, DocsInfoConfig, SupportedDocJson, TypeDocNode } from '../../src/ts/types'; +import { constants } from '../../src/ts/utils/constants'; import * as v0TypeDocJson from './json/0.1.12.json'; import * as v2TypeDocJson from './json/0.2.0.json'; @@ -15,6 +16,7 @@ const IntroMarkdown = require('md/introduction'); const docSections = { introduction: 'introduction', web3Wrapper: 'web3Wrapper', + types: constants.TYPES_SECTION_NAME, }; const docsInfoConfig: DocsInfoConfig = { @@ -25,6 +27,7 @@ const docsInfoConfig: DocsInfoConfig = { menu: { introduction: [docSections.introduction], web3Wrapper: [docSections.web3Wrapper], + types: [docSections.types], }, sectionNameToMarkdown: { [docSections.introduction]: IntroMarkdown, @@ -33,7 +36,8 @@ const docsInfoConfig: DocsInfoConfig = { // currently no way to extract the re-exported types from index.ts via TypeDoc :( publicTypes: ['TxData', 'TransactionReceipt', 'RawLogEntry'], sectionNameToModulePath: { - [docSections.web3Wrapper]: ['"index"'], + [docSections.web3Wrapper]: ['"web3-wrapper/src/index"'], + [docSections.types]: ['"types/src/index"'], }, menuSubsectionToVersionWhenIntroduced: {}, sections: docSections, @@ -59,7 +63,7 @@ export class Docs extends React.Component { super(props); this.state = { selectedVersion: availableVersions[1], - docAgnosticFormat: docsInfo.convertToDocAgnosticFormat(v0TypeDocJson), + docAgnosticFormat: docsInfo.convertToDocAgnosticFormat(v2TypeDocJson), }; } public render() { -- cgit v1.2.3 From 9aec1feae30870b3e6c8a778051877c83aacbe58 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 7 Mar 2018 15:19:59 +0100 Subject: Move remaining type configs to topLevel DocsInfoConfigs --- packages/react-docs/example/ts/docs.tsx | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'packages/react-docs/example/ts/docs.tsx') diff --git a/packages/react-docs/example/ts/docs.tsx b/packages/react-docs/example/ts/docs.tsx index c4b165c13..f1c4a31bd 100644 --- a/packages/react-docs/example/ts/docs.tsx +++ b/packages/react-docs/example/ts/docs.tsx @@ -32,9 +32,6 @@ const docsInfoConfig: DocsInfoConfig = { sectionNameToMarkdown: { [docSections.introduction]: IntroMarkdown, }, - // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is - // currently no way to extract the re-exported types from index.ts via TypeDoc :( - publicTypes: ['TxData', 'TransactionReceipt', 'RawLogEntry'], sectionNameToModulePath: { [docSections.web3Wrapper]: ['"web3-wrapper/src/index"'], [docSections.types]: ['"types/src/index"'], @@ -42,6 +39,35 @@ const docsInfoConfig: DocsInfoConfig = { menuSubsectionToVersionWhenIntroduced: {}, sections: docSections, visibleConstructors: [docSections.web3Wrapper], + typeConfigs: { + // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is + // currently no way to extract the re-exported types from index.ts via TypeDoc :( + publicTypes: ['TxData', 'TransactionReceipt', 'RawLogEntry'], + typeNameToExternalLink: { + Web3: 'https://github.com/ethereum/wiki/wiki/JavaScript-API', + Provider: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L123', + BigNumber: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L127', + DecodedLogEntryEvent: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L150', + LogEntryEvent: 'http://mikemcl.github.io/bignumber.js', + CallData: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L348', + BlockWithoutTransactionData: + 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L314', + LogEntry: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L366', + FilterObject: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L109', + ['Web3.BlockParam']: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L278', + ['Web3.ContractAbi']: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L47', + }, + typeNameToPrefix: { + Provider: 'Web3', + CallData: 'Web3', + BlockWithoutTransactionData: 'Web3', + LogEntry: 'Web3', + FilterObject: 'Web3', + }, + typeNameToDocSection: { + Web3Wrapper: docSections.web3Wrapper, + }, + }, }; const docsInfo = new DocsInfo(docsInfoConfig); -- cgit v1.2.3 From d1a92a0a2e63fc73802b07ca3a3dcaf532e21720 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 7 Mar 2018 16:05:20 +0100 Subject: fix source link --- packages/react-docs/example/ts/docs.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/react-docs/example/ts/docs.tsx') diff --git a/packages/react-docs/example/ts/docs.tsx b/packages/react-docs/example/ts/docs.tsx index f1c4a31bd..70c165636 100644 --- a/packages/react-docs/example/ts/docs.tsx +++ b/packages/react-docs/example/ts/docs.tsx @@ -117,7 +117,7 @@ export class Docs extends React.Component { private _getSourceUrl() { const sourceUrl = `${docsInfoConfig.packageUrl}/blob/@0xproject/web3-wrapper%40${ this.state.selectedVersion - }/packages/web3-wrapper`; + }/packages`; return sourceUrl; } } -- cgit v1.2.3 From e37f3b4fa379592f98078659d0e3a3f674a965f0 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 8 Mar 2018 14:43:09 +0100 Subject: Fix external type links --- packages/react-docs/example/ts/docs.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'packages/react-docs/example/ts/docs.tsx') diff --git a/packages/react-docs/example/ts/docs.tsx b/packages/react-docs/example/ts/docs.tsx index 70c165636..9af81cfe8 100644 --- a/packages/react-docs/example/ts/docs.tsx +++ b/packages/react-docs/example/ts/docs.tsx @@ -45,9 +45,8 @@ const docsInfoConfig: DocsInfoConfig = { publicTypes: ['TxData', 'TransactionReceipt', 'RawLogEntry'], typeNameToExternalLink: { Web3: 'https://github.com/ethereum/wiki/wiki/JavaScript-API', - Provider: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L123', + Provider: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L150', BigNumber: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L127', - DecodedLogEntryEvent: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L150', LogEntryEvent: 'http://mikemcl.github.io/bignumber.js', CallData: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L348', BlockWithoutTransactionData: -- cgit v1.2.3 From f3154313a8112d4e6356a8477d22370273b8e7d1 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 8 Mar 2018 14:43:33 +0100 Subject: Use unencoded @ symbol, browser will fix --- packages/react-docs/example/ts/docs.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/react-docs/example/ts/docs.tsx') diff --git a/packages/react-docs/example/ts/docs.tsx b/packages/react-docs/example/ts/docs.tsx index 9af81cfe8..7d3e3f5b6 100644 --- a/packages/react-docs/example/ts/docs.tsx +++ b/packages/react-docs/example/ts/docs.tsx @@ -114,7 +114,7 @@ export class Docs extends React.Component { }); } private _getSourceUrl() { - const sourceUrl = `${docsInfoConfig.packageUrl}/blob/@0xproject/web3-wrapper%40${ + const sourceUrl = `${docsInfoConfig.packageUrl}/blob/@0xproject/web3-wrapper@${ this.state.selectedVersion }/packages`; return sourceUrl; -- cgit v1.2.3