diff --git a/resources/scripts/components/server/ServerConsole.tsx b/resources/scripts/components/server/ServerConsole.tsx
index 2e10efcf..0d0c5ee6 100644
--- a/resources/scripts/components/server/ServerConsole.tsx
+++ b/resources/scripts/components/server/ServerConsole.tsx
@@ -12,8 +12,8 @@ import TitledGreyBox from '@/components/elements/TitledGreyBox';
type PowerAction = 'start' | 'stop' | 'restart' | 'kill';
-const ChunkedConsole = lazy(() => import('@/components/server/Console'));
-const ChunkedStatGraphs = lazy(() => import('@/components/server/StatGraphs'));
+const ChunkedConsole = lazy(() => import(/* webpackChunkName: "console" */'@/components/server/Console'));
+const ChunkedStatGraphs = lazy(() => import(/* webpackChunkName: "graphs" */'@/components/server/StatGraphs'));
const StopOrKillButton = ({ onPress }: { onPress: (action: PowerAction) => void }) => {
const [ clicked, setClicked ] = useState(false);
diff --git a/resources/scripts/components/server/files/FileEditContainer.tsx b/resources/scripts/components/server/files/FileEditContainer.tsx
index 681c821b..9119c7af 100644
--- a/resources/scripts/components/server/files/FileEditContainer.tsx
+++ b/resources/scripts/components/server/files/FileEditContainer.tsx
@@ -1,25 +1,115 @@
-import React, { useEffect, useState } from 'react';
+import React, { useCallback, useEffect, useState } from 'react';
import useRouter from 'use-react-router';
import { ServerContext } from '@/state/server';
import getFileContents from '@/api/server/files/getFileContents';
+import ace, { Editor } from 'brace';
+import styled from 'styled-components';
+
+const EditorContainer = styled.div`
+ height: calc(100vh - 16rem);
+ ${tw`relative`};
+
+ #editor {
+ ${tw`rounded h-full`};
+ }
+`;
+
+const modes: { [k: string]: string } = {
+ // eslint-disable-next-line @typescript-eslint/camelcase
+ assembly_x86: 'Assembly (x86)',
+ // eslint-disable-next-line @typescript-eslint/camelcase
+ c_cpp: 'C++',
+ coffee: 'Coffeescript',
+ css: 'CSS',
+ dockerfile: 'Dockerfile',
+ golang: 'Go',
+ html: 'HTML',
+ ini: 'Ini',
+ java: 'Java',
+ javascript: 'Javascript',
+ json: 'JSON',
+ kotlin: 'Kotlin',
+ lua: 'Luascript',
+ perl: 'Perl',
+ php: 'PHP',
+ properties: 'Properties',
+ python: 'Python',
+ ruby: 'Ruby',
+ text: 'Plaintext',
+ toml: 'TOML',
+ typescript: 'Typescript',
+ xml: 'XML',
+ yaml: 'YAML',
+};
export default () => {
const { location: { hash } } = useRouter();
- const [content, setContent] = useState('');
+ const [ content, setContent ] = useState('');
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
+ const [ editor, setEditor ] = useState
();
+ const ref = useCallback(node => {
+ if (node) {
+ setEditor(ace.edit('editor'));
+ }
+ }, []);
+
+ useEffect(() => {
+ Object.keys(modes).forEach(mode => {
+ import(/* webpackMode: "lazy-once", webpackChunkName: "ace_mode" */`brace/mode/${mode}`);
+ });
+ }, []);
+
useEffect(() => {
getFileContents(uuid, hash.replace(/^#/, ''))
.then(setContent)
.catch(error => console.error(error));
- }, []);
+ }, [ uuid, hash ]);
+
+ useEffect(() => {
+ editor && editor.session.setValue(content);
+ }, [ editor, content ]);
+
+ useEffect(() => {
+ if (!editor) {
+ return;
+ }
+
+ require('ayu-ace/mirage');
+ editor.setTheme('ace/theme/ayu-mirage');
+
+ editor.$blockScrolling = Infinity;
+ editor.container.style.lineHeight = '1.375rem';
+ editor.container.style.fontWeight = '500';
+ editor.renderer.updateFontSize();
+ editor.renderer.setShowPrintMargin(false);
+ editor.session.setTabSize(4);
+ editor.session.setUseSoftTabs(true);
+ }, [ editor ]);
return (
-
+
+
+
+
+
+
+
+
);
};
diff --git a/resources/scripts/routers/ServerRouter.tsx b/resources/scripts/routers/ServerRouter.tsx
index 28079fb2..1afd9fcc 100644
--- a/resources/scripts/routers/ServerRouter.tsx
+++ b/resources/scripts/routers/ServerRouter.tsx
@@ -13,7 +13,7 @@ import { CSSTransition } from 'react-transition-group';
import SuspenseSpinner from '@/components/elements/SuspenseSpinner';
const LazyFileEditContainer = lazy>>(
- () => import('@/components/server/files/FileEditContainer')
+ () => import(/* webpackChunkName: "editor" */'@/components/server/files/FileEditContainer')
);
const ServerRouter = ({ match, location }: RouteComponentProps<{ id: string }>) => {
diff --git a/resources/styles/components/forms.css b/resources/styles/components/forms.css
index a56b86a9..584a9163 100644
--- a/resources/styles/components/forms.css
+++ b/resources/styles/components/forms.css
@@ -15,7 +15,7 @@ input[type=number] {
/**
* Styling for other forms throughout the Panel.
*/
-.input, .input-dark {
+.input:not(select), .input-dark:not(select) {
@apply .appearance-none .w-full;
min-width: 0;
@@ -24,7 +24,7 @@ input[type=number] {
}
}
-.input {
+.input:not(select) {
@apply .p-3 .rounded .border .border-neutral-200 .text-neutral-800;
transition: border 150ms linear;
@@ -35,21 +35,21 @@ input[type=number] {
&.error {
@apply .text-red-600 .border-red-500;
}
-}
-.input:disabled {
- @apply .bg-neutral-100 .border-neutral-200;
-}
+ &:disabled {
+ @apply .bg-neutral-100 .border-neutral-200;
+ }
-.input + .input-help {
- @apply .text-xs .text-neutral-400 .pt-2;
+ & + .input-help {
+ @apply .text-xs .text-neutral-400 .pt-2;
- &.error {
- @apply .text-red-600;
+ &.error {
+ @apply .text-red-600;
+ }
}
}
-.input-dark {
+.input-dark:not(select) {
@apply .p-3 .bg-neutral-600 .border .border-neutral-500 .text-sm .rounded .text-neutral-200 .shadow-none;
transition: border 150ms linear, box-shaodw 150ms ease-in;
@@ -83,23 +83,47 @@ label {
}
select:not(.appearance-none) {
- @apply .outline-none .appearance-none .block .bg-white .border .border-neutral-200 .text-neutral-400 .p-3 .pr-8 rounded;
- transition: border-color 150ms linear, color 150ms linear;
+ @apply .shadow-none .block .p-3 .pr-8 .rounded .border .w-full .text-sm;
+ transition: border-color 150ms linear;
- &:hover:not(:disabled), &:focus {
- @apply .outline-none .border-primary-500 .text-neutral-700;
+ &, &:hover:not(:disabled), &:focus {
+ @apply .outline-none;
}
-webkit-appearance: none;
-moz-appearance: none;
+ background-size: 1rem;
+ background-repeat: no-repeat;
+ background-position-x: calc(100% - 0.75rem);
+ background-position-y: center;
&::-ms-expand {
display: none;
}
+}
- background: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath d='M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z'/%3e%3c/svg%3e ") no-repeat center center;
- background-size: 1rem;
- background-position-x: calc(100% - 0.75rem);
+select.input:not(.appearance-none) {
+ @apply .bg-white .border-neutral-200 .text-neutral-400;
+ transition: color 150ms linear;
+ background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath d='M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z'/%3e%3c/svg%3e ");
+
+ &:hover:not(:disabled), &:focus {
+ @apply .border-primary-500 .text-neutral-700;
+ }
+}
+
+select.input-dark:not(.appearance-none) {
+ @apply .bg-neutral-600 .border-neutral-500 .text-neutral-200;
+ background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='%23C3D1DF' d='M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z'/%3e%3c/svg%3e ");
+
+ &:hover:not(:disabled), &:focus {
+ @apply .border-neutral-400;
+ }
+
+ /* fix for Firefox trying to be cool with dark colors */
+ &:focus {
+ @apply .bg-white .text-neutral-800;
+ }
}
.input-dark-label {
diff --git a/yarn.lock b/yarn.lock
index 89cf4213..a9c1559d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1662,6 +1662,10 @@ axios@^0.18.0:
follow-redirects "^1.3.0"
is-buffer "^1.1.5"
+ayu-ace@^2.0.4:
+ version "2.0.4"
+ resolved "https://registry.yarnpkg.com/ayu-ace/-/ayu-ace-2.0.4.tgz#3877d4cbf8668e639de6f67e34c2a88c1589b082"
+
babel-code-frame@^6.22.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
@@ -1850,6 +1854,10 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"
+brace@^0.11.1:
+ version "0.11.1"
+ resolved "https://registry.yarnpkg.com/brace/-/brace-0.11.1.tgz#4896fcc9d544eef45f4bb7660db320d3b379fe58"
+
braces@^2.3.0, braces@^2.3.1, braces@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729"
@@ -3283,6 +3291,10 @@ eslint-plugin-promise@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-4.1.1.tgz#1e08cb68b5b2cd8839f8d5864c796f56d82746db"
+eslint-plugin-react-hooks@^2.1.2:
+ version "2.1.2"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-2.1.2.tgz#1358d2acb2c5e02b7e90c37e611ac258a488e3a7"
+
eslint-plugin-standard@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-standard/-/eslint-plugin-standard-4.0.0.tgz#f845b45109c99cd90e77796940a344546c8f6b5c"