From f4e1ff24bd1566ee6495c5b6f8f37f5663bed744 Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 6 Nov 2019 21:10:41 +0800 Subject: [PATCH] make react-split-pane works --- @antv/gatsby-theme-antv/package.json | 1 + .../site/components/PlayGround.module.less | 11 ++- .../site/components/PlayGround.tsx | 86 ++++++++++--------- yarn.lock | 19 ++++ 4 files changed, 77 insertions(+), 40 deletions(-) diff --git a/@antv/gatsby-theme-antv/package.json b/@antv/gatsby-theme-antv/package.json index 9aeab6b8..6a3cc839 100644 --- a/@antv/gatsby-theme-antv/package.json +++ b/@antv/gatsby-theme-antv/package.json @@ -24,6 +24,7 @@ "@babel/standalone": "^7.6.4", "@hot-loader/react-dom": "^16.9.0+4.12.11", "@types/classnames": "^2.2.9", + "@types/codemirror": "^0.0.80", "@types/jest": "^24.0.18", "@types/lodash-es": "^4.17.3", "@types/react": "^16.9.2", diff --git a/@antv/gatsby-theme-antv/site/components/PlayGround.module.less b/@antv/gatsby-theme-antv/site/components/PlayGround.module.less index 70f647e4..61aeff79 100644 --- a/@antv/gatsby-theme-antv/site/components/PlayGround.module.less +++ b/@antv/gatsby-theme-antv/site/components/PlayGround.module.less @@ -71,11 +71,20 @@ line-height: 1.5; font-size: 13px; padding: 8px 16px; - height: calc(100% - 54px); + height: calc(100% - 37px); } } } + // 非常关键 + // 参考:https://codesandbox.io/s/mow7x4zyqx + :global { + .Pane1, + .Pane2 { + overflow: auto; + } + } + .exampleContainerWrapper { height: 100%; display: flex; diff --git a/@antv/gatsby-theme-antv/site/components/PlayGround.tsx b/@antv/gatsby-theme-antv/site/components/PlayGround.tsx index beb9d719..cbad2aa7 100644 --- a/@antv/gatsby-theme-antv/site/components/PlayGround.tsx +++ b/@antv/gatsby-theme-antv/site/components/PlayGround.tsx @@ -1,5 +1,6 @@ import React, { useRef, useEffect, useState } from 'react'; -import { UnControlled as CodeMirror } from 'react-codemirror2'; +import { UnControlled as CodeMirrorEditor } from 'react-codemirror2'; +import { Editor } from 'codemirror'; import { Typography, Icon, Tooltip } from 'antd'; import debounce from 'lodash/debounce'; import { @@ -74,6 +75,7 @@ const PlayGround: React.FC = ({ const { t } = useTranslation(); const fullscreenNode = useRef(null); const playpround = useRef(null); + const cmInstance = useRef(); const [isFullScreen, updateIsFullScreen] = useState(false); const [error, setError] = useState(); const [compiledCode, updateCompiledCode] = useState(babeledSource); @@ -116,9 +118,51 @@ const PlayGround: React.FC = ({ }; }, []); + const editor = ( + { + updateCurrentSourceCode(value); + try { + const { code } = transform(value, { + filename: relativePath, + presets: ['react', 'typescript', 'es2015', 'stage-3'], + plugins: ['transform-modules-umd'], + }); + updateCompiledCode(code); + } catch (e) { + console.error(e); + setError(e); + return; + } + setError(null); + }} + editorDidMount={editor => { + cmInstance.current = editor; + }} + /> + ); + return (
- +
{error ? ( = ({
-
- { - updateCurrentSourceCode(value); - try { - const { code } = transform(value, { - filename: relativePath, - presets: ['react', 'typescript', 'es2015', 'stage-3'], - plugins: ['transform-modules-umd'], - }); - updateCompiledCode(code); - } catch (e) { - console.error(e); - setError(e); - return; - } - setError(null); - }} - /> -
+
{editor}
diff --git a/yarn.lock b/yarn.lock index 5be8ad41..7dbb7fd0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1540,6 +1540,13 @@ resolved "https://registry.npmjs.org/@types/classnames/-/classnames-2.2.9.tgz#d868b6febb02666330410fe7f58f3c4b8258be7b" integrity sha512-MNl+rT5UmZeilaPxAVs6YaPC2m6aA8rofviZbhbxpPpl61uKodfdQVsBtgJGTqGizEf02oW3tsVe7FYB8kK14A== +"@types/codemirror@^0.0.80": + version "0.0.80" + resolved "https://registry.npmjs.org/@types/codemirror/-/codemirror-0.0.80.tgz#c047bb30462582615c3d51e5be6155315f764427" + integrity sha512-oTi/s9PkWo3+/L9UrRpqngc4i6fRFMp3YQS0nv3Wy5vjl9n6GsqI9oNF6rjl/7J16Ipe67F9eatwRMTSB/Bo0w== + dependencies: + "@types/tern" "*" + "@types/configstore@^2.1.1": version "2.1.1" resolved "https://registry.npmjs.org/@types/configstore/-/configstore-2.1.1.tgz#cd1e8553633ad3185c3f2f239ecff5d2643e92b6" @@ -1555,6 +1562,11 @@ resolved "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== +"@types/estree@*": + version "0.0.39" + resolved "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + "@types/events@*": version "3.0.0" resolved "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" @@ -1714,6 +1726,13 @@ resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw== +"@types/tern@*": + version "0.23.3" + resolved "https://registry.npmjs.org/@types/tern/-/tern-0.23.3.tgz#4b54538f04a88c9ff79de1f6f94f575a7f339460" + integrity sha512-imDtS4TAoTcXk0g7u4kkWqedB3E4qpjXzCpD2LU5M5NAXHzCDsypyvXSaG7mM8DKYkCRa7tFp4tS/lp/Wo7Q3w== + dependencies: + "@types/estree" "*" + "@types/testing-library__dom@*", "@types/testing-library__dom@^6.0.0": version "6.10.0" resolved "https://registry.npmjs.org/@types/testing-library__dom/-/testing-library__dom-6.10.0.tgz#590d76e3875a7c536dc744eb530cbf51b6483404"