ui: use esbuild-loader & chunk-splitting

This commit is contained in:
undefined committed 2021-08-07 19:52:57 +08:00
1 parent db9def7917
commit e67c1c333a
9 files changed
+104 -54

No files matched your search

@@ -1,6 +1,8 @@
import React from 'react';
import { connect } from 'react-redux';
import load from 'vj/components/wastyle/index';
import monaco from 'vj/components/monaco/index';
import Notification from 'vj/components/notification';
const mapStateToProps = (state) => ({
value: state.editor.code,
@@ -29,7 +31,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e
const { language, theme } = this.props;
if (this.props.language === 'blockly') {
if (!this.blockly) {
import('./blockly.jsx').then(({ default: Blockly }) => {
import('./blockly').then(({ default: Blockly }) => {
if (!this.blockly) return;
Blockly.inject(this.containerElement, {
});
@@ -51,6 +53,29 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e
const fontSize = localStorage.getItem('scratchpad.editor.fontSize');
if (fontSize && !Number.isNaN(+fontSize)) config.fontSize = +fontSize;
this.editor = monaco.editor.create(this.containerElement, config);
this.editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KEY_P, () => {
this.editor.getAction('editor.action.quickCommand').run();
});
load().then(([loaded, format]) => {
if (!loaded) return;
const formatAction = {
id: 'hydro.format',
label: 'Format Code',
contextMenuOrder: 0,
contextMenuGroupId: 'operation',
keybindings: [monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KEY_F],
run: () => {
if (!['cpp', 'c'].includes(this.model._languageIdentifier.language)) return;
const [success, result] = format(this.editor.getValue(), `${UserContext.astyleOptions.trim()} mode=c`);
if (success) this.editor.setValue(result);
else Notification.warn(result);
},
};
this.editor.addAction(formatAction);
this.editor.addCommand(monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KEY_F, () => {
this.editor.getAction('hydro.format').run();
});
});
this.disposable.push(
this.editor.onDidChangeModelContent((event) => {
if (!this.__prevent_trigger_change_event) {
@@ -69,7 +94,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class MonacoEditor e
if (this.props.language === 'blockly') {
if (!this.blockly) {
this.editor.dispose();
import('./blockly.jsx').then(({ default: Blockly, toolbox }) => {
import('./blockly').then(({ default: Blockly, toolbox }) => {
if (!this.blockly) return;
Blockly.inject(this.containerElement, {
toolbox,