From 550a377dda79ae23faa4bed11a6ccf31ba6b0ad6 Mon Sep 17 00:00:00 2001 From: Edward Dewhurst Date: Wed, 6 Apr 2022 17:35:55 +0100 Subject: [PATCH] Address review feedback --- .eslintrc.js | 10 ++ package.json | 4 +- tsconfig.composite.json | 1 + website/docusaurus.config.js | 7 -- website/package.json | 2 +- .../theme/CodeBlock/chart.jsx | 101 ----------------- .../theme/CodeBlock/chart.tsx | 102 ++++++++++++++++++ .../import-lightweight-charts-version.ts | 14 +-- .../generate-versions-json-dts/index.js | 22 ---- website/scripts/generate-versions-dts.js | 27 +++++ website/src/components/tutorials/.eslintrc.js | 9 -- .../tutorials/simple-react-example.jsx | 8 +- .../tutorials/themed-chart-colors-wrapper.tsx | 24 ++--- website/theme-colors.js | 2 +- website/tsconfig.json | 1 - website/tutorials/react/01-simple.mdx | 5 + website/tutorials/react/02-advanced.mdx | 5 + 17 files changed, 169 insertions(+), 175 deletions(-) delete mode 100644 website/plugins/enhanced-codeblock/theme/CodeBlock/chart.jsx create mode 100644 website/plugins/enhanced-codeblock/theme/CodeBlock/chart.tsx delete mode 100644 website/plugins/generate-versions-json-dts/index.js create mode 100644 website/scripts/generate-versions-dts.js delete mode 100644 website/src/components/tutorials/.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index 61ceceb2a..013e3b0b5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -174,6 +174,16 @@ module.exports = { 'react/prop-types': 'off', }, }, + { + files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'], + globals: { + CHART_BACKGROUND_COLOR: true, + LINE_LINE_COLOR: true, + CHART_TEXT_COLOR: true, + AREA_TOP_COLOR: true, + AREA_BOTTOM_COLOR: true, + }, + }, { files: ['**/*.ts', '**/*.tsx'], excludedFiles: ['dist/**'], diff --git a/package.json b/package.json index 4fd7d9640..65552d8cc 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "eslint-plugin-mdx": "~1.16.0", "eslint-plugin-prefer-arrow": "~1.2.1", "eslint-plugin-tsdoc": "~0.2.14", - "eslint-plugin-unicorn": "~41.0.0", + "eslint-plugin-unicorn": "~40.1.0", "eslint-plugin-react": "~7.28.0", "express": "~4.17.2", "glob": "~7.2.0", @@ -92,7 +92,7 @@ "bundle-dts": "tsc --noEmit --allowJs dts-config.js && dts-bundle-generator --config dts-config.js", "tsc": "ttsc -p tsconfig.prod.json", "tsc-watch": "npm run tsc -- --watch --preserveWatchOutput", - "tsc-verify": "tsc -b tsconfig.composite.json", + "tsc-verify": "node website/scripts/generate-versions-dts.js && tsc -b tsconfig.composite.json", "lint": "npm-run-all -p lint:**", "lint:eslint": "eslint --format=unix ./", "lint:md": "markdownlint -i \"**/node_modules/**\" -i \"**/website/docs/api/**\" -i \"**/website/versioned_docs/**/api/**\" \"**/*.md\"", diff --git a/tsconfig.composite.json b/tsconfig.composite.json index b8ca06f9d..5f3b32416 100644 --- a/tsconfig.composite.json +++ b/tsconfig.composite.json @@ -2,6 +2,7 @@ "references": [ { "path": "./src/tsconfig.composite.json" }, { "path": "./tests/tsconfig.composite.json" }, + { "path": "./website/tsconfig.json" }, ], "include": [] } diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index dfa497416..44e7d3435 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -334,13 +334,6 @@ async function getConfig() { ], ...versions.map(typedocPluginForVersion), './plugins/enhanced-codeblock', - [ - './plugins/generate-versions-json-dts', - { - versionsJsonPath: path.resolve('./versions.json'), - versionsDtsOutputPath: path.resolve('./versions.d.ts'), - }, - ], ], }; diff --git a/website/package.json b/website/package.json index 520de5a3e..6c7a83d73 100644 --- a/website/package.json +++ b/website/package.json @@ -3,7 +3,7 @@ "scripts": { "docusaurus": "docusaurus", "start": "cross-env TYPEDOC_WATCH=true docusaurus start", - "build": "docusaurus build", + "build": "node scripts/generate-versions-dts.js && docusaurus build", "swizzle": "docusaurus swizzle", "deploy": "docusaurus deploy", "clear": "docusaurus clear", diff --git a/website/plugins/enhanced-codeblock/theme/CodeBlock/chart.jsx b/website/plugins/enhanced-codeblock/theme/CodeBlock/chart.jsx deleted file mode 100644 index 8b850ef30..000000000 --- a/website/plugins/enhanced-codeblock/theme/CodeBlock/chart.jsx +++ /dev/null @@ -1,101 +0,0 @@ -import * as React from 'react'; -import { useDocsVersion } from '@docusaurus/theme-common'; - -import { importLightweightChartsVersion } from './import-lightweight-charts-version'; -import styles from './styles.module.css'; - -function getSrcDocWithScript(script, parentOrigin) { - return ` - -
- - `; -} - -export const Chart = props => { - const { script } = props; - const { origin } = window; - const { version } = useDocsVersion(); - const srcDoc = getSrcDocWithScript(script, origin); - const ref = React.useRef(); - - /** - * iOS Safari seems to run scripts within the iframe in a different order - * compared to desktop Chrome, Safari, etc. - * - * On the desktop browsers the React effect will run first, so the 'ready' - * event listener is added before the iframe script calls postMessage. - * - * On iOS Safari the iframe script runs before the React effect, so the - * 'ready' event listener hasn't been added yet! - * - * We use the __READY_TO_RUN flag to handle this case. If __READY_TO_RUN - * is true then we know that the inner window's run function can be - * called immediately and we don't need to register a event listener. - */ - React.useEffect(() => { - const lightweightChartsImportPromise = importLightweightChartsVersion(version); - const injectCreateChartAndRun = contentWindow => { - lightweightChartsImportPromise.then(mod => { - const createChart = mod.createChart; - - contentWindow.createChart = (container, options) => { - const chart = createChart(container, options); - const resizeListener = () => { - const boundingClientRect = container.getBoundingClientRect(); - chart.resize(boundingClientRect.width, boundingClientRect.height); - }; - - contentWindow.addEventListener('resize', resizeListener, true); - - return chart; - }; - - contentWindow.run(); - }); - }; - - if (ref.current.contentWindow.__READY_TO_RUN) { - injectCreateChartAndRun(ref.current.contentWindow); - return; - } - - const readyMessageListener = event => { - if (event.origin !== origin || event.source !== ref.current.contentWindow) { - return; - } - - if (event.data === 'ready') { - injectCreateChartAndRun(event.source); - window.removeEventListener('message', readyMessageListener, false); - } - }; - - window.addEventListener('message', readyMessageListener, false); - }, [origin, srcDoc]); - - return ( -