diff --git a/packages/ui-default/components/monaco/index.js b/packages/ui-default/components/monaco/index.js index 4e2952a3b..c274cefc3 100644 --- a/packages/ui-default/components/monaco/index.js +++ b/packages/ui-default/components/monaco/index.js @@ -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(); }); } diff --git a/packages/ui-default/components/wastyle/index.js b/packages/ui-default/components/wastyle/index.js deleted file mode 100644 index e2af38d65..000000000 --- a/packages/ui-default/components/wastyle/index.js +++ /dev/null @@ -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]; - } -} diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index 9067d19b8..87be3abb5 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.29.1", + "version": "4.29.2", "author": "undefined ", "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", diff --git a/packages/ui-default/pages/home_preference.page.jsx b/packages/ui-default/pages/home_preference.page.jsx index 588da2b72..38d4d22c0 100644 --- a/packages/ui-default/pages/home_preference.page.jsx +++ b/packages/ui-default/pages/home_preference.page.jsx @@ -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( - , - $('[name="form_item_astyleOptions"]').get(0).parentNode.parentNode.parentNode, - ); - } + render( + , + $('[name="form_item_astyleOptions"]').get(0).parentNode.parentNode.parentNode, + ); } mountComponent();