diff --git a/app/client/craco.config.js b/app/client/craco.config.js index 03d5045123..6335c3850a 100644 --- a/app/client/craco.config.js +++ b/app/client/craco.config.js @@ -1,13 +1,7 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin"); const path = require("path"); module.exports = { webpack: { - plugins: [ - new MonacoWebpackPlugin({ - languages: ["json", "javascript"], - }), - ], resolve: { modules: [path.resolve(__dirname, "src"), "node_modules"], }, diff --git a/app/client/package.json b/app/client/package.json index 452a7f9ed0..2327409962 100644 --- a/app/client/package.json +++ b/app/client/package.json @@ -36,6 +36,7 @@ "@uppy/webcam": "^1.3.1", "axios": "^0.18.0", "chance": "^1.1.3", + "codemirror": "^5.50.0", "eslint": "^6.4.0", "flow-bin": "^0.91.0", "fontfaceobserver": "^2.1.0", @@ -48,8 +49,6 @@ "lodash": "^4.17.11", "moment": "^2.24.0", "moment-timezone": "^0.5.27", - "monaco-editor": "^0.19.0", - "monaco-editor-webpack-plugin": "^1.1.0", "nanoid": "^2.0.4", "node-sass": "^4.11.0", "normalizr": "^3.3.0", @@ -70,7 +69,6 @@ "react-router-dom": "^5.1.2", "react-scripts": "^3.3.0", "react-select": "^3.0.8", - "react-simple-tree-menu": "^1.1.9", "react-tabs": "^3.0.0", "react-transition-group": "^4.3.0", "redux": "^4.0.1", @@ -116,6 +114,7 @@ "@storybook/addons": "^5.2.6", "@storybook/preset-create-react-app": "^1.3.1", "@storybook/react": "^5.2.6", + "@types/codemirror": "^0.0.82", "@types/jest": "^24.0.22", "@types/react-select": "^3.0.5", "@types/react-tabs": "^2.3.1", diff --git a/app/client/src/components/editorComponents/ApiResponseView.tsx b/app/client/src/components/editorComponents/ApiResponseView.tsx index df4472839f..7dea588b8f 100644 --- a/app/client/src/components/editorComponents/ApiResponseView.tsx +++ b/app/client/src/components/editorComponents/ApiResponseView.tsx @@ -6,12 +6,12 @@ import { BaseText } from "components/designSystems/blueprint/TextComponent"; import { BaseTabbedView } from "components/designSystems/appsmith/TabbedView"; import styled from "styled-components"; import { AppState } from "reducers"; -import CodeEditor from "./CodeEditor"; import { ActionResponse } from "api/ActionAPI"; import { formatBytes } from "utils/helpers"; import { APIEditorRouteParams } from "constants/routes"; import { ApiPaneReduxState } from "reducers/uiReducers/apiPaneReducer"; import LoadingOverlayScreen from "components/editorComponents/LoadingOverlayScreen"; +import DynamicAutocompleteInput from "components/editorComponents/DynamicAutocompleteInput"; const ResponseWrapper = styled.div` position: relative; @@ -138,16 +138,12 @@ const ApiResponseView = (props: Props) => { key: "body", title: "Response Body", panelComponent: ( - ), }, diff --git a/app/client/src/components/editorComponents/CodeEditor.tsx b/app/client/src/components/editorComponents/CodeEditor.tsx index 0050f303ee..a5967da8f3 100644 --- a/app/client/src/components/editorComponents/CodeEditor.tsx +++ b/app/client/src/components/editorComponents/CodeEditor.tsx @@ -1,8 +1,9 @@ -import React from "react"; -import MonacoEditor from "react-monaco-editor"; - +import React, { ChangeEvent } from "react"; +import cm from "codemirror"; import styled from "styled-components"; -import { editor } from "monaco-editor"; +import "codemirror/lib/codemirror.css"; +import "codemirror/theme/monokai.css"; +require("codemirror/mode/javascript/javascript"); const Wrapper = styled.div<{ height: number }>` height: ${props => props.height}px; @@ -12,46 +13,49 @@ const Wrapper = styled.div<{ height: number }>` interface Props { input: { value: string; - onChange?: (value: string) => void; + onChange?: (event: ChangeEvent) => void; }; - language: string; height: number; - placeholder?: string; - lineNumbers?: "on" | "off"; - glyphMargin?: boolean; - folding?: boolean; - lineDecorationsWidth?: number; - lineNumbersMinChars?: number; - theme?: "LIGHT" | "DARK"; } -const CodeEditor = (props: Props) => { - const options: editor.IEditorConstructionOptions = { - wordWrap: "on", - wrappingIndent: "indent", - selectOnLineNumbers: true, - minimap: { enabled: false }, - readOnly: !props.input.onChange, - lineNumbers: props.lineNumbers, - glyphMargin: props.glyphMargin, - folding: props.folding, - contextmenu: false, - scrollBeyondLastLine: false, - // // Undocumented see https://github.com/Microsoft/vscode/issues/30795#issuecomment-410998882 - lineDecorationsWidth: props.lineDecorationsWidth, - lineNumbersMinChars: props.lineNumbersMinChars, - }; - return ( - - - - ); -}; +class CodeEditor extends React.Component { + textArea = React.createRef(); + editor: any; + constructor(props: Props) { + super(props); + } + componentDidMount(): void { + if (this.textArea.current) { + this.editor = cm.fromTextArea(this.textArea.current, { + mode: { name: "javascript", json: true }, + value: this.props.input.value, + lineNumbers: true, + tabSize: 2, + indentWithTabs: true, + lineWrapping: true, + }); + } + } + + componentDidUpdate( + prevProps: Readonly, + prevState: Readonly<{}>, + snapshot?: any, + ): void { + this.editor.setValue(this.props.input.value); + } + + render(): React.ReactNode { + return ( + +