mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: remove useless wastyle
This commit is contained in:
1 parent
fda667c424
commit
a93ff2a3d8
4 files changed
+6
-47
No files matched your search
@@ -1,6 +1,4 @@
|
|||||||
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
||||||
import loadFormatter from 'vj/components/wastyle/index';
|
|
||||||
import Notification from 'vj/components/notification';
|
|
||||||
import './monaco.css';
|
import './monaco.css';
|
||||||
|
|
||||||
export default monaco;
|
export default monaco;
|
||||||
@@ -31,23 +29,8 @@ export function registerAction(editor, model, element) {
|
|||||||
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyP, () => {
|
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyP, () => {
|
||||||
editor.getAction('editor.action.quickCommand').run();
|
editor.getAction('editor.action.quickCommand').run();
|
||||||
});
|
});
|
||||||
loadFormatter().then(([loaded, format]) => {
|
|
||||||
if (!loaded) return;
|
|
||||||
editor.addAction({
|
|
||||||
id: 'hydro.format',
|
|
||||||
label: 'Format Code',
|
|
||||||
contextMenuOrder: 0,
|
|
||||||
contextMenuGroupId: 'operation',
|
|
||||||
keybindings: [monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF],
|
|
||||||
run: () => {
|
|
||||||
if (!['cpp', 'c'].includes(model._languageIdentifier.language)) return;
|
|
||||||
const [success, result] = format(editor.getValue(), `${UserContext.astyleOptions.trim()} mode=c`);
|
|
||||||
if (success) editor.setValue(result);
|
|
||||||
else Notification.warn(result);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
editor.addCommand(monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF, () => {
|
editor.addCommand(monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF, () => {
|
||||||
editor.getAction('hydro.format').run();
|
const action = editor.getAction('editor.action.format') || editor.getAction('editor.action.formatDocument');
|
||||||
});
|
if (action) action.run();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import astyleBinaryUrl from 'wastyle/dist/astyle-optimize-size.wasm';
|
|
||||||
|
|
||||||
export default async function load() {
|
|
||||||
const { init, format } = await import('wastyle');
|
|
||||||
try {
|
|
||||||
await init(astyleBinaryUrl);
|
|
||||||
console.log('WAstyle is ready!');
|
|
||||||
const formatter = (code, options) => {
|
|
||||||
const [success, result] = format(code, options);
|
|
||||||
return [success, (result || '').replace(/^#(include|import)[\t ]*(<|")/gm, (match, p1, p2) => `#${p1} ${p2}`)];
|
|
||||||
};
|
|
||||||
return [true, formatter];
|
|
||||||
} catch (e) {
|
|
||||||
return [false, e.message];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.29.1",
|
"version": "4.29.2",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
@@ -92,7 +92,6 @@
|
|||||||
"timeago.js": "^4.0.2",
|
"timeago.js": "^4.0.2",
|
||||||
"vditor": "^3.8.10",
|
"vditor": "^3.8.10",
|
||||||
"vinyl-buffer": "^1.0.1",
|
"vinyl-buffer": "^1.0.1",
|
||||||
"wastyle": "^0.0.5",
|
|
||||||
"web-streams-polyfill": "^3.2.0",
|
"web-streams-polyfill": "^3.2.0",
|
||||||
"webpack": "^4.46.0",
|
"webpack": "^4.46.0",
|
||||||
"webpack-bundle-analyzer": "^4.5.0",
|
"webpack-bundle-analyzer": "^4.5.0",
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import { NamedPage } from 'vj/misc/Page';
|
import { NamedPage } from 'vj/misc/Page';
|
||||||
import load from 'vj/components/wastyle/index';
|
|
||||||
import code from 'vj/components/highlighter/code-example';
|
import code from 'vj/components/highlighter/code-example';
|
||||||
import i18n from 'vj/utils/i18n';
|
import i18n from 'vj/utils/i18n';
|
||||||
import tpl from 'vj/utils/tpl';
|
import tpl from 'vj/utils/tpl';
|
||||||
|
|
||||||
const page = new NamedPage('home_preference', async () => {
|
const page = new NamedPage('home_preference', async () => {
|
||||||
async function mountComponent() {
|
async function mountComponent() {
|
||||||
const [{ default: prismjs }, [success, format], React, { render }] = await Promise.all([
|
const [{ default: prismjs }, React, { render }] = await Promise.all([
|
||||||
import('vj/components/highlighter/prismjs'),
|
import('vj/components/highlighter/prismjs'),
|
||||||
load(),
|
|
||||||
import('react'),
|
import('react'),
|
||||||
import('react-dom'),
|
import('react-dom'),
|
||||||
]);
|
]);
|
||||||
@@ -16,9 +14,7 @@ const page = new NamedPage('home_preference', async () => {
|
|||||||
class AstylePreview extends React.PureComponent {
|
class AstylePreview extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { value: UserContext.astyleOptions };
|
this.state = { highlight: prismjs.highlight(this.preview, prismjs.Prism.languages.cpp, 'C++') };
|
||||||
[this.success, this.preview] = format(code, `${this.state.value.trim()} mode=c`);
|
|
||||||
this.state.highlight = prismjs.highlight(this.preview, prismjs.Prism.languages.cpp, 'C++');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -36,8 +32,7 @@ const page = new NamedPage('home_preference', async () => {
|
|||||||
style={{ height: '400px' }}
|
style={{ height: '400px' }}
|
||||||
onChange={(ev) => {
|
onChange={(ev) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
[this.success, this.preview] = format(code, `${ev.target.value.trim()} mode=c`);
|
const highlight = prismjs.highlight(code, prismjs.Prism.languages.cpp, 'C++');
|
||||||
const highlight = prismjs.highlight(this.preview, prismjs.Prism.languages.cpp, 'C++');
|
|
||||||
this.setState({ value: ev.target.value, highlight });
|
this.setState({ value: ev.target.value, highlight });
|
||||||
}}
|
}}
|
||||||
className="textbox"
|
className="textbox"
|
||||||
@@ -121,13 +116,11 @@ const page = new NamedPage('home_preference', async () => {
|
|||||||
$('[name="codeLang"]').val(this.value);
|
$('[name="codeLang"]').val(this.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (success) {
|
|
||||||
render(
|
render(
|
||||||
<AstylePreview></AstylePreview>,
|
<AstylePreview></AstylePreview>,
|
||||||
$('[name="form_item_astyleOptions"]').get(0).parentNode.parentNode.parentNode,
|
$('[name="form_item_astyleOptions"]').get(0).parentNode.parentNode.parentNode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mountComponent();
|
mountComponent();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user