Skip to content

Commit

Permalink
Fix editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizarrus committed Aug 22, 2024
1 parent 599c0fe commit 83b321e
Show file tree
Hide file tree
Showing 10 changed files with 3,600 additions and 680 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
.fruithost
.idea/*
temp/*
/default/js/codemirror/node_modules
default/js/codemirror/node_modules/
default/js/codemirror/package-lock.json
6 changes: 6 additions & 0 deletions default/js/codemirror/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# How to Build?

> npm install
> npm start
The builded editor will be bundled on `build/bundle.js`.
3,862 changes: 3,192 additions & 670 deletions default/js/codemirror/build/bundle.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion default/js/codemirror/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "codemirror",
"version": "1.0.0",
"main": "index.js",
"main": "src/main.js",
"type": "module",
"scripts": {
"start": "rollup -c"
Expand All @@ -11,10 +11,18 @@
"license": "ISC",
"description": "",
"dependencies": {
"@codemirror/basic-setup": "^0.20.0",
"@codemirror/highlight": "^0.19.8",
"@codemirror/lang-html": "^6.4.9",
"@codemirror/lang-javascript": "^6.2.2",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-python": "^6.1.6",
"@codemirror/language": "^6.10.2",
"@codemirror/language-data": "^6.5.1",
"@codemirror/legacy-modes": "^6.4.1",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.32.0",
"@lezer/highlight": "^1.2.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"codemirror": "^6.0.1",
"rollup": "^4.21.0"
Expand Down
15 changes: 8 additions & 7 deletions default/js/codemirror/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { nodeResolve } from "@rollup/plugin-node-resolve";
import {nodeResolve} from "@rollup/plugin-node-resolve";

export default {
input: "./source/editor.js",
output: {
file: "./build/bundle.js",
format: "iife",
},
plugins: [nodeResolve()],
input: "./src/main.js",
output: {
file: "./build/bundle.js",
format: "iife",
},
plugins: [nodeResolve()],
};
1 change: 0 additions & 1 deletion default/js/codemirror/source
Submodule source deleted from ec8210
38 changes: 38 additions & 0 deletions default/js/codemirror/src/highlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {HighlightStyle, tags} from '@codemirror/highlight';

export const myHighlightStyle = HighlightStyle.define(
{tag: tags.link, textDecoration: 'underline'},
{fontWeight: 'bold', tag: tags.heading, textDecoration: 'underline'},
{fontStyle: 'italic', tag: tags.emphasis},
{fontWeight: 'bold', tag: tags.strong},
{color: '#a77b51', tag: tags.keyword},
{
color: '#219',
tag: [
tags.atom,
tags.bool,
tags.url,
tags.contentSeparator,
tags.labelName,
],
},
{color: '#164', tag: [tags.literal, tags.inserted]},
{color: '#a11', tag: [tags.string, tags.deleted]},
{color: '#e40', tag: [tags.regexp, tags.escape, tags.special(tags.string)]},
{color: '#00f', tag: tags.definition(tags.variableName)},
{color: '#30a', tag: tags.local(tags.variableName)},
{color: '#085', tag: [tags.typeName, tags.namespace]},
{color: '#167', tag: tags.className},
{
color: '#256',
tag: [
tags.special(tags.variableName),
tags.macroName,
tags.local(tags.variableName),
],
},
{color: '#00c', tag: tags.definition(tags.propertyName)},
{color: '#940', tag: tags.comment},
{color: '#7a757a', tag: tags.meta},
{color: '#f00', tag: tags.invalid},
);
81 changes: 81 additions & 0 deletions default/js/codemirror/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html data-bs-theme="dark" lang="en">
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>CodeMirror 6</title>
<link crossorigin="anonymous" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" rel="stylesheet">
</head>
<body>
<div data-language="properties" id="code-editor"></div>
<script id="editor-content" type="text/plain">ServerName localhost
DocumentRoot /etc/fruithost/placeholder
DirectoryIndex index.php index.html
AddDefaultCharset UTF-8

ErrorDocument 100 /errors/100.html
ErrorDocument 101 /errors/101.html
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 405 /errors/405.html
ErrorDocument 408 /errors/408.html
ErrorDocument 410 /errors/410.html
ErrorDocument 411 /errors/411.html
ErrorDocument 412 /errors/412.html
ErrorDocument 413 /errors/413.html
ErrorDocument 414 /errors/414.html
ErrorDocument 415 /errors/415.html
ErrorDocument 500 /errors/500.html
ErrorDocument 501 /errors/501.html
ErrorDocument 502 /errors/502.html
ErrorDocument 503 /errors/503.html
ErrorDocument 504 /errors/504.html
ErrorDocument 505 /errors/505.html
ErrorDocument 506 /errors/506.html

<Directory /etc/fruithost/placeholder/errors>
Order allow,deny
Allow from all
</Directory>

<Directory /etc/fruithost/modules/*/hooks>
Require all denied
</Directory>
<Directory /etc/fruithost/modules/*/www>
Options +FollowSymLinks -Indexes
AllowOverride None
Require all granted
</Directory>

<Directory /etc/fruithost/placeholder>
Options +FollowSymLinks -Indexes
AllowOverride All
Require all granted
</Directory>

<Directory /etc/fruithost/placeholder/errors>
Options +FollowSymLinks -Indexes
AllowOverride All
Require all granted
</Directory>

<VirtualHost *:80>
ServerAdmin info@fruithost.de
DocumentRoot "/etc/fruithost/placeholder/"
</VirtualHost>

ServerSignature Off
ServerTokens Prod
Header set Server: "fruithost"

Include /etc/fruithost/config/apache2/panel.conf
IncludeOptional /etc/fruithost/config/apache2/vhosts/*.conf

</script>
<script src="../build/bundle.js"></script>
</body>
</html>
87 changes: 87 additions & 0 deletions default/js/codemirror/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {EditorView} from "@codemirror/view";
import {Compartment, EditorState} from "@codemirror/state";
import {basicSetup} from "codemirror";
import {html} from "@codemirror/lang-html";
import {javascript} from "@codemirror/lang-javascript";
import {StreamLanguage} from "@codemirror/language"
import {properties} from "@codemirror/legacy-modes/mode/properties"
import {myTheme} from "./theme.js";
import {json} from "@codemirror/lang-json";

class CodeEditor {
constructor() {
this._code = document.querySelector('#editor-content').innerHTML;
this._container = document.querySelector('#code-editor');
this._language = new Compartment;
this.init();
}

getLanguage() {
return this._container.dataset.language;
}

init() {
this._state = EditorState.create({
doc: this._code,
extensions: [
basicSetup,
myTheme,
this._language.of(this.findLanguage()),
this.loadLanguage()
],
});

this._view = new EditorView({
state: this._state,
parent: this._container
});
}

update() {
this._view.dispatch({
effects: this._language.reconfigure(this.findLanguage())
})
}

findLanguage() {
let language = null;

switch (this.getLanguage()) {
case "html":
language = html();
break;
case "javascript":
language = javascript();
break;
case "json":
language = json();
break;
case "properties":
language = StreamLanguage.define(properties);
break;
default:
language = html();
break;
}

if (language === null) {
return null
}

return language;
}

loadLanguage() {
return EditorState.transactionExtender.of(tr => {
if (!tr.docChanged) {
return null
}

return {
effects: this._language.reconfigure(this.findLanguage())
}
});
}
}

window.addEventListener('DOMContentLoaded', () => new CodeEditor);
Loading

0 comments on commit 83b321e

Please sign in to comment.