diff --git a/package.json b/package.json index 78ab662f3..8275a62f2 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,16 @@ "@codemirror/gutter": "^0.18.4", "@codemirror/highlight": "^0.18.4", "@codemirror/history": "^0.18.1", + "@codemirror/lang-cpp": "^0.18.0", + "@codemirror/lang-css": "^0.18.0", + "@codemirror/lang-html": "^0.18.1", + "@codemirror/lang-java": "^0.18.0", + "@codemirror/lang-javascript": "^0.18.0", "@codemirror/lang-json": "^0.18.0", + "@codemirror/lang-markdown": "^0.18.4", + "@codemirror/lang-rust": "^0.18.0", + "@codemirror/lang-sql": "^0.18.0", + "@codemirror/lang-xml": "^0.18.0", "@codemirror/language": "^0.18.2", "@codemirror/legacy-modes": "^0.18.1", "@codemirror/lint": "^0.18.4", @@ -36,7 +45,6 @@ "@hot-loader/react-dom": "^16.14.0", "axios": "^0.21.1", "chart.js": "^2.9.3", - "codemirror": "^5.62.0", "date-fns": "^2.22.1", "debounce": "^1.2.1", "deepmerge": "^4.2.2", @@ -96,7 +104,7 @@ "@types/debounce": "^1.2.0", "@types/events": "^3.0.0", "@types/history": "^4.7.9", - "@types/node": "^16.3.0", + "@types/node": "^16.4.0", "@types/qrcode.react": "^1.0.2", "@types/query-string": "^6.3.0", "@types/react": "^16.14.11", diff --git a/resources/scripts/components/admin/nests/eggs/EggInstallContainer.tsx b/resources/scripts/components/admin/nests/eggs/EggInstallContainer.tsx index 0184916c2..a4b2d9ead 100644 --- a/resources/scripts/components/admin/nests/eggs/EggInstallContainer.tsx +++ b/resources/scripts/components/admin/nests/eggs/EggInstallContainer.tsx @@ -1,10 +1,10 @@ +import { shell } from '@codemirror/legacy-modes/mode/shell'; import React from 'react'; import tw from 'twin.macro'; import AdminBox from '@/components/admin/AdminBox'; import { Context } from '@/components/admin/nests/eggs/EggRouter'; -import Editor2 from '@/components/elements/Editor2'; -import { shell } from '@codemirror/legacy-modes/mode/shell'; import Button from '@/components/elements/Button'; +import Editor from '@/components/elements/Editor'; import Input from '@/components/elements/Input'; import Label from '@/components/elements/Label'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; @@ -28,7 +28,7 @@ export default () => {
- +
diff --git a/resources/scripts/components/elements/CodemirrorEditor.tsx b/resources/scripts/components/elements/CodemirrorEditor.tsx deleted file mode 100644 index de33bc069..000000000 --- a/resources/scripts/components/elements/CodemirrorEditor.tsx +++ /dev/null @@ -1,216 +0,0 @@ -import React, { useCallback, useEffect, useState } from 'react'; -import CodeMirror from 'codemirror'; -import styled from 'styled-components/macro'; -import tw from 'twin.macro'; -import modes from '@/modes'; - -require('codemirror/lib/codemirror.css'); -require('codemirror/theme/ayu-mirage.css'); -require('codemirror/addon/edit/closebrackets'); -require('codemirror/addon/edit/closetag'); -require('codemirror/addon/edit/matchbrackets'); -require('codemirror/addon/edit/matchtags'); -require('codemirror/addon/edit/trailingspace'); -require('codemirror/addon/fold/foldcode'); -require('codemirror/addon/fold/foldgutter.css'); -require('codemirror/addon/fold/foldgutter'); -require('codemirror/addon/fold/brace-fold'); -require('codemirror/addon/fold/comment-fold'); -require('codemirror/addon/fold/indent-fold'); -require('codemirror/addon/fold/markdown-fold'); -require('codemirror/addon/fold/xml-fold'); -require('codemirror/addon/hint/css-hint'); -require('codemirror/addon/hint/html-hint'); -require('codemirror/addon/hint/javascript-hint'); -require('codemirror/addon/hint/show-hint.css'); -require('codemirror/addon/hint/show-hint'); -require('codemirror/addon/hint/sql-hint'); -require('codemirror/addon/hint/xml-hint'); -require('codemirror/addon/mode/simple'); -require('codemirror/addon/dialog/dialog.css'); -require('codemirror/addon/dialog/dialog'); -require('codemirror/addon/scroll/annotatescrollbar'); -require('codemirror/addon/scroll/scrollpastend'); -require('codemirror/addon/scroll/simplescrollbars.css'); -require('codemirror/addon/scroll/simplescrollbars'); -require('codemirror/addon/search/jump-to-line'); -require('codemirror/addon/search/match-highlighter'); -require('codemirror/addon/search/matchesonscrollbar.css'); -require('codemirror/addon/search/matchesonscrollbar'); -require('codemirror/addon/search/search'); -require('codemirror/addon/search/searchcursor'); - -require('codemirror/mode/brainfuck/brainfuck'); -require('codemirror/mode/clike/clike'); -require('codemirror/mode/css/css'); -require('codemirror/mode/dart/dart'); -require('codemirror/mode/diff/diff'); -require('codemirror/mode/dockerfile/dockerfile'); -require('codemirror/mode/erlang/erlang'); -require('codemirror/mode/gfm/gfm'); -require('codemirror/mode/go/go'); -require('codemirror/mode/handlebars/handlebars'); -require('codemirror/mode/htmlembedded/htmlembedded'); -require('codemirror/mode/htmlmixed/htmlmixed'); -require('codemirror/mode/http/http'); -require('codemirror/mode/javascript/javascript'); -require('codemirror/mode/jsx/jsx'); -require('codemirror/mode/julia/julia'); -require('codemirror/mode/lua/lua'); -require('codemirror/mode/markdown/markdown'); -require('codemirror/mode/nginx/nginx'); -require('codemirror/mode/perl/perl'); -require('codemirror/mode/php/php'); -require('codemirror/mode/properties/properties'); -require('codemirror/mode/protobuf/protobuf'); -require('codemirror/mode/pug/pug'); -require('codemirror/mode/python/python'); -require('codemirror/mode/rpm/rpm'); -require('codemirror/mode/ruby/ruby'); -require('codemirror/mode/rust/rust'); -require('codemirror/mode/sass/sass'); -require('codemirror/mode/shell/shell'); -require('codemirror/mode/smarty/smarty'); -require('codemirror/mode/sql/sql'); -require('codemirror/mode/swift/swift'); -require('codemirror/mode/toml/toml'); -require('codemirror/mode/twig/twig'); -require('codemirror/mode/vue/vue'); -require('codemirror/mode/xml/xml'); -require('codemirror/mode/yaml/yaml'); - -const EditorContainer = styled.div` - min-height: 16rem; - height: calc(100vh - 20rem); - ${tw`relative`}; - - > div { - ${tw`rounded h-full`}; - } - - .CodeMirror { - font-size: 12px; - line-height: 1.375rem; - } - - .CodeMirror-linenumber { - padding: 1px 12px 0 12px !important; - } - - .CodeMirror-foldmarker { - color: #CBCCC6; - text-shadow: none; - margin-left: 0.25rem; - margin-right: 0.25rem; - } -`; - -export interface Props { - style?: React.CSSProperties; - initialContent?: string; - mode: string; - filename?: string; - onModeChanged: (mode: string) => void; - fetchContent: (callback: () => Promise) => void; - onContentSaved: () => void; -} - -const findModeByFilename = (filename: string) => { - for (let i = 0; i < modes.length; i++) { - const info = modes[i]; - - if (info.file && info.file.test(filename)) { - return info; - } - } - - const dot = filename.lastIndexOf('.'); - const ext = dot > -1 && filename.substring(dot + 1, filename.length); - - if (ext) { - for (let i = 0; i < modes.length; i++) { - const info = modes[i]; - if (info.ext) { - for (let j = 0; j < info.ext.length; j++) { - if (info.ext[j] === ext) { - return info; - } - } - } - } - } - - return undefined; -}; - -export default ({ style, initialContent, filename, mode, fetchContent, onContentSaved, onModeChanged }: Props) => { - const [ editor, setEditor ] = useState(); - - const ref = useCallback((node) => { - if (!node) return; - - const e = CodeMirror.fromTextArea(node, { - mode: 'text/plain', - theme: 'ayu-mirage', - indentUnit: 4, - smartIndent: true, - tabSize: 4, - indentWithTabs: false, - lineWrapping: true, - lineNumbers: true, - // @ts-ignore - foldGutter: true, - fixedGutter: true, - scrollbarStyle: 'native', - coverGutterNextToScrollbar: false, - readOnly: false, - showCursorWhenSelecting: false, - autofocus: false, - spellcheck: true, - autocorrect: false, - autocapitalize: false, - lint: false, - autoCloseBrackets: true, - matchBrackets: true, - gutters: [ 'CodeMirror-linenumbers', 'CodeMirror-foldgutter' ], - }); - - setEditor(e); - }, []); - - useEffect(() => { - if (filename === undefined) { - return; - } - - onModeChanged(findModeByFilename(filename)?.mime || 'text/plain'); - }, [ filename ]); - - useEffect(() => { - editor && editor.setOption('mode', mode); - }, [ editor, mode ]); - - useEffect(() => { - editor && editor.setValue(initialContent || ''); - }, [ editor, initialContent ]); - - useEffect(() => { - if (!editor) { - fetchContent(() => Promise.reject(new Error('no editor session has been configured'))); - return; - } - - editor.addKeyMap({ - 'Ctrl-S': () => onContentSaved(), - 'Cmd-S': () => onContentSaved(), - }); - - fetchContent(() => Promise.resolve(editor.getValue())); - }, [ editor, fetchContent, onContentSaved ]); - - return ( - -