mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
ui: remove useless wastyle
This commit is contained in:
1 parent
fda667c424
commit
a93ff2a3d8
4 files changed
+11
-52
No files matched your search
@@ -1,6 +1,4 @@
|
||||
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';
|
||||
|
||||
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.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.getAction('hydro.format').run();
|
||||
});
|
||||
editor.addCommand(monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF, () => {
|
||||
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",
|
||||
"version": "4.29.1",
|
||||
"version": "4.29.2",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
@@ -92,7 +92,6 @@
|
||||
"timeago.js": "^4.0.2",
|
||||
"vditor": "^3.8.10",
|
||||
"vinyl-buffer": "^1.0.1",
|
||||
"wastyle": "^0.0.5",
|
||||
"web-streams-polyfill": "^3.2.0",
|
||||
"webpack": "^4.46.0",
|
||||
"webpack-bundle-analyzer": "^4.5.0",
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { NamedPage } from 'vj/misc/Page';
|
||||
import load from 'vj/components/wastyle/index';
|
||||
import code from 'vj/components/highlighter/code-example';
|
||||
import i18n from 'vj/utils/i18n';
|
||||
import tpl from 'vj/utils/tpl';
|
||||
|
||||
const page = new NamedPage('home_preference', async () => {
|
||||
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'),
|
||||
load(),
|
||||
import('react'),
|
||||
import('react-dom'),
|
||||
]);
|
||||
@@ -16,9 +14,7 @@ const page = new NamedPage('home_preference', async () => {
|
||||
class AstylePreview extends React.PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { value: UserContext.astyleOptions };
|
||||
[this.success, this.preview] = format(code, `${this.state.value.trim()} mode=c`);
|
||||
this.state.highlight = prismjs.highlight(this.preview, prismjs.Prism.languages.cpp, 'C++');
|
||||
this.state = { highlight: prismjs.highlight(this.preview, prismjs.Prism.languages.cpp, 'C++') };
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -36,8 +32,7 @@ const page = new NamedPage('home_preference', async () => {
|
||||
style={{ height: '400px' }}
|
||||
onChange={(ev) => {
|
||||
ev.stopPropagation();
|
||||
[this.success, this.preview] = format(code, `${ev.target.value.trim()} mode=c`);
|
||||
const highlight = prismjs.highlight(this.preview, prismjs.Prism.languages.cpp, 'C++');
|
||||
const highlight = prismjs.highlight(code, prismjs.Prism.languages.cpp, 'C++');
|
||||
this.setState({ value: ev.target.value, highlight });
|
||||
}}
|
||||
className="textbox"
|
||||
@@ -121,12 +116,10 @@ const page = new NamedPage('home_preference', async () => {
|
||||
$('[name="codeLang"]').val(this.value);
|
||||
});
|
||||
|
||||
if (success) {
|
||||
render(
|
||||
<AstylePreview></AstylePreview>,
|
||||
$('[name="form_item_astyleOptions"]').get(0).parentNode.parentNode.parentNode,
|
||||
);
|
||||
}
|
||||
render(
|
||||
<AstylePreview></AstylePreview>,
|
||||
$('[name="form_item_astyleOptions"]').get(0).parentNode.parentNode.parentNode,
|
||||
);
|
||||
}
|
||||
|
||||
mountComponent();
|
||||
|
||||
Reference in new issue
Block a user